Automatically pull in EEPROMSettings, and set up defaults

To make it easier to use the plugin, pull in `EEPROMSettings` by default, and
explicitly call its `onSetup` (it is safe to do so), so user sketches don't have
to if they don't use `EEPROMSettings` directly. Also set `Layer.getKey` to
`EEPROMKeymap.getKeyOverride` to provide a sensible default.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/365/head
Gergely Nagy 6 years ago
parent fbdc8bdf35
commit a02cde9c21

@ -37,11 +37,9 @@ We can then update the keymap via [Focus][plugin:focus].
```c++ ```c++
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-EEPROM-Keymap.h> #include <Kaleidoscope-EEPROM-Keymap.h>
#include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-Focus.h> #include <Kaleidoscope-Focus.h>
KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings, KALEIDOSCOPE_INIT_PLUGINS(EEPROMKeymap,
EEPROMKeymap,
Focus); Focus);
void setup() { void setup() {
@ -52,10 +50,7 @@ void setup() {
Focus.addHook(FOCUS_HOOK_KEYMAP); Focus.addHook(FOCUS_HOOK_KEYMAP);
Focus.addHook(FOCUS_HOOK_KEYMAP_TRANSFER); Focus.addHook(FOCUS_HOOK_KEYMAP_TRANSFER);
Layer.getKey = EEPROMKeymap.getKeyOverride;
EEPROMKeymap.max_layers(1); EEPROMKeymap.max_layers(1);
EEPROMSettings.seal();
} }
``` ```

@ -20,7 +20,7 @@
#include <Kaleidoscope-Focus.h> #include <Kaleidoscope-Focus.h>
// *INDENT-OFF* // *INDENT-OFF*
const Key keymaps[][ROWS][COLS] PROGMEM = { KEYMAPS(
[0] = KEYMAP_STACKED [0] = KEYMAP_STACKED
(Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, (Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey,
Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab,
@ -37,10 +37,10 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_skip), Key_skip),
}; )
// *INDENT-ON* // *INDENT-ON*
KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings, EEPROMKeymap, Focus); KALEIDOSCOPE_INIT_PLUGINS(EEPROMKeymap, Focus);
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
@ -53,10 +53,7 @@ void setup() {
Focus.addHook(FOCUS_HOOK_HELP); Focus.addHook(FOCUS_HOOK_HELP);
Focus.addHook(FOCUS_HOOK_VERSION); Focus.addHook(FOCUS_HOOK_VERSION);
Layer.getKey = EEPROMKeymap.getKeyOverride;
EEPROMKeymap.max_layers(1); EEPROMKeymap.max_layers(1);
EEPROMSettings.seal();
} }
void loop() { void loop() {

@ -23,6 +23,13 @@ namespace kaleidoscope {
uint16_t EEPROMKeymap::keymap_base_; uint16_t EEPROMKeymap::keymap_base_;
uint8_t EEPROMKeymap::max_layers_; uint8_t EEPROMKeymap::max_layers_;
EventHandlerResult EEPROMKeymap::onSetup() {
::EEPROMSettings.onSetup();
Layer.getKey = ::EEPROMKeymap.getKeyOverride;
return EventHandlerResult::OK;
}
void EEPROMKeymap::max_layers(uint8_t max) { void EEPROMKeymap::max_layers(uint8_t max) {
max_layers_ = max; max_layers_ = max;
keymap_base_ = ::EEPROMSettings.requestSlice(max_layers_ * ROWS * COLS * 2); keymap_base_ = ::EEPROMSettings.requestSlice(max_layers_ * ROWS * COLS * 2);

@ -25,6 +25,8 @@ class EEPROMKeymap : public kaleidoscope::Plugin {
public: public:
EEPROMKeymap(void) {} EEPROMKeymap(void) {}
EventHandlerResult onSetup();
static void max_layers(uint8_t max); static void max_layers(uint8_t max);
static uint16_t keymap_base(void); static uint16_t keymap_base(void);

Loading…
Cancel
Save