34
34
#include "py/objproperty.h"
35
35
#include "py/objstr.h"
36
36
#include "py/runtime.h"
37
- #include "shared-bindings/bleio/__init__.h"
38
37
#include "shared-bindings/bleio/Adapter.h"
39
38
#include "shared-bindings/bleio/Address.h"
40
39
#include "shared-bindings/bleio/Characteristic.h"
66
65
//|
67
66
//| central = bleio.Central()
68
67
//| central.connect(my_entry.address, 10) # timeout after 10 seconds
69
- //| central.discover_remote_services()
68
+ //| remote_services = central.discover_remote_services()
70
69
//|
71
70
72
71
//| .. class:: Central()
@@ -132,15 +131,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_disconnect_obj, bleio_central_dis
132
131
133
132
//| .. method:: discover_remote_services(service_uuids_whitelist=None)
134
133
//| Do BLE discovery for all services or for the given service UUIDS,
135
- //| to find their handles and characteristics.
136
- //| The attribute `remote_services` will contain a list of all discovered services.
137
- //| `Central.connected` must be True.
134
+ //| to find their handles and characteristics, and return the discovered services.
135
+ //| `Peripheral.connected` must be True.
138
136
//|
139
137
//| :param iterable service_uuids_whitelist: an iterable of :py:class:~`UUID` objects for the services
140
138
//| provided by the peripheral that you want to use.
141
- //| The peripheral may provide more services, but services not listed are ignored.
142
- //| If a service in service_uuids_whitelist is not found during discovery, it will not
143
- //| appear in `remote_services`.
139
+ //| The peripheral may provide more services, but services not listed are ignored
140
+ //| and will not be returned.
144
141
//|
145
142
//| If service_uuids_whitelist is None, then all services will undergo discovery, which can be slow.
146
143
//|
@@ -149,6 +146,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_disconnect_obj, bleio_central_dis
149
146
//| service or characteristic to be discovered. Creating the UUID causes the UUID to be registered
150
147
//| for use. (This restriction may be lifted in the future.)
151
148
//|
149
+ //| :return: A tuple of services provided by the remote peripheral.
150
+ //|
152
151
STATIC mp_obj_t bleio_central_discover_remote_services (mp_uint_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
153
152
bleio_central_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
154
153
@@ -164,10 +163,9 @@ STATIC mp_obj_t bleio_central_discover_remote_services(mp_uint_t n_args, const m
164
163
mp_raise_ValueError (translate ("Not connected" ));
165
164
}
166
165
167
- common_hal_bleio_device_discover_remote_services (MP_OBJ_FROM_PTR (self ),
168
- args [ARG_service_uuids_whitelist ].u_obj );
169
-
170
- return mp_const_none ;
166
+ return MP_OBJ_FROM_PTR (common_hal_bleio_central_discover_remote_services (
167
+ MP_OBJ_FROM_PTR (self ),
168
+ args [ARG_service_uuids_whitelist ].u_obj ));
171
169
}
172
170
STATIC MP_DEFINE_CONST_FUN_OBJ_KW (bleio_central_discover_remote_services_obj , 1 , bleio_central_discover_remote_services );
173
171
@@ -189,28 +187,6 @@ const mp_obj_property_t bleio_central_connected_obj = {
189
187
(mp_obj_t )& mp_const_none_obj },
190
188
};
191
189
192
-
193
- //| .. attribute:: remote_services (read-only)
194
- //|
195
- //| A tuple of services provided by the remote peripheral.
196
- //| If the Central is not connected, an empty tuple will be returned.
197
- //|
198
- STATIC mp_obj_t bleio_central_get_remote_services (mp_obj_t self_in ) {
199
- bleio_central_obj_t * self = MP_OBJ_TO_PTR (self_in );
200
-
201
- // Return list as a tuple so user won't be able to change it.
202
- mp_obj_list_t * service_list = common_hal_bleio_central_get_remote_services (self );
203
- return mp_obj_new_tuple (service_list -> len , service_list -> items );
204
- }
205
- STATIC MP_DEFINE_CONST_FUN_OBJ_1 (bleio_central_get_remote_services_obj , bleio_central_get_remote_services );
206
-
207
- const mp_obj_property_t bleio_central_remote_services_obj = {
208
- .base .type = & mp_type_property ,
209
- .proxy = { (mp_obj_t )& bleio_central_get_remote_services_obj ,
210
- (mp_obj_t )& mp_const_none_obj ,
211
- (mp_obj_t )& mp_const_none_obj },
212
- };
213
-
214
190
STATIC const mp_rom_map_elem_t bleio_central_locals_dict_table [] = {
215
191
// Methods
216
192
{ MP_ROM_QSTR (MP_QSTR_connect ), MP_ROM_PTR (& bleio_central_connect_obj ) },
@@ -219,7 +195,6 @@ STATIC const mp_rom_map_elem_t bleio_central_locals_dict_table[] = {
219
195
220
196
// Properties
221
197
{ MP_ROM_QSTR (MP_QSTR_connected ), MP_ROM_PTR (& bleio_central_connected_obj ) },
222
- { MP_ROM_QSTR (MP_QSTR_remote_services ), MP_ROM_PTR (& bleio_central_remote_services_obj ) },
223
198
};
224
199
225
200
STATIC MP_DEFINE_CONST_DICT (bleio_central_locals_dict , bleio_central_locals_dict_table );
0 commit comments