Browse Source

Defer restart until next loop

alexa
Max Prokhorov 5 years ago
parent
commit
004a485e6f
4 changed files with 23 additions and 3 deletions
  1. +5
    -0
      code/espurna/debug.ino
  2. +1
    -0
      code/espurna/settings.ino
  3. +8
    -0
      code/espurna/system.ino
  4. +9
    -3
      code/espurna/utils.ino

+ 5
- 0
code/espurna/debug.ino View File

@ -209,6 +209,11 @@ void debugSetup() {
*/
extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack_start, uint32_t stack_end ) {
// Do not record crash data when resetting the board
if (checkNeedsReset()) {
return;
}
// This method assumes EEPROM has already been initialized
// which is the first thing ESPurna does


+ 1
- 0
code/espurna/settings.ino View File

@ -187,6 +187,7 @@ void _settingsInitCommands() {
settingsRegisterCommand(F("ERASE.CONFIG"), [](Embedis* e) {
DEBUG_MSG_P(PSTR("+OK\n"));
resetReason(CUSTOM_RESET_TERMINAL);
_eepromCommit();
ESP.eraseConfig();
*((int*) 0) = 0; // see https://github.com/esp8266/Arduino/issues/1494
});


+ 8
- 0
code/espurna/system.ino View File

@ -77,6 +77,14 @@ unsigned long systemLoadAverage() {
void systemLoop() {
// -------------------------------------------------------------------------
// User requested reset
// -------------------------------------------------------------------------
if (checkNeedsReset()) {
reset();
}
// -------------------------------------------------------------------------
// Check system stability
// -------------------------------------------------------------------------


+ 9
- 3
code/espurna/utils.ino View File

@ -9,6 +9,8 @@ Copyright (C) 2017-2018 by Xose Pérez <xose dot perez at gmail dot com>
#include <Ticker.h>
Ticker _defer_reset;
uint8_t _reset_reason = 0;
String getIdentifier() {
char buffer[20];
snprintf_P(buffer, sizeof(buffer), PSTR("%s-%06X"), APP_NAME, ESP.getChipId());
@ -463,8 +465,9 @@ unsigned char resetReason() {
}
void resetReason(unsigned char reason) {
_reset_reason = reason;
EEPROMr.write(EEPROM_CUSTOM_RESET, reason);
EEPROMr.commit();
eepromCommit();
}
void reset() {
@ -472,8 +475,11 @@ void reset() {
}
void deferredReset(unsigned long delay, unsigned char reason) {
resetReason(reason);
_defer_reset.once_ms(delay, reset);
_defer_reset.once_ms(delay, resetReason, reason);
}
bool checkNeedsReset() {
return _reset_reason > 0;
}
// -----------------------------------------------------------------------------


Loading…
Cancel
Save