47
47
#define INTERVAL_MAX_STRING "40.959375"
48
48
#define WINDOW_DEFAULT (0.1f)
49
49
50
- //| .. currentmodule:: _bleio
50
+ //| class Adapter:
51
+ //| """.. currentmodule:: _bleio
51
52
//|
52
- //| :class:`Adapter` --- BLE adapter
53
- //| ----------------------------------------------------
53
+ //| :class:`Adapter` --- BLE adapter
54
+ //| ----------------------------------------------------
54
55
//|
55
- //| The Adapter manages the discovery and connection to other nearby Bluetooth Low Energy devices.
56
- //| This part of the Bluetooth Low Energy Specification is known as Generic Access Profile (GAP).
56
+ //| The Adapter manages the discovery and connection to other nearby Bluetooth Low Energy devices.
57
+ //| This part of the Bluetooth Low Energy Specification is known as Generic Access Profile (GAP).
57
58
//|
58
- //| Discovery of other devices happens during a scanning process that listens for small packets of
59
- //| information, known as advertisements, that are broadcast unencrypted. The advertising packets
60
- //| have two different uses. The first is to broadcast a small piece of data to anyone who cares and
61
- //| and nothing more. These are known as Beacons. The second class of advertisement is to promote
62
- //| additional functionality available after the devices establish a connection. For example, a
63
- //| BLE keyboard may advertise that it can provide key information, but not what the key info is.
59
+ //| Discovery of other devices happens during a scanning process that listens for small packets of
60
+ //| information, known as advertisements, that are broadcast unencrypted. The advertising packets
61
+ //| have two different uses. The first is to broadcast a small piece of data to anyone who cares and
62
+ //| and nothing more. These are known as Beacons. The second class of advertisement is to promote
63
+ //| additional functionality available after the devices establish a connection. For example, a
64
+ //| BLE keyboard may advertise that it can provide key information, but not what the key info is.
64
65
//|
65
- //| The built-in BLE adapter can do both parts of this process: it can scan for other device
66
- //| advertisements and it can advertise its own data. Furthermore, Adapters can accept incoming
67
- //| connections and also initiate connections.
66
+ //| The built-in BLE adapter can do both parts of this process: it can scan for other device
67
+ //| advertisements and it can advertise its own data. Furthermore, Adapters can accept incoming
68
+ //| connections and also initiate connections."""
68
69
//|
69
70
70
- //| .. class:: Adapter()
71
- //|
72
- //| You cannot create an instance of `_bleio.Adapter`.
73
- //| Use `_bleio.adapter` to access the sole instance available .
71
+ //| def __init__(self, ):
72
+ //| """You cannot create an instance of `_bleio.Adapter`.
73
+ //| Use `_bleio.adapter` to access the sole instance available."""
74
+ //| .. .
74
75
//|
75
76
76
- //| .. attribute:: enabled
77
- //|
78
- //| State of the BLE adapter.
77
+ //| enabled: Any = ...
78
+ //| """State of the BLE adapter."""
79
79
//|
80
80
STATIC mp_obj_t bleio_adapter_get_enabled (mp_obj_t self ) {
81
81
return mp_obj_new_bool (common_hal_bleio_adapter_get_enabled (self ));
@@ -98,9 +98,8 @@ const mp_obj_property_t bleio_adapter_enabled_obj = {
98
98
(mp_obj_t )& mp_const_none_obj },
99
99
};
100
100
101
- //| .. attribute:: address
102
- //|
103
- //| MAC address of the BLE adapter. (read-only)
101
+ //| address: Any = ...
102
+ //| """MAC address of the BLE adapter. (read-only)"""
104
103
//|
105
104
STATIC mp_obj_t bleio_adapter_get_address (mp_obj_t self ) {
106
105
return MP_OBJ_FROM_PTR (common_hal_bleio_adapter_get_address (self ));
@@ -115,11 +114,10 @@ const mp_obj_property_t bleio_adapter_address_obj = {
115
114
(mp_obj_t )& mp_const_none_obj },
116
115
};
117
116
118
- //| .. attribute:: name
119
- //|
120
- //| name of the BLE adapter used once connected.
121
- //| The name is "CIRCUITPY" + the last four hex digits of ``adapter.address``,
122
- //| to make it easy to distinguish multiple CircuitPython boards.
117
+ //| name: Any = ...
118
+ //| """name of the BLE adapter used once connected.
119
+ //| The name is "CIRCUITPY" + the last four hex digits of ``adapter.address``,
120
+ //| to make it easy to distinguish multiple CircuitPython boards."""
123
121
//|
124
122
STATIC mp_obj_t bleio_adapter_get_name (mp_obj_t self ) {
125
123
return MP_OBJ_FROM_PTR (common_hal_bleio_adapter_get_name (self ));
@@ -140,18 +138,18 @@ const mp_obj_property_t bleio_adapter_name_obj = {
140
138
(mp_obj_t )& mp_const_none_obj },
141
139
};
142
140
143
- //| .. method:: start_advertising(data, *, scan_response=None, connectable=True, interval=0.1)
144
- //|
145
- //| Starts advertising until `stop_advertising` is called or if connectable, another device
146
- //| connects to us.
141
+ //| def start_advertising(self, data: buf, *, scan_response: buf = None, connectable: bool = True, interval: float = 0.1) -> Any:
142
+ //| """Starts advertising until `stop_advertising` is called or if connectable, another device
143
+ //| connects to us.
147
144
//|
148
- //| .. warning: If data is longer than 31 bytes, then this will automatically advertise as an
149
- //| extended advertisement that older BLE 4.x clients won't be able to scan for.
145
+ //| .. warning: If data is longer than 31 bytes, then this will automatically advertise as an
146
+ //| extended advertisement that older BLE 4.x clients won't be able to scan for.
150
147
//|
151
- //| :param buf data: advertising data packet bytes
152
- //| :param buf scan_response: scan response data packet bytes. ``None`` if no scan response is needed.
153
- //| :param bool connectable: If `True` then other devices are allowed to connect to this peripheral.
154
- //| :param float interval: advertising interval, in seconds
148
+ //| :param buf data: advertising data packet bytes
149
+ //| :param buf scan_response: scan response data packet bytes. ``None`` if no scan response is needed.
150
+ //| :param bool connectable: If `True` then other devices are allowed to connect to this peripheral.
151
+ //| :param float interval: advertising interval, in seconds"""
152
+ //| ...
155
153
//|
156
154
STATIC mp_obj_t bleio_adapter_start_advertising (mp_uint_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
157
155
bleio_adapter_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
@@ -198,9 +196,10 @@ STATIC mp_obj_t bleio_adapter_start_advertising(mp_uint_t n_args, const mp_obj_t
198
196
}
199
197
STATIC MP_DEFINE_CONST_FUN_OBJ_KW (bleio_adapter_start_advertising_obj , 2 , bleio_adapter_start_advertising );
200
198
201
- //| .. method:: stop_advertising()
199
+ //| def stop_advertising(self, ) -> Any:
200
+ //| """Stop sending advertising packets."""
201
+ //| ...
202
202
//|
203
- //| Stop sending advertising packets.
204
203
STATIC mp_obj_t bleio_adapter_stop_advertising (mp_obj_t self_in ) {
205
204
bleio_adapter_obj_t * self = MP_OBJ_TO_PTR (self_in );
206
205
@@ -210,25 +209,25 @@ STATIC mp_obj_t bleio_adapter_stop_advertising(mp_obj_t self_in) {
210
209
}
211
210
STATIC MP_DEFINE_CONST_FUN_OBJ_1 (bleio_adapter_stop_advertising_obj , bleio_adapter_stop_advertising );
212
211
213
- //| .. method:: start_scan(prefixes=b"", \*, buffer_size=512, extended=False, timeout=None, interval=0.1, window=0.1, minimum_rssi=-80, active=True)
212
+ //| def start_scan(self, prefixes: sequence = b"", *, buffer_size: int = 512, extended: bool = False, timeout: float = None, interval: float = 0.1, window: float = 0.1, minimum_rssi: int = -80, active: bool = True) -> Any:
213
+ //| """Starts a BLE scan and returns an iterator of results. Advertisements and scan responses are
214
+ //| filtered and returned separately.
214
215
//|
215
- //| Starts a BLE scan and returns an iterator of results. Advertisements and scan responses are
216
- //| filtered and returned separately.
217
- //|
218
- //| :param sequence prefixes: Sequence of byte string prefixes to filter advertising packets
219
- //| with. A packet without an advertising structure that matches one of the prefixes is
220
- //| ignored. Format is one byte for length (n) and n bytes of prefix and can be repeated.
221
- //| :param int buffer_size: the maximum number of advertising bytes to buffer.
222
- //| :param bool extended: When True, support extended advertising packets. Increasing buffer_size is recommended when this is set.
223
- //| :param float timeout: the scan timeout in seconds. If None, will scan until `stop_scan` is called.
224
- //| :param float interval: the interval (in seconds) between the start of two consecutive scan windows
225
- //| Must be in the range 0.0025 - 40.959375 seconds.
226
- //| :param float window: the duration (in seconds) to scan a single BLE channel.
227
- //| window must be <= interval.
228
- //| :param int minimum_rssi: the minimum rssi of entries to return.
229
- //| :param bool active: retrieve scan responses for scannable advertisements.
230
- //| :returns: an iterable of `_bleio.ScanEntry` objects
231
- //| :rtype: iterable
216
+ //| :param sequence prefixes: Sequence of byte string prefixes to filter advertising packets
217
+ //| with. A packet without an advertising structure that matches one of the prefixes is
218
+ //| ignored. Format is one byte for length (n) and n bytes of prefix and can be repeated.
219
+ //| :param int buffer_size: the maximum number of advertising bytes to buffer.
220
+ //| :param bool extended: When True, support extended advertising packets. Increasing buffer_size is recommended when this is set.
221
+ //| :param float timeout: the scan timeout in seconds. If None, will scan until `stop_scan` is called.
222
+ //| :param float interval: the interval (in seconds) between the start of two consecutive scan windows
223
+ //| Must be in the range 0.0025 - 40.959375 seconds.
224
+ //| :param float window: the duration (in seconds) to scan a single BLE channel.
225
+ //| window must be <= interval.
226
+ //| :param int minimum_rssi: the minimum rssi of entries to return.
227
+ //| :param bool active: retrieve scan responses for scannable advertisements.
228
+ //| :returns: an iterable of `_bleio.ScanEntry` objects
229
+ //| :rtype: iterable"""
230
+ //| ...
232
231
//|
233
232
STATIC mp_obj_t bleio_adapter_start_scan (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
234
233
enum { ARG_prefixes , ARG_buffer_size , ARG_extended , ARG_timeout , ARG_interval , ARG_window , ARG_minimum_rssi , ARG_active };
@@ -283,9 +282,10 @@ STATIC mp_obj_t bleio_adapter_start_scan(size_t n_args, const mp_obj_t *pos_args
283
282
}
284
283
STATIC MP_DEFINE_CONST_FUN_OBJ_KW (bleio_adapter_start_scan_obj , 1 , bleio_adapter_start_scan );
285
284
286
- //| .. method:: stop_scan()
285
+ //| def stop_scan(self, ) -> Any:
286
+ //| """Stop the current scan."""
287
+ //| ...
287
288
//|
288
- //| Stop the current scan.
289
289
STATIC mp_obj_t bleio_adapter_stop_scan (mp_obj_t self_in ) {
290
290
bleio_adapter_obj_t * self = MP_OBJ_TO_PTR (self_in );
291
291
@@ -295,10 +295,9 @@ STATIC mp_obj_t bleio_adapter_stop_scan(mp_obj_t self_in) {
295
295
}
296
296
STATIC MP_DEFINE_CONST_FUN_OBJ_1 (bleio_adapter_stop_scan_obj , bleio_adapter_stop_scan );
297
297
298
- //| .. attribute:: connected
299
- //|
300
- //| True when the adapter is connected to another device regardless of who initiated the
301
- //| connection. (read-only)
298
+ //| connected: Any = ...
299
+ //| """True when the adapter is connected to another device regardless of who initiated the
300
+ //| connection. (read-only)"""
302
301
//|
303
302
STATIC mp_obj_t bleio_adapter_get_connected (mp_obj_t self ) {
304
303
return mp_obj_new_bool (common_hal_bleio_adapter_get_connected (self ));
@@ -313,10 +312,9 @@ const mp_obj_property_t bleio_adapter_connected_obj = {
313
312
(mp_obj_t )& mp_const_none_obj },
314
313
};
315
314
316
- //| .. attribute:: connections
317
- //|
318
- //| Tuple of active connections including those initiated through
319
- //| :py:meth:`_bleio.Adapter.connect`. (read-only)
315
+ //| connections: Any = ...
316
+ //| """Tuple of active connections including those initiated through
317
+ //| :py:meth:`_bleio.Adapter.connect`. (read-only)"""
320
318
//|
321
319
STATIC mp_obj_t bleio_adapter_get_connections (mp_obj_t self ) {
322
320
return common_hal_bleio_adapter_get_connections (self );
@@ -330,12 +328,12 @@ const mp_obj_property_t bleio_adapter_connections_obj = {
330
328
(mp_obj_t )& mp_const_none_obj },
331
329
};
332
330
333
- //| .. method:: connect(address, *, timeout)
334
- //|
335
- //| Attempts a connection to the device with the given address.
331
+ //| def connect(self, address: Address, *, timeout: float/int) -> Any:
332
+ //| """Attempts a connection to the device with the given address.
336
333
//|
337
- //| :param Address address: The address of the peripheral to connect to
338
- //| :param float/int timeout: Try to connect for timeout seconds.
334
+ //| :param Address address: The address of the peripheral to connect to
335
+ //| :param float/int timeout: Try to connect for timeout seconds."""
336
+ //| ...
339
337
//|
340
338
STATIC mp_obj_t bleio_adapter_connect (mp_uint_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
341
339
bleio_adapter_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
@@ -360,9 +358,10 @@ STATIC mp_obj_t bleio_adapter_connect(mp_uint_t n_args, const mp_obj_t *pos_args
360
358
}
361
359
STATIC MP_DEFINE_CONST_FUN_OBJ_KW (bleio_adapter_connect_obj , 2 , bleio_adapter_connect );
362
360
363
- //| .. method:: erase_bonding()
361
+ //| def erase_bonding(self, ) -> Any:
362
+ //| """Erase all bonding information stored in flash memory."""
363
+ //| ...
364
364
//|
365
- //| Erase all bonding information stored in flash memory.
366
365
STATIC mp_obj_t bleio_adapter_erase_bonding (mp_obj_t self_in ) {
367
366
bleio_adapter_obj_t * self = MP_OBJ_TO_PTR (self_in );
368
367
0 commit comments