diff --git a/README.md b/README.md index 6bdb6bd3..b48d2c33 100644 --- a/README.md +++ b/README.md @@ -31,11 +31,12 @@ enum { // Place Key_Redial somewhere on the keymap... -void setup() { - Kaleidoscope.use(&Redial); - Redial.key = Key_Redial; +KALEIDOSCOPE_INIT_PLUGINS(Redial); +void setup() { Kaleidoscope.setup(); + + Redial.key = Key_Redial; } ``` diff --git a/examples/Redial/Redial.ino b/examples/Redial/Redial.ino index 7f7b8a56..80690945 100644 --- a/examples/Redial/Redial.ino +++ b/examples/Redial/Redial.ino @@ -53,11 +53,12 @@ const Key keymaps[][ROWS][COLS] PROGMEM = { }; // *INDENT-ON* -void setup() { - Kaleidoscope.use(&Redial); - Redial.key = Key_Redial; +KALEIDOSCOPE_INIT_PLUGINS(Redial); +void setup() { Kaleidoscope.setup(); + + Redial.key = Key_Redial; } void loop() { diff --git a/src/Kaleidoscope/Redial.cpp b/src/Kaleidoscope/Redial.cpp index 1236eea5..322a9859 100644 --- a/src/Kaleidoscope/Redial.cpp +++ b/src/Kaleidoscope/Redial.cpp @@ -23,23 +23,20 @@ namespace kaleidoscope { Key Redial::key; Key Redial::key_to_redial_; -Key Redial::eventHandlerHook_(Key mapped_key, byte row, byte col, uint8_t key_state) { +EventHandlerResult Redial::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state) { if (key == Key_NoKey) - return mapped_key; + return EventHandlerResult::OK; if (mapped_key == key) { - return key_to_redial_; + mapped_key = key_to_redial_; + return EventHandlerResult::OK; } if (keyToggledOn(key_state) && shouldRemember(mapped_key)) { key_to_redial_ = mapped_key; } - return mapped_key; -} - -void Redial::begin(void) { - Kaleidoscope.useEventHandlerHook(eventHandlerHook_); + return EventHandlerResult::OK; } __attribute__((weak)) bool Redial::shouldRemember(Key mapped_key) { @@ -51,6 +48,20 @@ __attribute__((weak)) bool Redial::shouldRemember(Key mapped_key) { return false; } +// Legacy V1 API +#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API +void Redial::begin() { + Kaleidoscope.useEventHandlerHook(legacyEventHandler); +} + +Key Redial::legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state) { + EventHandlerResult r = ::Redial.onKeyswitchEvent(mapped_key, row, col, key_state); + if (r == EventHandlerResult::OK) + return mapped_key; + return Key_NoKey; +} +#endif + } kaleidoscope::Redial Redial; diff --git a/src/Kaleidoscope/Redial.h b/src/Kaleidoscope/Redial.h index d8dfcbf7..8799dd4e 100644 --- a/src/Kaleidoscope/Redial.h +++ b/src/Kaleidoscope/Redial.h @@ -24,18 +24,22 @@ namespace kaleidoscope { class Redial : public KaleidoscopePlugin { public: - Redial(void) {}; - - void begin(void) final; + Redial(void) {} static Key key; static bool shouldRemember(Key mappedKey); + EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state); + +#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API + protected: + void begin(); + static Key legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state); +#endif + private: static Key key_to_redial_; - - static Key eventHandlerHook_(Key mapped_key, byte row, byte col, uint8_t key_state); }; }