Skip to content

Commit

Permalink
changes to allow restart command from API to complete before rebooting
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Oct 11, 2021
1 parent 3113d39 commit cddadcf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> & arguments __attribute__((unused))) {
EMSESP::system_.restart();
EMSESP::system_.system_restart();
});

EMSESPShell::commands->add_command(context,
Expand Down
21 changes: 13 additions & 8 deletions src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -192,7 +193,7 @@ void System::format(uuid::console::Shell & shell) {
LITTLEFS.format();
#endif

System::restart();
System::system_restart();
}

void System::syslog_start() {
Expand Down Expand Up @@ -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

Expand All @@ -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;
Expand All @@ -452,6 +458,7 @@ void System::loop() {
}
*/
#endif

#endif

#endif
Expand Down Expand Up @@ -1028,11 +1035,9 @@ bool System::load_board_profile(std::vector<uint8_t> & 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;
}

Expand Down
11 changes: 10 additions & 1 deletion src/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -84,6 +84,14 @@ class System {
static bool is_valid_gpio(uint8_t pin);
static bool load_board_profile(std::vector<uint8_t> & 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_;
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define EMSESP_APP_VERSION "3.2.2b10"
#define EMSESP_APP_VERSION "3.2.2b11"

0 comments on commit cddadcf

Please sign in to comment.