From cb68ebb6459f114447b44480c34fa699458fde64 Mon Sep 17 00:00:00 2001 From: Joris van der Wel Date: Fri, 2 Aug 2024 20:12:55 +0200 Subject: [PATCH] aioble: Pass additional connection arguments to gap_connect. This allows the following arguments to be passed to `device.connect()`: * scan_duration_ms * min_conn_interval_us * max_conn_interval_us These are passed as-is to `gap_connect()`. The default value for all of these is `None`, which causes gap_connect to use its own defaults. Signed-off-by: Joris van der Wel --- micropython/bluetooth/aioble/aioble/central.py | 12 ++++++++++-- micropython/bluetooth/aioble/aioble/device.py | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/micropython/bluetooth/aioble/aioble/central.py b/micropython/bluetooth/aioble/aioble/central.py index 6d90cd0f8..131b1e0db 100644 --- a/micropython/bluetooth/aioble/aioble/central.py +++ b/micropython/bluetooth/aioble/aioble/central.py @@ -104,7 +104,9 @@ async def _cancel_pending(): # Start connecting to a peripheral. # Call device.connect() rather than using method directly. -async def _connect(connection, timeout_ms): +async def _connect( + connection, timeout_ms, scan_duration_ms, min_conn_interval_us, max_conn_interval_us +): device = connection.device if device in _connecting: return @@ -122,7 +124,13 @@ async def _connect(connection, timeout_ms): try: with DeviceTimeout(None, timeout_ms): - ble.gap_connect(device.addr_type, device.addr) + ble.gap_connect( + device.addr_type, + device.addr, + scan_duration_ms, + min_conn_interval_us, + max_conn_interval_us, + ) # Wait for the connected IRQ. await connection._event.wait() diff --git a/micropython/bluetooth/aioble/aioble/device.py b/micropython/bluetooth/aioble/aioble/device.py index d02d6385f..93819bc1e 100644 --- a/micropython/bluetooth/aioble/aioble/device.py +++ b/micropython/bluetooth/aioble/aioble/device.py @@ -132,14 +132,26 @@ def __str__(self): def addr_hex(self): return binascii.hexlify(self.addr, ":").decode() - async def connect(self, timeout_ms=10000): + async def connect( + self, + timeout_ms=10000, + scan_duration_ms=None, + min_conn_interval_us=None, + max_conn_interval_us=None, + ): if self._connection: return self._connection # Forward to implementation in central.py. from .central import _connect - await _connect(DeviceConnection(self), timeout_ms) + await _connect( + DeviceConnection(self), + timeout_ms, + scan_duration_ms, + min_conn_interval_us, + max_conn_interval_us, + ) # Start the device task that will clean up after disconnection. self._connection._run_task()