File tree Expand file tree Collapse file tree 3 files changed +19
-2
lines changed
Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ STATIC const mp_map_elem_t microbit_button_locals_dict_table[] = {
6464
6565STATIC MP_DEFINE_CONST_DICT (microbit_button_locals_dict , microbit_button_locals_dict_table );
6666
67- STATIC const mp_obj_type_t microbit_button_type = {
67+ const mp_obj_type_t microbit_button_type = {
6868 { & mp_type_type },
6969 .name = MP_QSTR_MicroBitButton ,
7070 .locals_dict = (mp_obj_dict_t * )& microbit_button_locals_dict ,
@@ -81,3 +81,8 @@ const microbit_button_obj_t microbit_button_b_obj = {
8181 .pin = & microbit_p11_obj ,
8282 .button_id = 1 ,
8383};
84+
85+ // This function assumes "button" is of type microbit_button_type.
86+ uint8_t microbit_obj_get_button_id (mp_obj_t button ) {
87+ return ((microbit_button_obj_t * )MP_OBJ_TO_PTR (button ))-> button_id ;
88+ }
Original file line number Diff line number Diff line change @@ -266,7 +266,7 @@ const mp_obj_type_t microbit_touch_only_pin_type = {
266266
267267const microbit_pin_obj_t * microbit_obj_get_pin (mp_const_obj_t o ) {
268268 const mp_obj_type_t * type = mp_obj_get_type (o );
269- if (type == & microbit_touch_pin_type || type == & microbit_ad_pin_type || type == & microbit_dig_pin_type ) {
269+ if (microbit_obj_type_is_pin ( type ) ) {
270270 return (microbit_pin_obj_t * )o ;
271271 } else {
272272 mp_raise_TypeError (MP_ERROR_TEXT ("expecting a pin" ));
Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ typedef struct _microbit_soundevent_obj_t microbit_soundevent_obj_t;
8080
8181extern const microbit_pinmode_t microbit_pinmodes [];
8282
83+ extern const mp_obj_type_t microbit_button_type ;
8384extern const mp_obj_type_t microbit_ad_pin_type ;
8485extern const mp_obj_type_t microbit_dig_pin_type ;
8586extern const mp_obj_type_t microbit_touch_pin_type ;
@@ -192,6 +193,17 @@ extern const struct _microbit_microphone_obj_t microbit_microphone_obj;
192193extern const struct _microbit_button_obj_t microbit_button_a_obj ;
193194extern const struct _microbit_button_obj_t microbit_button_b_obj ;
194195
196+ static inline bool microbit_obj_type_is_button (const mp_obj_type_t * type ) {
197+ return type == & microbit_button_type ;
198+ }
199+
200+ static inline bool microbit_obj_type_is_pin (const mp_obj_type_t * type ) {
201+ return type == & microbit_touch_pin_type || type == & microbit_ad_pin_type || type == & microbit_dig_pin_type ;
202+ }
203+
204+ // This function assumes "button" is of type microbit_button_type.
205+ uint8_t microbit_obj_get_button_id (mp_obj_t button );
206+
195207const microbit_pin_obj_t * microbit_obj_get_pin (mp_const_obj_t o );
196208uint8_t microbit_obj_get_pin_name (mp_obj_t o );
197209
You can’t perform that action at this time.
0 commit comments