Skip to content

Commit c465a34

Browse files
committed
pybricks.parameters.Button: add BT button
Make the Bluetooth button of the SPIKE Prime Hub accessible.
1 parent c16a761 commit c465a34

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

pybricks/common/pb_type_keypad.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
// TODO: buttons are currently a module due to the legacy C API, but should be
1818
// an instance of a KeyPad type. That would make it consistent with the other C
19-
// types and the high level Python API.
19+
// types and the high level Python API, and simplify device-specific buttons.
2020

2121
STATIC mp_obj_t buttons_pressed(void) {
2222
mp_obj_t button_list[10];
@@ -35,7 +35,11 @@ STATIC mp_obj_t buttons_pressed(void) {
3535
button_list[size++] = MP_OBJ_FROM_PTR(&pb_Button_RIGHT_obj);
3636
}
3737
if (pressed & PBIO_BUTTON_RIGHT_UP) {
38+
#ifdef PYBRICKS_HUB_PRIMEHUB
39+
button_list[size++] = MP_OBJ_FROM_PTR(&pb_Button_BT_obj);
40+
#else
3841
button_list[size++] = MP_OBJ_FROM_PTR(&pb_Button_RIGHT_UP_obj);
42+
#endif
3943
}
4044
if (pressed & PBIO_BUTTON_UP) {
4145
button_list[size++] = MP_OBJ_FROM_PTR(&pb_Button_UP_obj);

pybricks/parameters.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ const pb_obj_enum_member_t pb_Button_LEFT_UP_obj;
2727
const pb_obj_enum_member_t pb_Button_LEFT_DOWN_obj;
2828
const pb_obj_enum_member_t pb_Button_RIGHT_UP_obj;
2929
const pb_obj_enum_member_t pb_Button_RIGHT_DOWN_obj;
30+
#if PYBRICKS_HUB_EV3BRICK
3031
const pb_obj_enum_member_t pb_Button_BEACON_obj;
32+
#endif
33+
#if PYBRICKS_HUB_PRIMEHUB
34+
const pb_obj_enum_member_t pb_Button_BT_obj;
35+
#endif
3136

3237
#endif // PYBRICKS_PY_PARAMETERS_BUTTON
3338

pybricks/parameters/pb_type_button.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,21 @@ const pb_obj_enum_member_t pb_Button_RIGHT_DOWN_obj = {
7070
.value = PBIO_BUTTON_RIGHT_DOWN
7171
};
7272

73+
#if PYBRICKS_HUB_EV3BRICK
7374
const pb_obj_enum_member_t pb_Button_BEACON_obj = {
7475
{&pb_enum_type_Button},
7576
.name = MP_QSTR_BEACON,
7677
.value = PBIO_BUTTON_UP
7778
};
79+
#endif
80+
81+
#if PYBRICKS_HUB_PRIMEHUB
82+
const pb_obj_enum_member_t pb_Button_BT_obj = {
83+
{&pb_enum_type_Button},
84+
.name = MP_QSTR_BT,
85+
.value = PBIO_BUTTON_RIGHT_UP
86+
};
87+
#endif
7888

7989
STATIC const mp_rom_map_elem_t pb_enum_Button_table[] = {
8090
{ MP_ROM_QSTR(MP_QSTR_UP), MP_ROM_PTR(&pb_Button_UP_obj) },
@@ -86,7 +96,12 @@ STATIC const mp_rom_map_elem_t pb_enum_Button_table[] = {
8696
{ MP_ROM_QSTR(MP_QSTR_LEFT_DOWN), MP_ROM_PTR(&pb_Button_LEFT_DOWN_obj) },
8797
{ MP_ROM_QSTR(MP_QSTR_RIGHT_UP), MP_ROM_PTR(&pb_Button_RIGHT_UP_obj) },
8898
{ MP_ROM_QSTR(MP_QSTR_RIGHT_DOWN), MP_ROM_PTR(&pb_Button_RIGHT_DOWN_obj)},
99+
#if PYBRICKS_HUB_EV3BRICK
89100
{ MP_ROM_QSTR(MP_QSTR_BEACON), MP_ROM_PTR(&pb_Button_BEACON_obj) },
101+
#endif
102+
#ifdef PYBRICKS_HUB_PRIMEHUB
103+
{ MP_ROM_QSTR(MP_QSTR_BT), MP_ROM_PTR(&pb_Button_BT_obj) },
104+
#endif
90105
};
91106
STATIC MP_DEFINE_CONST_DICT(pb_enum_type_Button_locals_dict, pb_enum_Button_table);
92107

0 commit comments

Comments
 (0)