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[] = {
64
64
65
65
STATIC MP_DEFINE_CONST_DICT (microbit_button_locals_dict , microbit_button_locals_dict_table );
66
66
67
- STATIC const mp_obj_type_t microbit_button_type = {
67
+ const mp_obj_type_t microbit_button_type = {
68
68
{ & mp_type_type },
69
69
.name = MP_QSTR_MicroBitButton ,
70
70
.locals_dict = (mp_obj_dict_t * )& microbit_button_locals_dict ,
@@ -81,3 +81,8 @@ const microbit_button_obj_t microbit_button_b_obj = {
81
81
.pin = & microbit_p11_obj ,
82
82
.button_id = 1 ,
83
83
};
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 = {
266
266
267
267
const microbit_pin_obj_t * microbit_obj_get_pin (mp_const_obj_t o ) {
268
268
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 ) ) {
270
270
return (microbit_pin_obj_t * )o ;
271
271
} else {
272
272
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;
80
80
81
81
extern const microbit_pinmode_t microbit_pinmodes [];
82
82
83
+ extern const mp_obj_type_t microbit_button_type ;
83
84
extern const mp_obj_type_t microbit_ad_pin_type ;
84
85
extern const mp_obj_type_t microbit_dig_pin_type ;
85
86
extern const mp_obj_type_t microbit_touch_pin_type ;
@@ -192,6 +193,17 @@ extern const struct _microbit_microphone_obj_t microbit_microphone_obj;
192
193
extern const struct _microbit_button_obj_t microbit_button_a_obj ;
193
194
extern const struct _microbit_button_obj_t microbit_button_b_obj ;
194
195
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
+
195
207
const microbit_pin_obj_t * microbit_obj_get_pin (mp_const_obj_t o );
196
208
uint8_t microbit_obj_get_pin_name (mp_obj_t o );
197
209
You can’t perform that action at this time.
0 commit comments