@@ -85,10 +85,6 @@ static pbdrv_bluetooth_peripheral_char_t pb_lwp3device_char = {
8585 .request_notification = true,
8686};
8787
88- // Needed for global notification callback. This is cleared when the finalizer
89- // runs.
90- static mp_obj_t self_obj ;
91-
9288typedef struct {
9389 mp_obj_base_t base ;
9490 /**
@@ -172,16 +168,15 @@ static void handle_remote_notification(void *user, const uint8_t *value, uint32_
172168 }
173169}
174170
175- static pbdrv_bluetooth_ad_match_result_flags_t lwp3_advertisement_matches (uint8_t event_type , const uint8_t * data , const char * name , const uint8_t * addr , const uint8_t * match_addr ) {
171+ static pbdrv_bluetooth_ad_match_result_flags_t lwp3_advertisement_matches (void * user , uint8_t event_type , const uint8_t * data , const char * name , const uint8_t * addr , const uint8_t * match_addr ) {
176172
177173 pbdrv_bluetooth_ad_match_result_flags_t flags = PBDRV_BLUETOOTH_AD_MATCH_NONE ;
178174
179- if (self_obj == MP_OBJ_NULL ) {
175+ pb_lwp3device_obj_t * self = user ;
176+ if (!self ) {
180177 return flags ;
181178 }
182179
183- pb_lwp3device_obj_t * self = MP_OBJ_TO_PTR (self_obj );
184-
185180 // Whether this looks like a LWP3 advertisement of the correct hub kind.
186181 if (event_type == PBDRV_BLUETOOTH_AD_TYPE_ADV_IND
187182 && data [3 ] == 17 /* length */
@@ -199,16 +194,15 @@ static pbdrv_bluetooth_ad_match_result_flags_t lwp3_advertisement_matches(uint8_
199194 return flags ;
200195}
201196
202- static pbdrv_bluetooth_ad_match_result_flags_t lwp3_advertisement_response_matches (uint8_t event_type , const uint8_t * data , const char * name , const uint8_t * addr , const uint8_t * match_addr ) {
197+ static pbdrv_bluetooth_ad_match_result_flags_t lwp3_advertisement_response_matches (void * user , uint8_t event_type , const uint8_t * data , const char * name , const uint8_t * addr , const uint8_t * match_addr ) {
203198
204199 pbdrv_bluetooth_ad_match_result_flags_t flags = PBDRV_BLUETOOTH_AD_MATCH_NONE ;
205200
206- if (self_obj == MP_OBJ_NULL ) {
201+ pb_lwp3device_obj_t * self = user ;
202+ if (!self ) {
207203 return flags ;
208204 }
209205
210- pb_lwp3device_obj_t * self = MP_OBJ_TO_PTR (self_obj );
211-
212206 // This is the only value check we do on LWP3 response messages.
213207 if (event_type == PBDRV_BLUETOOTH_AD_TYPE_SCAN_RSP ) {
214208 flags |= PBDRV_BLUETOOTH_AD_MATCH_VALUE ;
@@ -493,7 +487,6 @@ static mp_obj_t pb_type_pupdevices_Remote_make_new(const mp_obj_type_t *type, si
493487 pb_module_tools_assert_blocking ();
494488
495489 pb_lwp3device_obj_t * self = mp_obj_malloc_with_finaliser (pb_lwp3device_obj_t , type );
496- self_obj = MP_OBJ_FROM_PTR (self );
497490
498491 self -> buttons = pb_type_Keypad_obj_new (MP_OBJ_FROM_PTR (self ), pb_type_remote_button_pressed );
499492 self -> light = pb_type_ColorLight_external_obj_new (MP_OBJ_FROM_PTR (self ), pb_type_pupdevices_Remote_light_on );
@@ -624,7 +617,6 @@ static mp_obj_t pb_type_iodevices_LWP3Device_make_new(const mp_obj_type_t *type,
624617 }
625618
626619 pb_lwp3device_obj_t * self = mp_obj_malloc_var_with_finaliser (pb_lwp3device_obj_t , uint8_t , LWP3_MAX_MESSAGE_SIZE * noti_num , type );
627- self_obj = MP_OBJ_FROM_PTR (self );
628620
629621 memset (self -> notification_buffer , 0 , LWP3_MAX_MESSAGE_SIZE * noti_num );
630622 self -> noti_num = noti_num ;
0 commit comments