diff --git a/src/Power.cpp b/src/Power.cpp index ae51e803..ba908e3f 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -134,6 +134,14 @@ bool Power::setup() return found; } +void Power::shutdown() +{ +#ifdef TBEAM_V10 + DEBUG_MSG("Shutting down\n"); + axp.shutdown(); +#endif +} + /// Reads power status to powerStatus singleton. // // TODO(girts): move this and other axp stuff to power.h/power.cpp. diff --git a/src/main.cpp b/src/main.cpp index 33b60d84..e0c1dbc1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -168,6 +168,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") { @@ -180,6 +182,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 @@ -191,6 +195,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 } @@ -223,8 +229,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 TBEAM_V10 + if (axp192_found == true) { + power->shutdown(); + } +#endif + } else { + //DEBUG_MSG("Long press %u\n", (millis() - longPressTime)); + } } static void userButtonDoublePressed() @@ -237,6 +254,7 @@ class ButtonThread : public OSThread static Periodic *ledPeriodic; static OSThread *powerFSMthread, *buttonThread; +uint32_t ButtonThread::longPressTime = 0; RadioInterface *rIf = NULL; @@ -246,6 +264,10 @@ void setup() SEGGER_RTT_ConfigUpBuffer(SEGGER_STDOUT_CH, NULL, NULL, 1024, SEGGER_RTT_MODE_NO_BLOCK_TRIM); #endif +#ifdef USE_SEGGER + SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_TRIM); +#endif + // Debug #ifdef DEBUG_PORT DEBUG_PORT.init(); // Set serial baud rate and init our mesh console diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index 0d8fbc00..9a5ec536 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -254,7 +254,7 @@ void RadioLibInterface::handleReceiveInterrupt() } } } - + /** start an immediate transmit */ void RadioLibInterface::startSend(MeshPacket *txp) { diff --git a/src/power.h b/src/power.h index 8b75834a..815e2267 100644 --- a/src/power.h +++ b/src/power.h @@ -23,6 +23,7 @@ class Power : private concurrency::OSThread Power(); + void shutdown(); void readPowerStatus(); virtual bool setup(); virtual int32_t runOnce();