Skip to content

Commit cd92069

Browse files
author
Scott Powell
committed
* UITask: new UI_HAS_JOYSTICK
* MomentaryButton: new constructor 'multiclick' param * WIoTrackerL1: now just use joystick, joystick press for KEY_ENTER, no multi-click for snappier UI
1 parent d3be6af commit cd92069

File tree

7 files changed

+32
-18
lines changed

7 files changed

+32
-18
lines changed

examples/companion_radio/ui-new/UITask.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
#define UI_RECENT_LIST_SIZE 4
2121
#endif
2222

23-
#define PRESS_LABEL "long press"
23+
#if UI_HAS_JOYSTICK
24+
#define PRESS_LABEL "press Enter"
25+
#else
26+
#define PRESS_LABEL "long press"
27+
#endif
2428

2529
#include "icons.h"
2630

@@ -360,7 +364,7 @@ class HomeScreen : public UIScreen {
360364
display.drawTextCentered(display.width() / 2, 34, "hibernating...");
361365
} else {
362366
display.drawXbm((display.width() - 32) / 2, 18, power_icon, 32, 32);
363-
display.drawTextCentered(display.width() / 2, 64 - 11, "hibernate: " PRESS_LABEL);
367+
display.drawTextCentered(display.width() / 2, 64 - 11, "hibernate:" PRESS_LABEL);
364368
}
365369
}
366370
return 5000; // next render after 5000 ms
@@ -660,19 +664,13 @@ bool UITask::isButtonPressed() const {
660664

661665
void UITask::loop() {
662666
char c = 0;
663-
#if defined(PIN_USER_BTN)
667+
#if UI_HAS_JOYSTICK
664668
int ev = user_btn.check();
665669
if (ev == BUTTON_EVENT_CLICK) {
666-
c = checkDisplayOn(KEY_NEXT);
670+
c = checkDisplayOn(KEY_ENTER);
667671
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
668-
c = handleLongPress(KEY_ENTER);
669-
} else if (ev == BUTTON_EVENT_DOUBLE_CLICK) {
670-
c = handleDoubleClick(KEY_PREV);
671-
} else if (ev == BUTTON_EVENT_TRIPLE_CLICK) {
672-
c = handleTripleClick(KEY_SELECT);
672+
c = handleLongPress(KEY_ENTER); // REVISIT: could be mapped to different key code
673673
}
674-
#endif
675-
#if defined(WIO_TRACKER_L1)
676674
ev = joystick_left.check();
677675
if (ev == BUTTON_EVENT_CLICK) {
678676
c = checkDisplayOn(KEY_LEFT);
@@ -685,6 +683,17 @@ void UITask::loop() {
685683
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
686684
c = handleLongPress(KEY_RIGHT);
687685
}
686+
#elif defined(PIN_USER_BTN)
687+
int ev = user_btn.check();
688+
if (ev == BUTTON_EVENT_CLICK) {
689+
c = checkDisplayOn(KEY_NEXT);
690+
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
691+
c = handleLongPress(KEY_ENTER);
692+
} else if (ev == BUTTON_EVENT_DOUBLE_CLICK) {
693+
c = handleDoubleClick(KEY_PREV);
694+
} else if (ev == BUTTON_EVENT_TRIPLE_CLICK) {
695+
c = handleTripleClick(KEY_SELECT);
696+
}
688697
#endif
689698
#if defined(PIN_USER_BTN_ANA)
690699
ev = analog_btn.check();

src/helpers/ui/MomentaryButton.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#define MULTI_CLICK_WINDOW_MS 280
44

5-
MomentaryButton::MomentaryButton(int8_t pin, int long_press_millis, bool reverse, bool pulldownup) {
5+
MomentaryButton::MomentaryButton(int8_t pin, int long_press_millis, bool reverse, bool pulldownup, bool multiclick) {
66
_pin = pin;
77
_reverse = reverse;
88
_pull = pulldownup;
@@ -13,7 +13,7 @@ MomentaryButton::MomentaryButton(int8_t pin, int long_press_millis, bool reverse
1313
_threshold = 0;
1414
_click_count = 0;
1515
_last_click_time = 0;
16-
_multi_click_window = MULTI_CLICK_WINDOW_MS;
16+
_multi_click_window = multiclick ? MULTI_CLICK_WINDOW_MS : 0;
1717
_pending_click = false;
1818
}
1919

src/helpers/ui/MomentaryButton.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class MomentaryButton {
2323
bool isPressed(int level) const;
2424

2525
public:
26-
MomentaryButton(int8_t pin, int long_press_mills=0, bool reverse=false, bool pulldownup=false);
26+
MomentaryButton(int8_t pin, int long_press_mills=0, bool reverse=false, bool pulldownup=false, bool multiclick=true);
2727
MomentaryButton(int8_t pin, int long_press_mills, int analog_threshold);
2828
void begin();
2929
int check(bool repeat_click=false); // returns one of BUTTON_EVENT_*

variants/wio-tracker-l1/platformio.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ build_flags = ${WioTrackerL1.build_flags}
6363
-D MAX_CONTACTS=350
6464
-D MAX_GROUP_CHANNELS=40
6565
-D DISPLAY_CLASS=SH1106Display
66+
-D UI_HAS_JOYSTICK=1
6667
-D OFFLINE_QUEUE_SIZE=256
6768
-D PIN_BUZZER=12
6869
-D QSPIFLASH=1
@@ -91,6 +92,7 @@ build_flags = ${WioTrackerL1.build_flags}
9192
-D BLE_DEBUG_LOGGING=1
9293
-D OFFLINE_QUEUE_SIZE=256
9394
-D DISPLAY_CLASS=SH1106Display
95+
-D UI_HAS_JOYSTICK=1
9496
-D PIN_BUZZER=12
9597
-D QSPIFLASH=1
9698
; -D MESH_PACKET_LOGGING=1

variants/wio-tracker-l1/target.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ EnvironmentSensorManager sensors = EnvironmentSensorManager();
2121

2222
#ifdef DISPLAY_CLASS
2323
DISPLAY_CLASS display;
24-
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
25-
MomentaryButton joystick_left(JOYSTICK_LEFT, 1000, true);
26-
MomentaryButton joystick_right(JOYSTICK_RIGHT, 1000, true);
24+
MomentaryButton user_btn(PIN_USER_BTN, 1000, true, false, false);
25+
MomentaryButton joystick_left(JOYSTICK_LEFT, 1000, true, false, false);
26+
MomentaryButton joystick_right(JOYSTICK_RIGHT, 1000, true, false, false);
27+
MomentaryButton back_btn(PIN_BACK_BTN, 1000, true, false, false);
2728
#endif
2829

2930
bool radio_init() {

variants/wio-tracker-l1/target.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extern EnvironmentSensorManager sensors;
2727
extern MomentaryButton user_btn;
2828
extern MomentaryButton joystick_left;
2929
extern MomentaryButton joystick_right;
30+
extern MomentaryButton back_btn;
3031
#endif
3132

3233
bool radio_init();

variants/wio-tracker-l1/variant.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@
3131
#define PIN_BUTTON4 (27) // Joystick Left
3232
#define PIN_BUTTON5 (28) // Joystick Right
3333
#define PIN_BUTTON6 (29) // Joystick Press
34-
#define PIN_USER_BTN PIN_BUTTON1
34+
#define PIN_BACK_BTN PIN_BUTTON1
3535
#define JOYSTICK_UP PIN_BUTTON2
3636
#define JOYSTICK_DOWN PIN_BUTTON3
3737
#define JOYSTICK_LEFT PIN_BUTTON4
3838
#define JOYSTICK_RIGHT PIN_BUTTON5
3939
#define JOYSTICK_PRESS PIN_BUTTON6
40+
#define PIN_USER_BTN PIN_BUTTON6
4041

4142
// Buzzer
4243
// #define PIN_BUZZER (12) // Buzzer pin (defined per firmware type)

0 commit comments

Comments
 (0)