Skip to content

Commit c90eb29

Browse files
committed
Allow a more direct access to the joystick/button API than via getKey.
1 parent ecd5bb9 commit c90eb29

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/Braccio++.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,22 +272,22 @@ void BraccioClass::motors_connected_thread() {
272272
}
273273

274274
int BraccioClass::getKey() {
275-
if (digitalRead(BTN_LEFT) == LOW) {
275+
if (isJoystickPressed_LEFT()) {
276276
return 1;
277277
}
278-
if (digitalRead(BTN_RIGHT) == LOW) {
278+
if (isJoystickPressed_RIGHT()) {
279279
return 2;
280280
}
281-
if (digitalRead(BTN_SEL) == LOW) {
281+
if (isJoystickPressed_SELECT()) {
282282
return 3;
283283
}
284-
if (digitalRead(BTN_UP) == LOW) {
284+
if (isJoystickPressed_UP()) {
285285
return 4;
286286
}
287-
if (digitalRead(BTN_DOWN) == LOW) {
287+
if (isJoystickPressed_DOWN()) {
288288
return 5;
289289
}
290-
if (digitalRead(BTN_ENTER) == LOW) {
290+
if (isButtonPressed_ENTER()) {
291291
return 6;
292292
}
293293
return 0;

src/Braccio++.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ class BraccioClass
146146
int getKey();
147147
void connectJoystickTo(lv_obj_t* obj);
148148

149+
inline bool isJoystickPressed_LEFT() { return (digitalRead(BTN_LEFT) == LOW); }
150+
inline bool isJoystickPressed_RIGHT() { return (digitalRead(BTN_RIGHT) == LOW); }
151+
inline bool isJoystickPressed_SELECT() { return (digitalRead(BTN_SEL) == LOW); }
152+
inline bool isJoystickPressed_UP() { return (digitalRead(BTN_UP) == LOW); }
153+
inline bool isJoystickPressed_DOWN() { return (digitalRead(BTN_DOWN) == LOW); }
154+
inline bool isButtonPressed_ENTER() { return (digitalRead(BTN_ENTER) == LOW); }
155+
149156
TFT_eSPI gfx = TFT_eSPI();
150157

151158
bool ping_allowed = true;

0 commit comments

Comments
 (0)