summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2020-08-29 15:14:29 +1000
committerDamien George <damien@micropython.org>2020-08-29 15:18:01 +1000
commit06659077a81b85882254cf0953c33b27614e018e (patch)
treef0463060ca6144a82b0e54ffc4f394c208d4d92c /examples
parent0c7354afaf91da3dac2c5ec471603c9e7acc8eac (diff)
all: Update Python code to conform to latest black formatting.
Updating to Black v20.8b1 there are two changes that affect the code in this repository: - If there is a trailing comma in a list (eg [], () or function call) then that list is now written out with one line per element. So remove such trailing commas where the list should stay on one line. - Spaces at the start of """ doc strings are removed. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'examples')
-rw-r--r--examples/bluetooth/ble_simple_central.py6
-rw-r--r--examples/bluetooth/ble_simple_peripheral.py12
-rw-r--r--examples/bluetooth/ble_temperature.py6
-rw-r--r--examples/bluetooth/ble_temperature_central.py6
-rw-r--r--examples/bluetooth/ble_uart_peripheral.py12
5 files changed, 19 insertions, 23 deletions
diff --git a/examples/bluetooth/ble_simple_central.py b/examples/bluetooth/ble_simple_central.py
index f6996366e..f0a3297d3 100644
--- a/examples/bluetooth/ble_simple_central.py
+++ b/examples/bluetooth/ble_simple_central.py
@@ -74,7 +74,7 @@ class BLESimpleCentral:
def _irq(self, event, data):
if event == _IRQ_SCAN_RESULT:
addr_type, addr, adv_type, rssi, adv_data = data
- if adv_type in (_ADV_IND, _ADV_DIRECT_IND,) and _UART_SERVICE_UUID in decode_services(
+ if adv_type in (_ADV_IND, _ADV_DIRECT_IND) and _UART_SERVICE_UUID in decode_services(
adv_data
):
# Found a potential device, remember it and stop scanning.
@@ -97,14 +97,14 @@ class BLESimpleCentral:
elif event == _IRQ_PERIPHERAL_CONNECT:
# Connect successful.
- conn_handle, addr_type, addr, = data
+ conn_handle, addr_type, addr = data
if addr_type == self._addr_type and addr == self._addr:
self._conn_handle = conn_handle
self._ble.gattc_discover_services(self._conn_handle)
elif event == _IRQ_PERIPHERAL_DISCONNECT:
# Disconnect (either initiated by us or the remote end).
- conn_handle, _, _, = data
+ conn_handle, _, _ = data
if conn_handle == self._conn_handle:
# If it was initiated by us, it'll already be reset.
self._reset()
diff --git a/examples/bluetooth/ble_simple_peripheral.py b/examples/bluetooth/ble_simple_peripheral.py
index 08cd7fa98..f5e766192 100644
--- a/examples/bluetooth/ble_simple_peripheral.py
+++ b/examples/bluetooth/ble_simple_peripheral.py
@@ -23,7 +23,7 @@ _UART_RX = (
)
_UART_SERVICE = (
_UART_UUID,
- (_UART_TX, _UART_RX,),
+ (_UART_TX, _UART_RX),
)
@@ -32,22 +32,20 @@ class BLESimplePeripheral:
self._ble = ble
self._ble.active(True)
self._ble.irq(handler=self._irq)
- ((self._handle_tx, self._handle_rx,),) = self._ble.gatts_register_services(
- (_UART_SERVICE,)
- )
+ ((self._handle_tx, self._handle_rx),) = self._ble.gatts_register_services((_UART_SERVICE,))
self._connections = set()
self._write_callback = None
- self._payload = advertising_payload(name=name, services=[_UART_UUID],)
+ self._payload = advertising_payload(name=name, services=[_UART_UUID])
self._advertise()
def _irq(self, event, data):
# Track connections so we can send notifications.
if event == _IRQ_CENTRAL_CONNECT:
- conn_handle, _, _, = data
+ conn_handle, _, _ = data
print("New connection", conn_handle)
self._connections.add(conn_handle)
elif event == _IRQ_CENTRAL_DISCONNECT:
- conn_handle, _, _, = data
+ conn_handle, _, _ = data
print("Disconnected", conn_handle)
self._connections.remove(conn_handle)
# Start advertising again to allow a new connection.
diff --git a/examples/bluetooth/ble_temperature.py b/examples/bluetooth/ble_temperature.py
index 0e2da2239..001a26b11 100644
--- a/examples/bluetooth/ble_temperature.py
+++ b/examples/bluetooth/ble_temperature.py
@@ -46,15 +46,15 @@ class BLETemperature:
def _irq(self, event, data):
# Track connections so we can send notifications.
if event == _IRQ_CENTRAL_CONNECT:
- conn_handle, _, _, = data
+ conn_handle, _, _ = data
self._connections.add(conn_handle)
elif event == _IRQ_CENTRAL_DISCONNECT:
- conn_handle, _, _, = data
+ conn_handle, _, _ = data
self._connections.remove(conn_handle)
# Start advertising again to allow a new connection.
self._advertise()
elif event == _IRQ_GATTS_INDICATE_DONE:
- conn_handle, value_handle, status, = data
+ conn_handle, value_handle, status = data
def set_temperature(self, temp_deg_c, notify=False, indicate=False):
# Data is sint16 in degrees Celsius with a resolution of 0.01 degrees Celsius.
diff --git a/examples/bluetooth/ble_temperature_central.py b/examples/bluetooth/ble_temperature_central.py
index f9db225c1..798303417 100644
--- a/examples/bluetooth/ble_temperature_central.py
+++ b/examples/bluetooth/ble_temperature_central.py
@@ -87,7 +87,7 @@ class BLETemperatureCentral:
def _irq(self, event, data):
if event == _IRQ_SCAN_RESULT:
addr_type, addr, adv_type, rssi, adv_data = data
- if adv_type in (_ADV_IND, _ADV_DIRECT_IND,) and _ENV_SENSE_UUID in decode_services(
+ if adv_type in (_ADV_IND, _ADV_DIRECT_IND) and _ENV_SENSE_UUID in decode_services(
adv_data
):
# Found a potential device, remember it and stop scanning.
@@ -110,14 +110,14 @@ class BLETemperatureCentral:
elif event == _IRQ_PERIPHERAL_CONNECT:
# Connect successful.
- conn_handle, addr_type, addr, = data
+ conn_handle, addr_type, addr = data
if addr_type == self._addr_type and addr == self._addr:
self._conn_handle = conn_handle
self._ble.gattc_discover_services(self._conn_handle)
elif event == _IRQ_PERIPHERAL_DISCONNECT:
# Disconnect (either initiated by us or the remote end).
- conn_handle, _, _, = data
+ conn_handle, _, _ = data
if conn_handle == self._conn_handle:
# If it was initiated by us, it'll already be reset.
self._reset()
diff --git a/examples/bluetooth/ble_uart_peripheral.py b/examples/bluetooth/ble_uart_peripheral.py
index cc8d589b0..59b35f7e6 100644
--- a/examples/bluetooth/ble_uart_peripheral.py
+++ b/examples/bluetooth/ble_uart_peripheral.py
@@ -20,7 +20,7 @@ _UART_RX = (
)
_UART_SERVICE = (
_UART_UUID,
- (_UART_TX, _UART_RX,),
+ (_UART_TX, _UART_RX),
)
# org.bluetooth.characteristic.gap.appearance.xml
@@ -32,9 +32,7 @@ class BLEUART:
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()
@@ -50,16 +48,16 @@ class BLEUART:
def _irq(self, event, data):
# Track connections so we can send notifications.
if event == _IRQ_CENTRAL_CONNECT:
- conn_handle, _, _, = data
+ conn_handle, _, _ = data
self._connections.add(conn_handle)
elif event == _IRQ_CENTRAL_DISCONNECT:
- conn_handle, _, _, = data
+ conn_handle, _, _ = data
if conn_handle in self._connections:
self._connections.remove(conn_handle)
# Start advertising again to allow a new connection.
self._advertise()
elif event == _IRQ_GATTS_WRITE:
- conn_handle, value_handle, = data
+ conn_handle, value_handle = data
if conn_handle in self._connections and value_handle == self._rx_handle:
self._rx_buffer += self._ble.gatts_read(self._rx_handle)
if self._handler: