mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-25 17:42:48 +00:00
Add support for the power button #528
This commit is contained in:
parent
3ab9d2a50e
commit
2bd40b7053
@ -134,6 +134,11 @@ bool Power::setup()
|
||||
return found;
|
||||
}
|
||||
|
||||
void Power::shutdown() {
|
||||
DEBUG_MSG("Shutting down\n");
|
||||
axp.shutdown();
|
||||
}
|
||||
|
||||
/// Reads power status to powerStatus singleton.
|
||||
//
|
||||
// TODO(girts): move this and other axp stuff to power.h/power.cpp.
|
||||
|
32
src/main.cpp
32
src/main.cpp
@ -167,6 +167,8 @@ class ButtonThread : public OSThread
|
||||
#endif
|
||||
|
||||
public:
|
||||
static uint32_t longPressTime;
|
||||
|
||||
// callback returns the period for the next callback invocation (or 0 if we should no longer be called)
|
||||
ButtonThread() : OSThread("Button")
|
||||
{
|
||||
@ -179,6 +181,8 @@ class ButtonThread : public OSThread
|
||||
userButton.attachClick(userButtonPressed);
|
||||
userButton.attachDuringLongPress(userButtonPressedLong);
|
||||
userButton.attachDoubleClick(userButtonDoublePressed);
|
||||
userButton.attachLongPressStart(userButtonPressedLongStart);
|
||||
userButton.attachLongPressStop(userButtonPressedLongStop);
|
||||
wakeOnIrq(BUTTON_PIN, FALLING);
|
||||
#endif
|
||||
#ifdef BUTTON_PIN_ALT
|
||||
@ -190,6 +194,8 @@ class ButtonThread : public OSThread
|
||||
userButtonAlt.attachClick(userButtonPressed);
|
||||
userButtonAlt.attachDuringLongPress(userButtonPressedLong);
|
||||
userButtonAlt.attachDoubleClick(userButtonDoublePressed);
|
||||
userButtonAlt.attachLongPressStart(userButtonPressedLongStart);
|
||||
userButtonAlt.attachLongPressStop(userButtonPressedLongStop);
|
||||
wakeOnIrq(BUTTON_PIN_ALT, FALLING);
|
||||
#endif
|
||||
}
|
||||
@ -222,8 +228,19 @@ class ButtonThread : public OSThread
|
||||
}
|
||||
static void userButtonPressedLong()
|
||||
{
|
||||
DEBUG_MSG("Long press!\n");
|
||||
// DEBUG_MSG("Long press!\n");
|
||||
screen->adjustBrightness();
|
||||
|
||||
// If user button is held down for 10 seconds, shutdown the device.
|
||||
if (millis() - longPressTime > 10 * 1000) {
|
||||
#ifdef AXP192_SLAVE_ADDRESS
|
||||
if (axp192_found == true) {
|
||||
power->shutdown();
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
//DEBUG_MSG("Long press %u\n", (millis() - longPressTime));
|
||||
}
|
||||
}
|
||||
|
||||
static void userButtonDoublePressed()
|
||||
@ -232,10 +249,23 @@ class ButtonThread : public OSThread
|
||||
disablePin();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void userButtonPressedLongStart()
|
||||
{
|
||||
DEBUG_MSG("Long press start!\n");
|
||||
longPressTime = millis();
|
||||
}
|
||||
|
||||
static void userButtonPressedLongStop()
|
||||
{
|
||||
DEBUG_MSG("Long press stop!\n");
|
||||
longPressTime = 0;
|
||||
}
|
||||
};
|
||||
|
||||
static Periodic *ledPeriodic;
|
||||
static OSThread *powerFSMthread, *buttonThread;
|
||||
uint32_t ButtonThread::longPressTime = 0;
|
||||
|
||||
RadioInterface *rIf = NULL;
|
||||
|
||||
|
@ -23,6 +23,7 @@ class Power : private concurrency::OSThread
|
||||
|
||||
Power();
|
||||
|
||||
void shutdown();
|
||||
void readPowerStatus();
|
||||
virtual bool setup();
|
||||
virtual int32_t runOnce();
|
||||
|
Loading…
Reference in New Issue
Block a user