From f3887ec283e93d59a46e4c819a68cc2cf2292430 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 12 May 2018 17:57:47 +0200 Subject: [PATCH] Updated to work with the new plugin API Signed-off-by: Gergely Nagy --- README.md | 5 +-- .../GhostInTheFirmware/GhostInTheFirmware.ino | 30 ++++++++++++------ src/Kaleidoscope/GhostInTheFirmware.cpp | 31 ++++++++++++------- src/Kaleidoscope/GhostInTheFirmware.h | 15 ++++++--- 4 files changed, 54 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index fb1b47dd..58259ea4 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,10 @@ static const kaleidoscope::GhostInTheFirmware::GhostKey ghost_keys[] PROGMEM = { {0, 0, 0} }; -void setup() { - Kaleidoscope.use(&GhostInTheFirmware, &Macros); +KALEIDOSCOPE_INIT_PLUGINS(GhostInTheFirmware, + Macros); +void setup() { Kaleidoscope.setup (); GhostInTheFirmware.ghost_keys = ghost_keys; diff --git a/examples/GhostInTheFirmware/GhostInTheFirmware.ino b/examples/GhostInTheFirmware/GhostInTheFirmware.ino index 809381c3..425085e5 100644 --- a/examples/GhostInTheFirmware/GhostInTheFirmware.ino +++ b/examples/GhostInTheFirmware/GhostInTheFirmware.ino @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-GhostInTheFirmware -- Let the keyboard write for you! - * 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 @@ -21,6 +21,7 @@ #include #include +// *INDENT-OFF* const Key keymaps[][ROWS][COLS] PROGMEM = { [0] = KEYMAP_STACKED (___, ___, ___, ___, ___, ___, M(0), @@ -33,16 +34,24 @@ const Key keymaps[][ROWS][COLS] PROGMEM = { ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, - ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___), }; +// *INDENT-ON* -static Key eventDropper(Key, byte, byte, uint8_t) { - return Key_NoKey; -} +class EventDropper_ : public kaleidoscope::Plugin { + public: + EventDropper_() {} + + kaleidoscope::EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state) { + return kaleidoscope::EventHandlerResult::EVENT_CONSUMED; + } +}; + +static EventDropper_ EventDropper; const macro_t *macroAction(uint8_t macro_index, uint8_t key_state) { if (macro_index == 0 && keyToggledOn(key_state)) @@ -120,15 +129,16 @@ static const kaleidoscope::GhostInTheFirmware::GhostKey ghost_keys[] PROGMEM = { {0, 0, 0, 0} }; +KALEIDOSCOPE_INIT_PLUGINS(GhostInTheFirmware, + StalkerEffect, + Macros, + EventDropper); + void setup() { - Kaleidoscope.use(&GhostInTheFirmware, &StalkerEffect, &Macros); + Kaleidoscope.setup(); StalkerEffect.variant = STALKER(BlazingTrail); GhostInTheFirmware.ghost_keys = ghost_keys; - - Kaleidoscope.useEventHandlerHook(eventDropper); - - Kaleidoscope.setup(); } void loop() { diff --git a/src/Kaleidoscope/GhostInTheFirmware.cpp b/src/Kaleidoscope/GhostInTheFirmware.cpp index a8c196a9..0b343f34 100644 --- a/src/Kaleidoscope/GhostInTheFirmware.cpp +++ b/src/Kaleidoscope/GhostInTheFirmware.cpp @@ -28,20 +28,13 @@ uint32_t GhostInTheFirmware::start_time_; uint16_t GhostInTheFirmware::press_timeout_; uint16_t GhostInTheFirmware::delay_timeout_; -GhostInTheFirmware::GhostInTheFirmware(void) { -} - -void GhostInTheFirmware::begin(void) { - Kaleidoscope.useLoopHook(this->loopHook); -} - void GhostInTheFirmware::activate(void) { is_active_ = true; } -void GhostInTheFirmware::loopHook(bool is_post_clear) { - if (is_post_clear || !is_active_) - return; +EventHandlerResult GhostInTheFirmware::beforeReportingState() { + if (!is_active_) + return EventHandlerResult::OK; if (press_timeout_ == 0) { press_timeout_ = pgm_read_word(&(ghost_keys[current_pos_].pressTime)); @@ -50,7 +43,7 @@ void GhostInTheFirmware::loopHook(bool is_post_clear) { if (press_timeout_ == 0) { current_pos_ = 0; is_active_ = false; - return; + return EventHandlerResult::OK; } is_pressed_ = true; start_time_ = millis(); @@ -73,7 +66,23 @@ void GhostInTheFirmware::loopHook(bool is_post_clear) { press_timeout_ = 0; } } + + return EventHandlerResult::OK; +} + +// Legacy V1 API +#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API +void GhostInTheFirmware::begin() { + Kaleidoscope.useLoopHook(legacyLoopHook); +} + +void GhostInTheFirmware::legacyLoopHook(bool is_post_clear) { + if (is_post_clear) + return; + + ::GhostInTheFirmware.beforeReportingState(); } +#endif }; diff --git a/src/Kaleidoscope/GhostInTheFirmware.h b/src/Kaleidoscope/GhostInTheFirmware.h index 131d0153..2720691e 100644 --- a/src/Kaleidoscope/GhostInTheFirmware.h +++ b/src/Kaleidoscope/GhostInTheFirmware.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-GhostInTheFirmware -- Let the keyboard write for you! - * 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 @@ -21,7 +21,7 @@ #include namespace kaleidoscope { -class GhostInTheFirmware : public KaleidoscopePlugin { +class GhostInTheFirmware : public kaleidoscope::Plugin { public: typedef struct { byte row; @@ -31,11 +31,18 @@ class GhostInTheFirmware : public KaleidoscopePlugin { } GhostKey; static const GhostKey *ghost_keys; - GhostInTheFirmware(void); + GhostInTheFirmware(void) {} - void begin(void) final; static void activate(void); + EventHandlerResult beforeReportingState(); + +#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API + protected: + void begin(); + static void legacyLoopHook(bool is_post_clear); +#endif + private: static bool is_active_; static bool is_pressed_;