From cddadcfae2d4f4a33fb061a7e3a0baf8ccd7ed08 Mon Sep 17 00:00:00 2001 From: Proddy Date: Mon, 11 Oct 2021 16:42:36 +0200 Subject: [PATCH] changes to allow restart command from API to complete before rebooting --- src/console.cpp | 2 +- src/system.cpp | 21 +++++++++++++-------- src/system.h | 11 ++++++++++- src/version.h | 2 +- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/console.cpp b/src/console.cpp index 2825a74b5..71be1fc13 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -597,7 +597,7 @@ void Console::load_system_commands(unsigned int context) { CommandFlags::ADMIN, flash_string_vector{F_(restart)}, [](Shell & shell __attribute__((unused)), const std::vector & arguments __attribute__((unused))) { - EMSESP::system_.restart(); + EMSESP::system_.system_restart(); }); EMSESPShell::commands->add_command(context, diff --git a/src/system.cpp b/src/system.cpp index 24d217324..437c9a99c 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -34,6 +34,7 @@ uuid::syslog::SyslogService System::syslog_; // init statics uint32_t System::heap_start_ = 1; // avoid using 0 to divide-by-zero later PButton System::myPButton_; +bool System::restart_requested_ = false; // send on/off to a gpio pin // value: true = HIGH, false = LOW @@ -160,8 +161,8 @@ bool System::command_watch(const char * value, const int8_t id) { } // restart EMS-ESP -void System::restart() { - LOG_INFO(F("Restarting system...")); +void System::system_restart() { + LOG_INFO(F("Restarting EMS-ESP...")); Shell::loop_all(); delay(1000); // wait a second #ifndef EMSESP_STANDALONE @@ -192,7 +193,7 @@ void System::format(uuid::console::Shell & shell) { LITTLEFS.format(); #endif - System::restart(); + System::system_restart(); } void System::syslog_start() { @@ -422,6 +423,11 @@ void System::upload_status(bool in_progress) { // checks system health and handles LED flashing wizardry void System::loop() { + // check if we're supposed to do a reset/restart + if (restart_requested()) { + this->system_restart(); + } + #ifndef EMSESP_STANDALONE myPButton_.check(); // check button press @@ -441,8 +447,8 @@ void System::loop() { last_heartbeat_ = currentMillis; send_heartbeat(); } - #ifndef EMSESP_STANDALONE + #if defined(EMSESP_DEBUG) /* static uint32_t last_memcheck_ = 0; @@ -452,6 +458,7 @@ void System::loop() { } */ #endif + #endif #endif @@ -1028,11 +1035,9 @@ bool System::load_board_profile(std::vector & data, const std::string & return true; } -// restart command - perform a hard reset +// restart command - perform a hard reset by setting flag bool System::command_restart(const char * value, const int8_t id) { -#ifndef EMSESP_STANDALONE - ESP.restart(); -#endif + restart_requested(true); return true; } diff --git a/src/system.h b/src/system.h index 352893a13..16bd35aa2 100644 --- a/src/system.h +++ b/src/system.h @@ -63,7 +63,7 @@ class System { static bool command_settings(const char * value, const int8_t id, JsonObject & json); static bool command_commands(const char * value, const int8_t id, JsonObject & json); - void restart(); + void system_restart(); void format(uuid::console::Shell & shell); void upload_status(bool in_progress); bool upload_status(); @@ -84,6 +84,14 @@ class System { static bool is_valid_gpio(uint8_t pin); static bool load_board_profile(std::vector & data, const std::string & board_profile); + static void restart_requested(bool restart_requested) { + restart_requested_ = restart_requested; + } + + static bool restart_requested() { + return restart_requested_; + } + bool analog_enabled() { return analog_enabled_; } @@ -122,6 +130,7 @@ class System { private: static uuid::log::Logger logger_; static uint32_t heap_start_; + static bool restart_requested_; // button static PButton myPButton_; // PButton instance diff --git a/src/version.h b/src/version.h index cebdcb7ec..a726d7b37 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define EMSESP_APP_VERSION "3.2.2b10" +#define EMSESP_APP_VERSION "3.2.2b11"