From 68e3e07bc7ab63931cead3854b2a114e9a084248 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-central/manifest.py | 2 +- micropython/bluetooth/aioble-core/manifest.py | 2 +- micropython/bluetooth/aioble/aioble/central.py | 12 ++++++++++-- micropython/bluetooth/aioble/aioble/device.py | 16 ++++++++++++++-- micropython/bluetooth/aioble/manifest.py | 2 +- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/micropython/bluetooth/aioble-central/manifest.py b/micropython/bluetooth/aioble-central/manifest.py index 9564ecf7..ed61ec9d 100644 --- a/micropython/bluetooth/aioble-central/manifest.py +++ b/micropython/bluetooth/aioble-central/manifest.py @@ -1,4 +1,4 @@ -metadata(version="0.2.2") +metadata(version="0.3.0") require("aioble-core") diff --git a/micropython/bluetooth/aioble-core/manifest.py b/micropython/bluetooth/aioble-core/manifest.py index c2d335b5..e040f107 100644 --- a/micropython/bluetooth/aioble-core/manifest.py +++ b/micropython/bluetooth/aioble-core/manifest.py @@ -1,4 +1,4 @@ -metadata(version="0.3.0") +metadata(version="0.4.0") package( "aioble", diff --git a/micropython/bluetooth/aioble/aioble/central.py b/micropython/bluetooth/aioble/aioble/central.py index 6d90cd0f..131b1e0d 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 d02d6385..93819bc1 100644 --- a/micropython/bluetooth/aioble/aioble/device.py +++ b/micropython/bluetooth/aioble/aioble/device.py @@ -132,14 +132,26 @@ class Device: 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() diff --git a/micropython/bluetooth/aioble/manifest.py b/micropython/bluetooth/aioble/manifest.py index 82464742..83220057 100644 --- a/micropython/bluetooth/aioble/manifest.py +++ b/micropython/bluetooth/aioble/manifest.py @@ -3,7 +3,7 @@ # code. This allows (for development purposes) all the files to live in the # one directory. -metadata(version="0.5.2") +metadata(version="0.6.0") # Default installation gives you everything. Install the individual # components (or a combination of them) if you want a more minimal install.