Skip to content

Commit ee68401

Browse files
committed
fixing button handling to allow both button types simultaneously
1 parent eb58266 commit ee68401

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

examples/companion_radio/UITask.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,31 @@ void UITask::begin(DisplayDriver* display, NodePrefs* node_prefs) {
5858
buzzer.begin();
5959
#endif
6060

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

71-
// Set up button callbacks
66+
// Set up digital button callbacks
7267
_userButton->onShortPress([this]() { handleButtonShortPress(); });
7368
_userButton->onDoublePress([this]() { handleButtonDoublePress(); });
7469
_userButton->onTriplePress([this]() { handleButtonTriplePress(); });
7570
_userButton->onLongPress([this]() { handleButtonLongPress(); });
7671
_userButton->onAnyPress([this]() { handleButtonAnyPress(); });
7772
#endif
73+
74+
// Initialize analog button if available
75+
#ifdef PIN_USER_BTN_ANA
76+
_userButtonAnalog = new Button(PIN_USER_BTN_ANA, USER_BTN_PRESSED, true, 20);
77+
_userButtonAnalog->begin();
78+
79+
// Set up analog button callbacks
80+
_userButtonAnalog->onShortPress([this]() { handleButtonShortPress(); });
81+
_userButtonAnalog->onDoublePress([this]() { handleButtonDoublePress(); });
82+
_userButtonAnalog->onTriplePress([this]() { handleButtonTriplePress(); });
83+
_userButtonAnalog->onLongPress([this]() { handleButtonLongPress(); });
84+
_userButtonAnalog->onAnyPress([this]() { handleButtonAnyPress(); });
85+
#endif
7886
ui_started_at = millis();
7987
}
8088

@@ -289,11 +297,16 @@ void UITask::shutdown(bool restart){
289297
}
290298

291299
void UITask::loop() {
292-
#if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA)
300+
#ifdef PIN_USER_BTN
293301
if (_userButton) {
294302
_userButton->update();
295303
}
296304
#endif
305+
#ifdef PIN_USER_BTN_ANA
306+
if (_userButtonAnalog) {
307+
_userButtonAnalog->update();
308+
}
309+
#endif
297310
userLedHandler();
298311

299312
#ifdef PIN_BUZZER

examples/companion_radio/UITask.h

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

4242
// Button handlers
43-
#if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA)
43+
#ifdef PIN_USER_BTN
4444
Button* _userButton = nullptr;
4545
#endif
46+
#ifdef PIN_USER_BTN_ANA
47+
Button* _userButtonAnalog = nullptr;
48+
#endif
4649

4750
void renderCurrScreen();
4851
void userLedHandler();

0 commit comments

Comments
 (0)