diff options
author | Damien George <damien.p.george@gmail.com> | 2020-02-27 15:36:53 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-02-28 10:33:03 +1100 |
commit | 69661f3343bedf86e514337cff63d96cc42f8859 (patch) | |
tree | af5dfb380ffdb75dda84828f63cf9d840d992f0f /examples/bluetooth/ble_uart_peripheral.py | |
parent | 3f39d18c2b884d32f0443e2e8114ff9d7a14d718 (diff) |
all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
Diffstat (limited to 'examples/bluetooth/ble_uart_peripheral.py')
-rw-r--r-- | examples/bluetooth/ble_uart_peripheral.py | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/examples/bluetooth/ble_uart_peripheral.py b/examples/bluetooth/ble_uart_peripheral.py index 14f710272..c013d96ec 100644 --- a/examples/bluetooth/ble_uart_peripheral.py +++ b/examples/bluetooth/ble_uart_peripheral.py @@ -4,24 +4,37 @@ import bluetooth 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) -_UART_UUID = bluetooth.UUID('6E400001-B5A3-F393-E0A9-E50E24DCCA9E') -_UART_TX = (bluetooth.UUID('6E400003-B5A3-F393-E0A9-E50E24DCCA9E'), bluetooth.FLAG_NOTIFY,) -_UART_RX = (bluetooth.UUID('6E400002-B5A3-F393-E0A9-E50E24DCCA9E'), bluetooth.FLAG_WRITE,) -_UART_SERVICE = (_UART_UUID, (_UART_TX, _UART_RX,),) +_IRQ_CENTRAL_CONNECT = const(1 << 0) +_IRQ_CENTRAL_DISCONNECT = const(1 << 1) +_IRQ_GATTS_WRITE = const(1 << 2) + +_UART_UUID = bluetooth.UUID("6E400001-B5A3-F393-E0A9-E50E24DCCA9E") +_UART_TX = ( + bluetooth.UUID("6E400003-B5A3-F393-E0A9-E50E24DCCA9E"), + bluetooth.FLAG_NOTIFY, +) +_UART_RX = ( + bluetooth.UUID("6E400002-B5A3-F393-E0A9-E50E24DCCA9E"), + bluetooth.FLAG_WRITE, +) +_UART_SERVICE = ( + _UART_UUID, + (_UART_TX, _UART_RX,), +) # org.bluetooth.characteristic.gap.appearance.xml _ADV_APPEARANCE_GENERIC_COMPUTER = const(128) + class BLEUART: - def __init__(self, ble, name='mpy-uart', rxbuf=100): + def __init__(self, ble, name="mpy-uart", rxbuf=100): self._ble = ble self._ble.active(True) self._ble.irq(handler=self._irq) - ((self._tx_handle, self._rx_handle,),) = self._ble.gatts_register_services((_UART_SERVICE,)) + ((self._tx_handle, self._rx_handle,),) = self._ble.gatts_register_services( + (_UART_SERVICE,) + ) # Increase the size of the rx buffer and enable append mode. self._ble.gatts_set_buffer(self._rx_handle, rxbuf, True) self._connections = set() @@ -82,7 +95,7 @@ def demo(): uart = BLEUART(ble) def on_rx(): - print('rx: ', uart.read().decode().strip()) + print("rx: ", uart.read().decode().strip()) uart.irq(handler=on_rx) nums = [4, 8, 15, 16, 23, 42] @@ -90,7 +103,7 @@ def demo(): try: while True: - uart.write(str(nums[i]) + '\n') + uart.write(str(nums[i]) + "\n") i = (i + 1) % len(nums) time.sleep_ms(1000) except KeyboardInterrupt: @@ -99,5 +112,5 @@ def demo(): uart.close() -if __name__ == '__main__': +if __name__ == "__main__": demo() |