Skip to content

Commit c13b4ae

Browse files
committed
Analogue button delay based on millis
1 parent 7755400 commit c13b4ae

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

examples/companion_radio/ui-new/UITask.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -700,15 +700,18 @@ void UITask::loop() {
700700
}
701701
#endif
702702
#if defined(PIN_USER_BTN_ANA)
703-
ev = analog_btn.check();
704-
if (ev == BUTTON_EVENT_CLICK) {
705-
c = checkDisplayOn(KEY_NEXT);
706-
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
707-
c = handleLongPress(KEY_ENTER);
708-
} else if (ev == BUTTON_EVENT_DOUBLE_CLICK) {
709-
c = handleDoubleClick(KEY_PREV);
710-
} else if (ev == BUTTON_EVENT_TRIPLE_CLICK) {
711-
c = handleTripleClick(KEY_SELECT);
703+
if (abs(millis() - _analogue_pin_read_millis) > 10) {
704+
ev = analog_btn.check();
705+
if (ev == BUTTON_EVENT_CLICK) {
706+
c = checkDisplayOn(KEY_NEXT);
707+
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
708+
c = handleLongPress(KEY_ENTER);
709+
} else if (ev == BUTTON_EVENT_DOUBLE_CLICK) {
710+
c = handleDoubleClick(KEY_PREV);
711+
} else if (ev == BUTTON_EVENT_TRIPLE_CLICK) {
712+
c = handleTripleClick(KEY_SELECT);
713+
}
714+
_analogue_pin_read_millis = millis();
712715
}
713716
#endif
714717
#if defined(DISP_BACKLIGHT) && defined(BACKLIGHT_BTN)

examples/companion_radio/ui-new/UITask.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class UITask : public AbstractUITask {
4040
int last_led_increment = 0;
4141
#endif
4242

43+
#ifdef PIN_USER_BTN_ANA
44+
unsigned long _analogue_pin_read_millis = millis();
45+
#endif
46+
4347
UIScreen* splash;
4448
UIScreen* home;
4549
UIScreen* msg_preview;

0 commit comments

Comments
 (0)