mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Merge pull request #416 from jquatier/analog-button
Button handling fix
This commit is contained in:
commit
b37f61d720
2 changed files with 28 additions and 11 deletions
|
|
@ -59,17 +59,12 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
|
||||||
buzzer.begin();
|
buzzer.begin();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Initialize button with appropriate configuration
|
// Initialize digital button if available
|
||||||
#if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA)
|
#ifdef PIN_USER_BTN
|
||||||
#ifdef PIN_USER_BTN
|
_userButton = new Button(PIN_USER_BTN, USER_BTN_PRESSED);
|
||||||
_userButton = new Button(PIN_USER_BTN, USER_BTN_PRESSED);
|
|
||||||
#else
|
|
||||||
_userButton = new Button(PIN_USER_BTN_ANA, USER_BTN_PRESSED, true, 20);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_userButton->begin();
|
_userButton->begin();
|
||||||
|
|
||||||
// Set up button callbacks
|
// Set up digital button callbacks
|
||||||
_userButton->onShortPress([this]() { handleButtonShortPress(); });
|
_userButton->onShortPress([this]() { handleButtonShortPress(); });
|
||||||
_userButton->onDoublePress([this]() { handleButtonDoublePress(); });
|
_userButton->onDoublePress([this]() { handleButtonDoublePress(); });
|
||||||
_userButton->onTriplePress([this]() { handleButtonTriplePress(); });
|
_userButton->onTriplePress([this]() { handleButtonTriplePress(); });
|
||||||
|
|
@ -77,6 +72,20 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
|
||||||
_userButton->onLongPress([this]() { handleButtonLongPress(); });
|
_userButton->onLongPress([this]() { handleButtonLongPress(); });
|
||||||
_userButton->onAnyPress([this]() { handleButtonAnyPress(); });
|
_userButton->onAnyPress([this]() { handleButtonAnyPress(); });
|
||||||
#endif
|
#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();
|
ui_started_at = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -291,11 +300,16 @@ void UITask::shutdown(bool restart){
|
||||||
}
|
}
|
||||||
|
|
||||||
void UITask::loop() {
|
void UITask::loop() {
|
||||||
#if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA)
|
#ifdef PIN_USER_BTN
|
||||||
if (_userButton) {
|
if (_userButton) {
|
||||||
_userButton->update();
|
_userButton->update();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef PIN_USER_BTN_ANA
|
||||||
|
if (_userButtonAnalog) {
|
||||||
|
_userButtonAnalog->update();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
userLedHandler();
|
userLedHandler();
|
||||||
|
|
||||||
#ifdef PIN_BUZZER
|
#ifdef PIN_BUZZER
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,12 @@ class UITask {
|
||||||
unsigned long ui_started_at;
|
unsigned long ui_started_at;
|
||||||
|
|
||||||
// Button handlers
|
// Button handlers
|
||||||
#if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA)
|
#ifdef PIN_USER_BTN
|
||||||
Button* _userButton = nullptr;
|
Button* _userButton = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef PIN_USER_BTN_ANA
|
||||||
|
Button* _userButtonAnalog = nullptr;
|
||||||
|
#endif
|
||||||
|
|
||||||
void renderCurrScreen();
|
void renderCurrScreen();
|
||||||
void userLedHandler();
|
void userLedHandler();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue