From 94b7d139901b2602c9a1911bdb09885cd4bcbb9c Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 12 May 2018 17:47:13 +0200 Subject: [PATCH] Updated to use the new plugin APIs Signed-off-by: Gergely Nagy --- README.md | 6 ++---- examples/EEPROM-Settings/EEPROM-Settings.ino | 10 ++++++---- src/Kaleidoscope/EEPROM-Settings.cpp | 18 +++++++++++++----- src/Kaleidoscope/EEPROM-Settings.h | 13 +++++++++---- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index cff535be..d2365de2 100644 --- a/README.md +++ b/README.md @@ -36,11 +36,9 @@ static struct { bool someSettingFlag; } testSettings; -void setup () { - Kaleidoscope.use(&EEPROMSettings); - - /* Use other plugins that make use of the EEPROM */ +KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings, /* Other plugins that use EEPROM... */); +void setup () { Kaleidoscope.setup(); settingsBase = EEPROMSettings.requestSlice(sizeof(testSettings)); diff --git a/examples/EEPROM-Settings/EEPROM-Settings.ino b/examples/EEPROM-Settings/EEPROM-Settings.ino index 9c8db0b0..d01f8132 100644 --- a/examples/EEPROM-Settings/EEPROM-Settings.ino +++ b/examples/EEPROM-Settings/EEPROM-Settings.ino @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-EEPROM-Settings -- Basic EEPROM settings plugin for Kaleidoscope. - * Copyright (C) 2017 Gergely Nagy + * Copyright (C) 2017, 2018 Gergely Nagy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,6 +19,7 @@ #include #include +// *INDENT-OFF* const Key keymaps[][ROWS][COLS] PROGMEM = { [0] = KEYMAP_STACKED (Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, @@ -31,20 +32,21 @@ const Key keymaps[][ROWS][COLS] PROGMEM = { Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip, Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, - Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, + Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, Key_skip), }; +// *INDENT-ON* + +KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings); void setup() { Serial.begin(9600); Kaleidoscope.setup(); - Kaleidoscope.use(&EEPROMSettings); - while (!Serial) { } diff --git a/src/Kaleidoscope/EEPROM-Settings.cpp b/src/Kaleidoscope/EEPROM-Settings.cpp index 9037c701..83f4e11f 100644 --- a/src/Kaleidoscope/EEPROM-Settings.cpp +++ b/src/Kaleidoscope/EEPROM-Settings.cpp @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-EEPROM-Settings -- Basic EEPROM settings plugin for Kaleidoscope. - * Copyright (C) 2017 Gergely Nagy + * Copyright (C) 2017, 2018 Gergely Nagy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,11 +26,9 @@ bool EEPROMSettings::is_valid_; bool EEPROMSettings::sealed_; uint16_t EEPROMSettings::next_start_ = sizeof(EEPROMSettings::settings); -EEPROMSettings::EEPROMSettings(void) { -} - -void EEPROMSettings::begin(void) { +EventHandlerResult EEPROMSettings::onSetup() { EEPROM.get(0, settings_); + return EventHandlerResult::OK; } bool EEPROMSettings::isValid(void) { @@ -65,6 +63,9 @@ uint16_t EEPROMSettings::requestSlice(uint16_t size) { if (sealed_) return 0; + Serial.print("requestSlice; size="); + Serial.println(size); + uint16_t start = next_start_; next_start_ += size; @@ -97,6 +98,13 @@ void EEPROMSettings::version(uint8_t ver) { update(); } +// Legacy V1 API +#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API +void EEPROMSettings::begin() { + ::EEPROMSettings.onSetup(); +} +#endif + } kaleidoscope::EEPROMSettings EEPROMSettings; diff --git a/src/Kaleidoscope/EEPROM-Settings.h b/src/Kaleidoscope/EEPROM-Settings.h index b58f6536..1b8e483c 100644 --- a/src/Kaleidoscope/EEPROM-Settings.h +++ b/src/Kaleidoscope/EEPROM-Settings.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-EEPROM-Settings -- Basic EEPROM settings plugin for Kaleidoscope. - * Copyright (C) 2017 Gergely Nagy + * Copyright (C) 2017, 2018 Gergely Nagy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,11 +22,11 @@ #include namespace kaleidoscope { -class EEPROMSettings : public KaleidoscopePlugin { +class EEPROMSettings : public kaleidoscope::Plugin { public: - EEPROMSettings(void); + EEPROMSettings(void) {} - void begin(void) final; + EventHandlerResult onSetup(); static void update(void); static bool isValid(void); @@ -39,6 +39,11 @@ class EEPROMSettings : public KaleidoscopePlugin { static uint16_t crc(void); static uint16_t used(void); +#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API + protected: + void begin(); +#endif + private: static uint16_t next_start_; static bool is_valid_;