Source code for poseyctrl.sensor

# NOTE: We need a patched UARTService class with a larger buffer. The default
# is tiny and does not work when trying to send large packets.
#from adafruit_ble.services.nordic import UARTService
# ATW: The Adafruit library has egregiously small buffers that, because of how
# the class is instantiated, can't be enlarged after the fact, so we need this
# patch.
from poseyctrl.patch.nordic import UARTService
from poseyctrl import hil


[docs]class PoseySensor: def __init__(self, name, ble, advertisement, qout, qin, pq, nowstamp): self.name = name self.ble = ble self.advertisement = advertisement self.connection = None self.service = None self.hil = hil.PoseyHIL( name, qout, qin, pq, advertisement, None, None, nowstamp)
[docs] def disconnect(self): if (self.connection is not None) and (self.connection.connected): self.connection.disconnect() self.connection = None self.service = None self.hil.uart_conn = None self.hil.uart_service = None
[docs] def connect(self, timeout=10): self.disconnect() self.connection = self.ble.connect(self.advertisement, timeout=timeout) if self.connection.connected: self.service = self.connection[UARTService] self.hil.uart_conn = self.connection self.hil.uart_service = self.service return True else: self.connection = None return False
@property def connected(self): return self.connection and self.connection.connected def __str__(self) -> str: return f'{self.name} <{self.advertisement.address.string}>' def __repr__(self) -> str: return self.__str__(self)

Last update: May 05, 2023