Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions examples/companion_radio/UITask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,33 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
buzzer.begin();
#endif

// Initialize button with appropriate configuration
#if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA)
#ifdef PIN_USER_BTN
_userButton = new Button(PIN_USER_BTN, USER_BTN_PRESSED);
#else
_userButton = new Button(PIN_USER_BTN_ANA, USER_BTN_PRESSED, true, 20);
#endif

// Initialize digital button if available
#ifdef PIN_USER_BTN
_userButton = new Button(PIN_USER_BTN, USER_BTN_PRESSED);
_userButton->begin();

// Set up button callbacks
// Set up digital button callbacks
_userButton->onShortPress([this]() { handleButtonShortPress(); });
_userButton->onDoublePress([this]() { handleButtonDoublePress(); });
_userButton->onTriplePress([this]() { handleButtonTriplePress(); });
_userButton->onQuadruplePress([this]() { handleButtonQuadruplePress(); });
_userButton->onLongPress([this]() { handleButtonLongPress(); });
_userButton->onAnyPress([this]() { handleButtonAnyPress(); });
#endif

// Initialize analog button if available
#ifdef PIN_USER_BTN_ANA
_userButtonAnalog = new Button(PIN_USER_BTN_ANA, USER_BTN_PRESSED, true, 20);
_userButtonAnalog->begin();

// Set up analog button callbacks
_userButtonAnalog->onShortPress([this]() { handleButtonShortPress(); });
_userButtonAnalog->onDoublePress([this]() { handleButtonDoublePress(); });
_userButtonAnalog->onTriplePress([this]() { handleButtonTriplePress(); });
_userButtonAnalog->onQuadruplePress([this]() { handleButtonQuadruplePress(); });
_userButtonAnalog->onLongPress([this]() { handleButtonLongPress(); });
_userButtonAnalog->onAnyPress([this]() { handleButtonAnyPress(); });
#endif
ui_started_at = millis();
}

Expand Down Expand Up @@ -291,11 +300,16 @@ void UITask::shutdown(bool restart){
}

void UITask::loop() {
#if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA)
#ifdef PIN_USER_BTN
if (_userButton) {
_userButton->update();
}
#endif
#ifdef PIN_USER_BTN_ANA
if (_userButtonAnalog) {
_userButtonAnalog->update();
}
#endif
userLedHandler();

#ifdef PIN_BUZZER
Expand Down
5 changes: 4 additions & 1 deletion examples/companion_radio/UITask.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ class UITask {
unsigned long ui_started_at;

// Button handlers
#if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA)
#ifdef PIN_USER_BTN
Button* _userButton = nullptr;
#endif
#ifdef PIN_USER_BTN_ANA
Button* _userButtonAnalog = nullptr;
#endif

void renderCurrScreen();
void userLedHandler();
Expand Down