Browse Source

Trigger commit in eeprom module

alexa
Max Prokhorov 6 years ago
parent
commit
7c85225764
5 changed files with 44 additions and 15 deletions
  1. +37
    -0
      code/espurna/eeprom.ino
  2. +1
    -1
      code/espurna/mqtt.ino
  3. +2
    -2
      code/espurna/relay.ino
  4. +3
    -11
      code/espurna/settings.ino
  5. +1
    -1
      code/espurna/system.ino

+ 37
- 0
code/espurna/eeprom.ino View File

@ -8,6 +8,11 @@ EEPROM MODULE
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool _eeprom_commit = false;
uint32_t _eeprom_commit_count = 0;
bool _eeprom_last_commit_result = false;
void eepromRotate(bool value) { void eepromRotate(bool value) {
// Enable/disable EEPROM rotation only if we are using more sectors than the // Enable/disable EEPROM rotation only if we are using more sectors than the
// reserved by the memory layout // reserved by the memory layout
@ -34,15 +39,38 @@ String eepromSectors() {
return response; return response;
} }
bool _eepromCommit() {
_eeprom_commit_count++;
_eeprom_last_commit_result = EEPROMr.commit();
return _eeprom_last_commit_result;
}
void eepromCommit() {
_eeprom_commit = true;
}
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT
void _eepromInitCommands() { void _eepromInitCommands() {
settingsRegisterCommand(F("EEPROM"), [](Embedis* e) { settingsRegisterCommand(F("EEPROM"), [](Embedis* e) {
infoMemory("EEPROM", SPI_FLASH_SEC_SIZE, SPI_FLASH_SEC_SIZE - settingsSize()); infoMemory("EEPROM", SPI_FLASH_SEC_SIZE, SPI_FLASH_SEC_SIZE - settingsSize());
if (_eeprom_commit_count > 0) {
DEBUG_MSG_P(PSTR("[MAIN] Commits done: %lu\n"), _eeprom_commit_count);
DEBUG_MSG_P(PSTR("[MAIN] Last result: %s\n"), _eeprom_last_commit_result ? "OK" : "ERROR");
}
DEBUG_MSG_P(PSTR("+OK\n")); DEBUG_MSG_P(PSTR("+OK\n"));
}); });
settingsRegisterCommand(F("EEPROM.COMMIT"), [](Embedis* e) {
const bool res = _eepromCommit();
if (res) {
DEBUG_MSG_P(PSTR("+OK\n"));
} else {
DEBUG_MSG_P(PSTR("-ERROR\n"));
}
});
settingsRegisterCommand(F("EEPROM.DUMP"), [](Embedis* e) { settingsRegisterCommand(F("EEPROM.DUMP"), [](Embedis* e) {
EEPROMr.dump(settingsSerial()); EEPROMr.dump(settingsSerial());
DEBUG_MSG_P(PSTR("\n+OK\n")); DEBUG_MSG_P(PSTR("\n+OK\n"));
@ -69,6 +97,13 @@ void _eepromInitCommands() {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void eepromLoop() {
if (_eeprom_commit) {
_eepromCommit();
_eeprom_commit = false;
}
}
void eepromSetup() { void eepromSetup() {
#ifdef EEPROM_ROTATE_SECTORS #ifdef EEPROM_ROTATE_SECTORS
@ -92,4 +127,6 @@ void eepromSetup() {
_eepromInitCommands(); _eepromInitCommands();
#endif #endif
espurnaRegisterLoop(eepromLoop);
} }

+ 1
- 1
code/espurna/mqtt.ino View File

@ -291,7 +291,7 @@ unsigned long _mqttNextMessageId() {
EEPROMr.write(EEPROM_MESSAGE_ID + 1, (id >> 16) & 0xFF); EEPROMr.write(EEPROM_MESSAGE_ID + 1, (id >> 16) & 0xFF);
EEPROMr.write(EEPROM_MESSAGE_ID + 2, (id >> 8) & 0xFF); EEPROMr.write(EEPROM_MESSAGE_ID + 2, (id >> 8) & 0xFF);
EEPROMr.write(EEPROM_MESSAGE_ID + 3, (id >> 0) & 0xFF); EEPROMr.write(EEPROM_MESSAGE_ID + 3, (id >> 0) & 0xFF);
saveSettings();
eepromCommit();
} }
id++; id++;


+ 2
- 2
code/espurna/relay.ino View File

@ -418,7 +418,7 @@ void relaySave(bool do_commit) {
// We are actually enqueuing the commit so it will be // We are actually enqueuing the commit so it will be
// executed on the main loop, in case this is called from a callback // executed on the main loop, in case this is called from a callback
saveSettings();
eepromCommit();
} }
@ -548,7 +548,7 @@ void _relayBoot() {
// Save if there is any relay in the RELAY_BOOT_TOGGLE mode // Save if there is any relay in the RELAY_BOOT_TOGGLE mode
if (trigger_save) { if (trigger_save) {
EEPROMr.write(EEPROM_RELAY_STATUS, mask); EEPROMr.write(EEPROM_RELAY_STATUS, mask);
saveSettings();
eepromCommit();
} }
_relayRecursive = false; _relayRecursive = false;


+ 3
- 11
code/espurna/settings.ino View File

@ -22,8 +22,6 @@ EmbedisWrap embedis(_serial, TERMINAL_BUFFER_SIZE);
#endif // SERIAL_RX_ENABLED #endif // SERIAL_RX_ENABLED
#endif // TERMINAL_SUPPORT #endif // TERMINAL_SUPPORT
bool _settings_save = false;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Reverse engineering EEPROM storage format // Reverse engineering EEPROM storage format
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -310,7 +308,7 @@ void _settingsInitCommands() {
#if not SETTINGS_AUTOSAVE #if not SETTINGS_AUTOSAVE
settingsRegisterCommand(F("SAVE"), [](Embedis* e) { settingsRegisterCommand(F("SAVE"), [](Embedis* e) {
_settings_save = true;
eepromCommit();
DEBUG_MSG_P(PSTR("\n+OK\n")); DEBUG_MSG_P(PSTR("\n+OK\n"));
}); });
#endif #endif
@ -367,7 +365,7 @@ bool hasSetting(const String& key, unsigned int index) {
void saveSettings() { void saveSettings() {
#if not SETTINGS_AUTOSAVE #if not SETTINGS_AUTOSAVE
_settings_save = true;
eepromCommit();
#endif #endif
} }
@ -464,7 +462,7 @@ void settingsSetup() {
[](size_t pos) -> char { return EEPROMr.read(pos); }, [](size_t pos) -> char { return EEPROMr.read(pos); },
[](size_t pos, char value) { EEPROMr.write(pos, value); }, [](size_t pos, char value) { EEPROMr.write(pos, value); },
#if SETTINGS_AUTOSAVE #if SETTINGS_AUTOSAVE
[]() { _settings_save = true; }
[]() { eepromCommit(); }
#else #else
[]() {} []() {}
#endif #endif
@ -485,12 +483,6 @@ void settingsSetup() {
void settingsLoop() { void settingsLoop() {
if (_settings_save) {
EEPROMr.commit();
_settings_save = false;
}
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT
#if DEBUG_SERIAL_SUPPORT #if DEBUG_SERIAL_SUPPORT


+ 1
- 1
code/espurna/system.ino View File

@ -42,7 +42,7 @@ void systemCheck(bool stable) {
} }
} }
EEPROMr.write(EEPROM_CRASH_COUNTER, value); EEPROMr.write(EEPROM_CRASH_COUNTER, value);
EEPROMr.commit();
eepromCommit();
} }
bool systemCheck() { bool systemCheck() {


Loading…
Cancel
Save