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) {
// Enable/disable EEPROM rotation only if we are using more sectors than the
// reserved by the memory layout
@ -34,15 +39,38 @@ String eepromSectors() {
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
void _eepromInitCommands() {
settingsRegisterCommand(F("EEPROM"), [](Embedis* e) {
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"));
});
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) {
EEPROMr.dump(settingsSerial());
DEBUG_MSG_P(PSTR("\n+OK\n"));
@ -69,6 +97,13 @@ void _eepromInitCommands() {
// -----------------------------------------------------------------------------
void eepromLoop() {
if (_eeprom_commit) {
_eepromCommit();
_eeprom_commit = false;
}
}
void eepromSetup() {
#ifdef EEPROM_ROTATE_SECTORS
@ -92,4 +127,6 @@ void eepromSetup() {
_eepromInitCommands();
#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 + 2, (id >> 8) & 0xFF);
EEPROMr.write(EEPROM_MESSAGE_ID + 3, (id >> 0) & 0xFF);
saveSettings();
eepromCommit();
}
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
// 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
if (trigger_save) {
EEPROMr.write(EEPROM_RELAY_STATUS, mask);
saveSettings();
eepromCommit();
}
_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 // TERMINAL_SUPPORT
bool _settings_save = false;
// -----------------------------------------------------------------------------
// Reverse engineering EEPROM storage format
// -----------------------------------------------------------------------------
@ -310,7 +308,7 @@ void _settingsInitCommands() {
#if not SETTINGS_AUTOSAVE
settingsRegisterCommand(F("SAVE"), [](Embedis* e) {
_settings_save = true;
eepromCommit();
DEBUG_MSG_P(PSTR("\n+OK\n"));
});
#endif
@ -367,7 +365,7 @@ bool hasSetting(const String& key, unsigned int index) {
void saveSettings() {
#if not SETTINGS_AUTOSAVE
_settings_save = true;
eepromCommit();
#endif
}
@ -464,7 +462,7 @@ void settingsSetup() {
[](size_t pos) -> char { return EEPROMr.read(pos); },
[](size_t pos, char value) { EEPROMr.write(pos, value); },
#if SETTINGS_AUTOSAVE
[]() { _settings_save = true; }
[]() { eepromCommit(); }
#else
[]() {}
#endif
@ -485,12 +483,6 @@ void settingsSetup() {
void settingsLoop() {
if (_settings_save) {
EEPROMr.commit();
_settings_save = false;
}
#if TERMINAL_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.commit();
eepromCommit();
}
bool systemCheck() {


Loading…
Cancel
Save