From 47efb47506673554cd064daa9e32630f92aa8fae Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Wed, 3 Oct 2018 06:42:08 +0200 Subject: [PATCH] Seal the EEPROM layout automatically If `EEPROMSettings.seal()` wasn't explicitly called, seal the layout in `beforeEachCycle()`. On the flip side, this makes user sketches simpler, because they don't have to seal explicitly. This is done at the cost of an if check each cycle. In the long run, EEPROM layout management will be moving out of this plugin, so this check will be eventually dropped too. Signed-off-by: Gergely Nagy --- README.md | 3 +++ src/Kaleidoscope/EEPROM-Settings.cpp | 7 +++++++ src/Kaleidoscope/EEPROM-Settings.h | 1 + 3 files changed, 11 insertions(+) diff --git a/README.md b/README.md index d2365de2..d6e86c33 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,9 @@ The plugin provides the `EEPROMSettings` object, which has the following methods > Seal the `EEPROM` layout, so no new slices can be requested. The CRC checksum > is considered final at this time, and the `isValid()`, `crc()`, `used()` and > `version()` methods can be used from this point onwards. +> +> If not called explicitly, the layout will be sealed automatically after +> `setup()` in the sketch finished. ### `update()` diff --git a/src/Kaleidoscope/EEPROM-Settings.cpp b/src/Kaleidoscope/EEPROM-Settings.cpp index 657fa89c..4e4fb247 100644 --- a/src/Kaleidoscope/EEPROM-Settings.cpp +++ b/src/Kaleidoscope/EEPROM-Settings.cpp @@ -30,6 +30,13 @@ EventHandlerResult EEPROMSettings::onSetup() { return EventHandlerResult::OK; } +EventHandlerResult EEPROMSettings::beforeEachCycle() { + if (!sealed_) + seal(); + + return EventHandlerResult::OK; +} + bool EEPROMSettings::isValid(void) { return is_valid_; } diff --git a/src/Kaleidoscope/EEPROM-Settings.h b/src/Kaleidoscope/EEPROM-Settings.h index 3fccd2ba..33cb0214 100644 --- a/src/Kaleidoscope/EEPROM-Settings.h +++ b/src/Kaleidoscope/EEPROM-Settings.h @@ -26,6 +26,7 @@ class EEPROMSettings : public kaleidoscope::Plugin { EEPROMSettings(void) {} EventHandlerResult onSetup(); + EventHandlerResult beforeEachCycle(); static void update(void); static bool isValid(void);