summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2020-05-11 21:20:07 +1000
committerDamien George <damien.p.george@gmail.com>2020-06-05 14:04:20 +1000
commite6881f08292d03f089185718c131f543d095089b (patch)
tree1819a0b92c14bdeb3289e49c799454ba3d6cf43c /examples
parent02cc4462b70729a42cb127c840fee891dd08a0d4 (diff)
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')
-rw-r--r--examples/bluetooth/ble_temperature.py4
-rw-r--r--examples/bluetooth/ble_temperature_central.py37
-rw-r--r--examples/bluetooth/ble_uart_peripheral.py6
3 files changed, 25 insertions, 22 deletions
diff --git a/examples/bluetooth/ble_temperature.py b/examples/bluetooth/ble_temperature.py
index 01d2f7441..fd24e74d7 100644
--- a/examples/bluetooth/ble_temperature.py
+++ b/examples/bluetooth/ble_temperature.py
@@ -11,8 +11,8 @@ from ble_advertising import advertising_payload
from micropython import const
-_IRQ_CENTRAL_CONNECT = const(1 << 0)
-_IRQ_CENTRAL_DISCONNECT = const(1 << 1)
+_IRQ_CENTRAL_CONNECT = const(1)
+_IRQ_CENTRAL_DISCONNECT = const(2)
# org.bluetooth.service.environmental_sensing
_ENV_SENSE_UUID = bluetooth.UUID(0x181A)
diff --git a/examples/bluetooth/ble_temperature_central.py b/examples/bluetooth/ble_temperature_central.py
index 04fed0a29..8b679b9b8 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).
diff --git a/examples/bluetooth/ble_uart_peripheral.py b/examples/bluetooth/ble_uart_peripheral.py
index c013d96ec..cc8d589b0 100644
--- a/examples/bluetooth/ble_uart_peripheral.py
+++ b/examples/bluetooth/ble_uart_peripheral.py
@@ -5,9 +5,9 @@ from ble_advertising import advertising_payload
from micropython import const
-_IRQ_CENTRAL_CONNECT = const(1 << 0)
-_IRQ_CENTRAL_DISCONNECT = const(1 << 1)
-_IRQ_GATTS_WRITE = const(1 << 2)
+_IRQ_CENTRAL_CONNECT = const(1)
+_IRQ_CENTRAL_DISCONNECT = const(2)
+_IRQ_GATTS_WRITE = const(3)
_UART_UUID = bluetooth.UUID("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")
_UART_TX = (