mirror of
https://github.com/meshtastic/firmware.git
synced 2025-07-31 02:45:41 +00:00
Unify the shutdown proceedure (#7393)
* Unify the shutdown proceedure * Don't double save nodeDB on shutdown * Re-tool button shutdown to better correspond to tones * Beep then save --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
parent
475cfe4af2
commit
36b94cf823
@ -681,7 +681,14 @@ bool Power::setup()
|
|||||||
|
|
||||||
void Power::shutdown()
|
void Power::shutdown()
|
||||||
{
|
{
|
||||||
LOG_INFO("Shutting Down");
|
|
||||||
|
#if HAS_SCREEN
|
||||||
|
if (screen) {
|
||||||
|
screen->showSimpleBanner("Shutting Down...", 0); // stays on screen
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
playShutdownMelody();
|
||||||
|
nodeDB->saveToDisk();
|
||||||
|
|
||||||
#if defined(ARCH_NRF52) || defined(ARCH_ESP32) || defined(ARCH_RP2040)
|
#if defined(ARCH_NRF52) || defined(ARCH_ESP32) || defined(ARCH_RP2040)
|
||||||
#ifdef PIN_LED1
|
#ifdef PIN_LED1
|
||||||
@ -693,7 +700,11 @@ void Power::shutdown()
|
|||||||
#ifdef PIN_LED3
|
#ifdef PIN_LED3
|
||||||
ledOff(PIN_LED3);
|
ledOff(PIN_LED3);
|
||||||
#endif
|
#endif
|
||||||
doDeepSleep(DELAY_FOREVER, false, false);
|
doDeepSleep(DELAY_FOREVER, false, true);
|
||||||
|
#elif defined(ARCH_PORTDUINO)
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
#else
|
||||||
|
LOG_WARN("FIXME implement shutdown for this platform");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,10 +47,6 @@ int BuzzerFeedbackThread::handleInputEvent(const InputEvent *event)
|
|||||||
playComboTune(); // Ping sent feedback
|
playComboTune(); // Ping sent feedback
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INPUT_BROKER_SHUTDOWN:
|
|
||||||
playShutdownMelody(); // Shutdown feedback
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// For other events, check if it's a printable character
|
// For other events, check if it's a printable character
|
||||||
if (event->kbchar >= 32 && event->kbchar <= 126) {
|
if (event->kbchar >= 32 && event->kbchar <= 126) {
|
||||||
|
@ -815,9 +815,8 @@ void menuHandler::shutdownMenu()
|
|||||||
bannerOptions.optionsCount = 2;
|
bannerOptions.optionsCount = 2;
|
||||||
bannerOptions.bannerCallback = [](int selected) -> void {
|
bannerOptions.bannerCallback = [](int selected) -> void {
|
||||||
if (selected == 1) {
|
if (selected == 1) {
|
||||||
IF_SCREEN(screen->showSimpleBanner("Shutting Down...", 0));
|
InputEvent event = {.inputEvent = (input_broker_event)INPUT_BROKER_SHUTDOWN, .kbchar = 0, .touchX = 0, .touchY = 0};
|
||||||
nodeDB->saveToDisk();
|
inputBroker->injectInputEvent(&event);
|
||||||
power->shutdown();
|
|
||||||
} else {
|
} else {
|
||||||
menuQueue = power_menu;
|
menuQueue = power_menu;
|
||||||
screen->runNow();
|
screen->runNow();
|
||||||
|
@ -53,23 +53,21 @@ bool ButtonThread::initButton(const ButtonConfig &config)
|
|||||||
},
|
},
|
||||||
this);
|
this);
|
||||||
|
|
||||||
if (config.longPress != INPUT_BROKER_NONE) {
|
_longPress = config.longPress;
|
||||||
_longPress = config.longPress;
|
userButton.attachLongPressStart(
|
||||||
userButton.attachLongPressStart(
|
[](void *callerThread) -> void {
|
||||||
[](void *callerThread) -> void {
|
ButtonThread *thread = (ButtonThread *)callerThread;
|
||||||
ButtonThread *thread = (ButtonThread *)callerThread;
|
// if (millis() > 30000) // hold off 30s after boot
|
||||||
// if (millis() > 30000) // hold off 30s after boot
|
thread->btnEvent = BUTTON_EVENT_LONG_PRESSED;
|
||||||
thread->btnEvent = BUTTON_EVENT_LONG_PRESSED;
|
},
|
||||||
},
|
this);
|
||||||
this);
|
userButton.attachLongPressStop(
|
||||||
userButton.attachLongPressStop(
|
[](void *callerThread) -> void {
|
||||||
[](void *callerThread) -> void {
|
ButtonThread *thread = (ButtonThread *)callerThread;
|
||||||
ButtonThread *thread = (ButtonThread *)callerThread;
|
// if (millis() > 30000) // hold off 30s after boot
|
||||||
// if (millis() > 30000) // hold off 30s after boot
|
thread->btnEvent = BUTTON_EVENT_LONG_RELEASED;
|
||||||
thread->btnEvent = BUTTON_EVENT_LONG_RELEASED;
|
},
|
||||||
},
|
this);
|
||||||
this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.doublePress != INPUT_BROKER_NONE) {
|
if (config.doublePress != INPUT_BROKER_NONE) {
|
||||||
_doublePress = config.doublePress;
|
_doublePress = config.doublePress;
|
||||||
@ -202,11 +200,11 @@ int32_t ButtonThread::runOnce()
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (_longPress != INPUT_BROKER_NONE) {
|
||||||
// Forward long press to InputBroker (but NOT as DOWN/SELECT, just forward a "button long press" event)
|
// Forward long press to InputBroker (but NOT as DOWN/SELECT, just forward a "button long press" event)
|
||||||
evt.inputEvent = _longPress;
|
evt.inputEvent = _longPress;
|
||||||
this->notifyObservers(&evt);
|
this->notifyObservers(&evt);
|
||||||
|
}
|
||||||
// Reset combination tracking
|
// Reset combination tracking
|
||||||
waitingForLongPress = false;
|
waitingForLongPress = false;
|
||||||
|
|
||||||
@ -253,7 +251,7 @@ int32_t ButtonThread::runOnce()
|
|||||||
// may wake the board immediatedly.
|
// may wake the board immediatedly.
|
||||||
case BUTTON_EVENT_LONG_RELEASED: {
|
case BUTTON_EVENT_LONG_RELEASED: {
|
||||||
|
|
||||||
LOG_INFO("LONG PRESS RELEASE");
|
LOG_INFO("LONG PRESS RELEASE AFTER %u MILLIS", millis() - buttonPressStartTime);
|
||||||
if (millis() > 30000 && _longLongPress != INPUT_BROKER_NONE &&
|
if (millis() > 30000 && _longLongPress != INPUT_BROKER_NONE &&
|
||||||
(millis() - buttonPressStartTime) >= _longLongPressTime) {
|
(millis() - buttonPressStartTime) >= _longLongPressTime) {
|
||||||
evt.inputEvent = _longLongPress;
|
evt.inputEvent = _longLongPress;
|
||||||
|
@ -18,7 +18,7 @@ struct ButtonConfig {
|
|||||||
uint16_t longPressTime = 500;
|
uint16_t longPressTime = 500;
|
||||||
input_broker_event doublePress = INPUT_BROKER_NONE;
|
input_broker_event doublePress = INPUT_BROKER_NONE;
|
||||||
input_broker_event longLongPress = INPUT_BROKER_NONE;
|
input_broker_event longLongPress = INPUT_BROKER_NONE;
|
||||||
uint16_t longLongPressTime = 5000;
|
uint16_t longLongPressTime = 3900;
|
||||||
input_broker_event triplePress = INPUT_BROKER_NONE;
|
input_broker_event triplePress = INPUT_BROKER_NONE;
|
||||||
input_broker_event shortLong = INPUT_BROKER_NONE;
|
input_broker_event shortLong = INPUT_BROKER_NONE;
|
||||||
bool touchQuirk = false;
|
bool touchQuirk = false;
|
||||||
|
@ -233,14 +233,7 @@ void ExpressLRSFiveWay::sendAdhocPing()
|
|||||||
// Contained as one method for easier remapping of buttons by user
|
// Contained as one method for easier remapping of buttons by user
|
||||||
void ExpressLRSFiveWay::shutdown()
|
void ExpressLRSFiveWay::shutdown()
|
||||||
{
|
{
|
||||||
LOG_INFO("Shutdown from long press");
|
sendKey(INPUT_BROKER_SHUTDOWN);
|
||||||
powerFSM.trigger(EVENT_PRESS);
|
|
||||||
screen->startAlert("Shutting Down...");
|
|
||||||
// Don't set alerting = true. We don't want to auto-dismiss this alert.
|
|
||||||
|
|
||||||
playShutdownMelody(); // In case user adds a buzzer
|
|
||||||
|
|
||||||
shutdownAtMsec = millis() + 3000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpressLRSFiveWay::click()
|
void ExpressLRSFiveWay::click()
|
||||||
|
@ -1042,8 +1042,9 @@ void setup()
|
|||||||
mainDelay.interruptFromISR(&higherWake);
|
mainDelay.interruptFromISR(&higherWake);
|
||||||
};
|
};
|
||||||
userConfigNoScreen.singlePress = INPUT_BROKER_USER_PRESS;
|
userConfigNoScreen.singlePress = INPUT_BROKER_USER_PRESS;
|
||||||
userConfigNoScreen.longPress = INPUT_BROKER_SHUTDOWN;
|
userConfigNoScreen.longPress = INPUT_BROKER_NONE;
|
||||||
userConfigNoScreen.longPressTime = 5000;
|
userConfigNoScreen.longPressTime = 500;
|
||||||
|
userConfigNoScreen.longLongPress = INPUT_BROKER_SHUTDOWN;
|
||||||
userConfigNoScreen.doublePress = INPUT_BROKER_SEND_PING;
|
userConfigNoScreen.doublePress = INPUT_BROKER_SEND_PING;
|
||||||
userConfigNoScreen.triplePress = INPUT_BROKER_GPS_TOGGLE;
|
userConfigNoScreen.triplePress = INPUT_BROKER_GPS_TOGGLE;
|
||||||
UserButtonThread->initButton(userConfigNoScreen);
|
UserButtonThread->initButton(userConfigNoScreen);
|
||||||
|
@ -107,11 +107,7 @@ int SystemCommandsModule::handleInputEvent(const InputEvent *event)
|
|||||||
return true;
|
return true;
|
||||||
// Power control
|
// Power control
|
||||||
case INPUT_BROKER_SHUTDOWN:
|
case INPUT_BROKER_SHUTDOWN:
|
||||||
LOG_ERROR("Shutting Down");
|
shutdownAtMsec = millis();
|
||||||
IF_SCREEN(screen->showSimpleBanner("Shutting Down..."));
|
|
||||||
nodeDB->saveToDisk();
|
|
||||||
shutdownAtMsec = millis() + DEFAULT_SHUTDOWN_SECONDS * 1000;
|
|
||||||
// runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -40,21 +40,8 @@ void powerCommandsCheck()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ARCH_ESP32) || defined(ARCH_NRF52)
|
|
||||||
if (shutdownAtMsec && screen) {
|
|
||||||
screen->showSimpleBanner("Shutting Down...", 0); // stays on screen
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (shutdownAtMsec && millis() > shutdownAtMsec) {
|
if (shutdownAtMsec && millis() > shutdownAtMsec) {
|
||||||
LOG_INFO("Shut down from admin command");
|
shutdownAtMsec = 0;
|
||||||
#if defined(ARCH_NRF52) || defined(ARCH_ESP32) || defined(ARCH_RP2040)
|
|
||||||
playShutdownMelody();
|
|
||||||
power->shutdown();
|
power->shutdown();
|
||||||
#elif defined(ARCH_PORTDUINO)
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
#else
|
|
||||||
LOG_WARN("FIXME implement shutdown for this platform");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user