Skip to content

Commit b37f61d

Browse files
authored
Merge pull request #416 from jquatier/analog-button
Button handling fix
2 parents 61301da + e6ba025 commit b37f61d

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

examples/companion_radio/UITask.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,33 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
5959
buzzer.begin();
6060
#endif
6161

62-
// Initialize button with appropriate configuration
63-
#if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA)
64-
#ifdef PIN_USER_BTN
65-
_userButton = new Button(PIN_USER_BTN, USER_BTN_PRESSED);
66-
#else
67-
_userButton = new Button(PIN_USER_BTN_ANA, USER_BTN_PRESSED, true, 20);
68-
#endif
69-
62+
// Initialize digital button if available
63+
#ifdef PIN_USER_BTN
64+
_userButton = new Button(PIN_USER_BTN, USER_BTN_PRESSED);
7065
_userButton->begin();
7166

72-
// Set up button callbacks
67+
// Set up digital button callbacks
7368
_userButton->onShortPress([this]() { handleButtonShortPress(); });
7469
_userButton->onDoublePress([this]() { handleButtonDoublePress(); });
7570
_userButton->onTriplePress([this]() { handleButtonTriplePress(); });
7671
_userButton->onQuadruplePress([this]() { handleButtonQuadruplePress(); });
7772
_userButton->onLongPress([this]() { handleButtonLongPress(); });
7873
_userButton->onAnyPress([this]() { handleButtonAnyPress(); });
7974
#endif
75+
76+
// Initialize analog button if available
77+
#ifdef PIN_USER_BTN_ANA
78+
_userButtonAnalog = new Button(PIN_USER_BTN_ANA, USER_BTN_PRESSED, true, 20);
79+
_userButtonAnalog->begin();
80+
81+
// Set up analog button callbacks
82+
_userButtonAnalog->onShortPress([this]() { handleButtonShortPress(); });
83+
_userButtonAnalog->onDoublePress([this]() { handleButtonDoublePress(); });
84+
_userButtonAnalog->onTriplePress([this]() { handleButtonTriplePress(); });
85+
_userButtonAnalog->onQuadruplePress([this]() { handleButtonQuadruplePress(); });
86+
_userButtonAnalog->onLongPress([this]() { handleButtonLongPress(); });
87+
_userButtonAnalog->onAnyPress([this]() { handleButtonAnyPress(); });
88+
#endif
8089
ui_started_at = millis();
8190
}
8291

@@ -291,11 +300,16 @@ void UITask::shutdown(bool restart){
291300
}
292301

293302
void UITask::loop() {
294-
#if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA)
303+
#ifdef PIN_USER_BTN
295304
if (_userButton) {
296305
_userButton->update();
297306
}
298307
#endif
308+
#ifdef PIN_USER_BTN_ANA
309+
if (_userButtonAnalog) {
310+
_userButtonAnalog->update();
311+
}
312+
#endif
299313
userLedHandler();
300314

301315
#ifdef PIN_BUZZER

examples/companion_radio/UITask.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ class UITask {
4242
unsigned long ui_started_at;
4343

4444
// Button handlers
45-
#if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA)
45+
#ifdef PIN_USER_BTN
4646
Button* _userButton = nullptr;
4747
#endif
48+
#ifdef PIN_USER_BTN_ANA
49+
Button* _userButtonAnalog = nullptr;
50+
#endif
4851

4952
void renderCurrScreen();
5053
void userLedHandler();

0 commit comments

Comments
 (0)