Skip to content

Commit

Permalink
aioble: Pass additional connection arguments to gap_connect.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Joris-van-der-Wel authored and dpgeorge committed Oct 18, 2024
1 parent a7cd740 commit 68e3e07
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion micropython/bluetooth/aioble-central/manifest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
metadata(version="0.2.2")
metadata(version="0.3.0")

require("aioble-core")

Expand Down
2 changes: 1 addition & 1 deletion micropython/bluetooth/aioble-core/manifest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
metadata(version="0.3.0")
metadata(version="0.4.0")

package(
"aioble",
Expand Down
12 changes: 10 additions & 2 deletions micropython/bluetooth/aioble/aioble/central.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
16 changes: 14 additions & 2 deletions micropython/bluetooth/aioble/aioble/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion micropython/bluetooth/aioble/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 68e3e07

Please sign in to comment.