import logging import time from struct import pack from pylgbst.comms import BLEConnection from pylgbst.constants import * from pylgbst.peripherals import Button, EncodedMotor, ColorDistanceSensor, LED, TiltSensor, Voltage, Peripheral, \ Amperage log = logging.getLogger('movehub') ENABLE_NOTIFICATIONS_HANDLE = 0x000f ENABLE_NOTIFICATIONS_VALUE = b'\x01\x00' class MoveHub(object): """ :type connection: pylgbst.comms.Connection :type devices: dict[int,Peripheral] :type led: LED :type tilt_sensor: TiltSensor :type button: Button :type amperage: Amperage :type voltage: Voltage :type color_distance_sensor: pylgbst.peripherals.ColorDistanceSensor :type port_C: Peripheral :type port_D: Peripheral :type motor_A: EncodedMotor :type motor_B: EncodedMotor :type motor_AB: EncodedMotor :type motor_external: EncodedMotor """ DEV_STATUS_DETACHED = 0x00 DEV_STATUS_DEVICE = 0x01 DEV_STATUS_GROUP = 0x02 def __init__(self, connection=None): if not connection: connection = BLEConnection().connect() self.connection = connection self.info = {} self.devices = {} # shorthand fields self.button = Button(self) self.led = None self.amperage = None self.voltage = None self.motor_A = None self.motor_B = None self.motor_AB = None self.color_distance_sensor = None self.tilt_sensor = None self.motor_external = None self.port_C = None self.port_D = None self.connection.set_notify_handler(self._notify) self._wait_for_devices() self._report_status() def send(self, msg_type, payload): cmd = pack("