Skip to content

stop main loop #32

@rafifajar22

Description

@rafifajar22

how to stop main loop, because there is blocking, and and I can't call stop function, this my code

import gatt

manager = gatt.DeviceManager(adapter_name='hci0')

class AnyDevice(gatt.Device):
def services_resolved(self):
super().services_resolved()

    device_proprietary_service = next(
        s for s in self.services
        if s.uuid == 'd0cbda9a-9a69-49ab-b4d1-a96d6fbd10c6')

    psp = next(
        c for c in device_proprietary_service.characteristics
        if c.uuid == 'd0cb6c99-9a69-49ab-b4d1-a96d6fbd10c6')

psp.write_value(bytearray(b'\x0a'))
tes="\x1D\x5A\x02"
best=tes.encode()
psp.write_value(best)
kay="\x1B\x5A\x00\x4C\x08\x11\x00\x43\x44\x3A\x42\x30\x3A\x32\x31\x3A\x32\x31\x3A\x34\x30\x3A\x42\x33"
best=kay.encode()
psp.write_value(best)

def characteristic_value_updated(self, characteristic, value):
    print(str(characteristic)+", value: "+value.decode("utf-8"))

def characteristic_write_value_succeeded(self, characteristic):
    print("Write successful.")

def characteristic_write_value_failed(self, characteristic, error):
    print("Write failed. "+str(error))

class Manager(gatt.DeviceManager):
def run(self):
print("Running Manager")
super().run()
def quit(self):
print("Stopping Manager")
super().stop()

manager = Manager(adapter_name = 'hci0')
device = AnyDevice(mac_address='CD:B0:21:21:40:B3', manager=manager)
device.connect()

manager.run()
time.sleep(2)
manager.quit()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions