@@ -92,26 +92,49 @@ STATIC mp_obj_t bleio_connection_disconnect(mp_obj_t self_in) {
9292}
9393STATIC MP_DEFINE_CONST_FUN_OBJ_1 (bleio_connection_disconnect_obj , bleio_connection_disconnect );
9494
95+
96+ //| .. method:: pair(*, bond=True)
97+ //|
98+ //| Pair to the peer to improve security.
99+ //|
100+ STATIC mp_obj_t bleio_connection_pair (mp_uint_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
101+ bleio_connection_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
102+
103+ enum { ARG_bond };
104+ static const mp_arg_t allowed_args [] = {
105+ { MP_QSTR_bond , MP_ARG_BOOL , {.u_bool = true} },
106+ };
107+
108+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
109+ mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
110+
111+ ensure_connected (self );
112+
113+ common_hal_bleio_connection_pair (self -> connection , args [ARG_bond ].u_bool );
114+ return mp_const_none ;
115+ }
116+ STATIC MP_DEFINE_CONST_FUN_OBJ_KW (bleio_connection_pair_obj , 1 , bleio_connection_pair );
117+
95118//| .. method:: discover_remote_services(service_uuids_whitelist=None)
96119//|
97120//| Do BLE discovery for all services or for the given service UUIDS,
98121//| to find their handles and characteristics, and return the discovered services.
99122//| `Connection.connected` must be True.
100123//|
101124//| :param iterable service_uuids_whitelist:
102- //|
125+ //|
103126//| an iterable of :py:class:~`UUID` objects for the services provided by the peripheral
104127//| that you want to use.
105128//|
106129//| The peripheral may provide more services, but services not listed are ignored
107130//| and will not be returned.
108131//|
109- //| If service_uuids_whitelist is None, then all services will undergo discovery, which can be
132+ //| If service_uuids_whitelist is None, then all services will undergo discovery, which can be
110133//| slow.
111134//|
112135//| If the service UUID is 128-bit, or its characteristic UUID's are 128-bit, you
113136//| you must have already created a :py:class:~`UUID` object for that UUID in order for the
114- //| service or characteristic to be discovered. Creating the UUID causes the UUID to be
137+ //| service or characteristic to be discovered. Creating the UUID causes the UUID to be
115138//| registered for use. (This restriction may be lifted in the future.)
116139//|
117140//| :return: A tuple of `_bleio.Service` objects provided by the remote peripheral.
@@ -137,7 +160,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_connection_discover_remote_services_obj,
137160
138161//| .. attribute:: connected
139162//|
140- //| True if connected to a remote peer.
163+ //| True if connected to the remote peer.
141164//|
142165STATIC mp_obj_t bleio_connection_get_connected (mp_obj_t self_in ) {
143166 bleio_connection_obj_t * self = MP_OBJ_TO_PTR (self_in );
@@ -153,13 +176,34 @@ const mp_obj_property_t bleio_connection_connected_obj = {
153176 (mp_obj_t )& mp_const_none_obj },
154177};
155178
179+
180+ //| .. attribute:: paired
181+ //|
182+ //| True if paired to the remote peer.
183+ //|
184+ STATIC mp_obj_t bleio_connection_get_paired (mp_obj_t self_in ) {
185+ bleio_connection_obj_t * self = MP_OBJ_TO_PTR (self_in );
186+
187+ return mp_obj_new_bool (common_hal_bleio_connection_get_paired (self ));
188+ }
189+ STATIC MP_DEFINE_CONST_FUN_OBJ_1 (bleio_connection_get_paired_obj , bleio_connection_get_paired );
190+
191+ const mp_obj_property_t bleio_connection_paired_obj = {
192+ .base .type = & mp_type_property ,
193+ .proxy = { (mp_obj_t )& bleio_connection_get_paired_obj ,
194+ (mp_obj_t )& mp_const_none_obj ,
195+ (mp_obj_t )& mp_const_none_obj },
196+ };
197+
156198STATIC const mp_rom_map_elem_t bleio_connection_locals_dict_table [] = {
157199 // Methods
200+ { MP_ROM_QSTR (MP_QSTR_pair ), MP_ROM_PTR (& bleio_connection_pair_obj ) },
158201 { MP_ROM_QSTR (MP_QSTR_disconnect ), MP_ROM_PTR (& bleio_connection_disconnect_obj ) },
159202 { MP_ROM_QSTR (MP_QSTR_discover_remote_services ), MP_ROM_PTR (& bleio_connection_discover_remote_services_obj ) },
160203
161204 // Properties
162205 { MP_ROM_QSTR (MP_QSTR_connected ), MP_ROM_PTR (& bleio_connection_connected_obj ) },
206+ { MP_ROM_QSTR (MP_QSTR_paired ), MP_ROM_PTR (& bleio_connection_paired_obj ) },
163207};
164208
165209STATIC MP_DEFINE_CONST_DICT (bleio_connection_locals_dict , bleio_connection_locals_dict_table );
0 commit comments