diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2020-05-11 21:20:07 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-06-05 14:04:20 +1000 |
commit | e6881f08292d03f089185718c131f543d095089b (patch) | |
tree | 1819a0b92c14bdeb3289e49c799454ba3d6cf43c /examples/bluetooth/ble_temperature_central.py | |
parent | 02cc4462b70729a42cb127c840fee891dd08a0d4 (diff) | |
download | micropython-e6881f08292d03f089185718c131f543d095089b.tar.gz micropython-e6881f08292d03f089185718c131f543d095089b.zip |
extmod/modbluetooth: Make modbluetooth event not a bitfield.
There doesn't appear to be any use for only triggering on specific events,
so it's just easier to number them sequentially. This makes them smaller
values so they take up only 1 byte in the ringbuf, only 1 byte for the
opcode in the bytecode, and makes room for more events.
Also add a couple of new event types that need to be implemented (to avoid
re-numbering later).
And rename _COMPLETE and _STATUS to _DONE for consistency.
In the future the "trigger" keyword argument can be reinstated by requiring
the user to compute the bitmask, eg:
ble.irq(handler, 1 << _IRQ_SCAN_RESULT | 1 << _IRQ_SCAN_DONE)
Diffstat (limited to 'examples/bluetooth/ble_temperature_central.py')
-rw-r--r-- | examples/bluetooth/ble_temperature_central.py | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/examples/bluetooth/ble_temperature_central.py b/examples/bluetooth/ble_temperature_central.py index 04fed0a299..8b679b9b80 100644 --- a/examples/bluetooth/ble_temperature_central.py +++ b/examples/bluetooth/ble_temperature_central.py @@ -10,22 +10,25 @@ from ble_advertising import decode_services, decode_name from micropython import const -_IRQ_CENTRAL_CONNECT = const(1 << 0) -_IRQ_CENTRAL_DISCONNECT = const(1 << 1) -_IRQ_GATTS_WRITE = const(1 << 2) -_IRQ_GATTS_READ_REQUEST = const(1 << 3) -_IRQ_SCAN_RESULT = const(1 << 4) -_IRQ_SCAN_COMPLETE = const(1 << 5) -_IRQ_PERIPHERAL_CONNECT = const(1 << 6) -_IRQ_PERIPHERAL_DISCONNECT = const(1 << 7) -_IRQ_GATTC_SERVICE_RESULT = const(1 << 8) -_IRQ_GATTC_CHARACTERISTIC_RESULT = const(1 << 9) -_IRQ_GATTC_DESCRIPTOR_RESULT = const(1 << 10) -_IRQ_GATTC_READ_RESULT = const(1 << 11) -_IRQ_GATTC_WRITE_STATUS = const(1 << 12) -_IRQ_GATTC_NOTIFY = const(1 << 13) -_IRQ_GATTC_INDICATE = const(1 << 14) -_IRQ_ALL = const(0xFFFF) +_IRQ_CENTRAL_CONNECT = const(1) +_IRQ_CENTRAL_DISCONNECT = const(2) +_IRQ_GATTS_WRITE = const(3) +_IRQ_GATTS_READ_REQUEST = const(4) +_IRQ_SCAN_RESULT = const(5) +_IRQ_SCAN_DONE = const(6) +_IRQ_PERIPHERAL_CONNECT = const(7) +_IRQ_PERIPHERAL_DISCONNECT = const(8) +_IRQ_GATTC_SERVICE_RESULT = const(9) +_IRQ_GATTC_SERVICE_DONE = const(10) +_IRQ_GATTC_CHARACTERISTIC_RESULT = const(11) +_IRQ_GATTC_CHARACTERISTIC_DONE = const(12) +_IRQ_GATTC_DESCRIPTOR_RESULT = const(13) +_IRQ_GATTC_DESCRIPTOR_DONE = const(14) +_IRQ_GATTC_READ_RESULT = const(15) +_IRQ_GATTC_READ_DONE = const(16) +_IRQ_GATTC_WRITE_DONE = const(17) +_IRQ_GATTC_NOTIFY = const(18) +_IRQ_GATTC_INDICATE = const(19) _ADV_IND = const(0x00) _ADV_DIRECT_IND = const(0x01) @@ -93,7 +96,7 @@ class BLETemperatureCentral: self._name = decode_name(adv_data) or "?" self._ble.gap_scan(None) - elif event == _IRQ_SCAN_COMPLETE: + elif event == _IRQ_SCAN_DONE: if self._scan_callback: if self._addr: # Found a device during the scan (and the scan was explicitly stopped). |