EEPROM-Settings: Implement an `eeprom.erase` command (#1137)

The `eeprom.erase` command makes it easier to erase the whole of EEPROM, and in
addition, it will reboot the keyboard so that the changes are picked up by every
single plugin.

Fixes #1134.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/1094/merge
Gergely Nagy 3 years ago committed by GitHub
parent c4fcb7fc21
commit 9f69e430ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -172,6 +172,11 @@ following commands:
> Returns the amount of free bytes in `EEPROM`.
### `eeprom.erase`
> Erases the entire `EEPROM`, and reboots the keyboard to make sure the erase is
> picked up by every single plugin.
## Dependencies
* (Kaleidoscope-FocusSerial)[Kaleidoscope-FocusSerial.md]

@ -208,15 +208,18 @@ EventHandlerResult FocusEEPROMCommand::onFocusEvent(const char *command) {
enum {
CONTENTS,
FREE,
ERASE,
} sub_command;
if (::Focus.handleHelp(command, PSTR("eeprom.contents\neeprom.free")))
if (::Focus.handleHelp(command, PSTR("eeprom.contents\neeprom.free\neeprom.erase")))
return EventHandlerResult::OK;
if (strcmp_P(command, PSTR("eeprom.contents")) == 0)
sub_command = CONTENTS;
else if (strcmp_P(command, PSTR("eeprom.free")) == 0)
sub_command = FREE;
else if (strcmp_P(command, PSTR("eeprom.erase")) == 0)
sub_command = ERASE;
else
return EventHandlerResult::OK;
@ -241,8 +244,15 @@ EventHandlerResult FocusEEPROMCommand::onFocusEvent(const char *command) {
case FREE:
::Focus.send(Runtime.storage().length() - ::EEPROMSettings.used());
break;
case ERASE: {
for (uint16_t i = 0; i < Runtime.storage().length(); i++) {
Runtime.storage().update(i, 255);
}
Runtime.storage().commit();
Runtime.device().rebootBootloader();
break;
}
}
return EventHandlerResult::EVENT_CONSUMED;
}

Loading…
Cancel
Save