Esempio n. 1
0
class Nuimo:

    def __init__(self, macAddress='FA:48:12:00:CA:AC'):
        self.macAddress = macAddress

    def connect(self):
        try:
            self.peripheral = Peripheral(self.macAddress, addrType='random')
        except BTLEException:
            return False
        try:
            self.enableNotifications()
            self.peripheral.setDelegate(NuimoDelegate())
        except BTLEException:
            self.peripheral.disconnect()
            self.peripheral = None
            return False
        return True

    def enableNotifications(self):
        self.peripheral.writeCharacteristic(CLICK_NOTIFICATION_HANDLE,    NOTIFICATION_ON)
        self.peripheral.writeCharacteristic(BATTERY_NOTIFICATION_HANDLE,  NOTIFICATION_ON)
        self.peripheral.writeCharacteristic(FLY_NOTIFICATION_HANDLE,      NOTIFICATION_ON)
        self.peripheral.writeCharacteristic(SWIPE_NOTIFICATION_HANDLE,    NOTIFICATION_ON)
        self.peripheral.writeCharacteristic(ROTATION_NOTIFICATION_HANDLE, NOTIFICATION_ON)

    def waitForNotifications(self):
        try:
            self.peripheral.waitForNotifications(1.0)
            return True
        except BTLEException as e:
            return False

    def displayLedMatrix(self, matrix, brightness, timeout):
        self.peripheral.writeCharacteristic(LEDMATRIX_VALUE_HANDLE, struct.pack("BBBBBBBBBBBBB", 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff))
Esempio n. 2
0
def startCycle():
    print("cerco di connettermi")
    per = Peripheral("d7:84:e7:e2:87:68")
    per.setDelegate(MyDelegate())
    print("connessione avvenuta")
    GObject.timeout_add(7000, doCycle, per)