From 115e439a4cb0e3b4775daf08fdfb5cb328341ebf Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 13 May 2018 10:29:00 +0200 Subject: [PATCH] Updated to use the new plugin APIs Signed-off-by: Gergely Nagy --- src/Kaleidoscope-NumPad.cpp | 30 ++++++++++++++++++++++-------- src/Kaleidoscope-NumPad.h | 15 ++++++++++----- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/Kaleidoscope-NumPad.cpp b/src/Kaleidoscope-NumPad.cpp index 84b9eba2..0057d08c 100644 --- a/src/Kaleidoscope-NumPad.cpp +++ b/src/Kaleidoscope-NumPad.cpp @@ -9,9 +9,9 @@ bool NumPad_::cleanupDone = true; bool NumPad_::originalNumLockState = false; cRGB numpad_color = CRGB(255, 0, 0); -void NumPad_::begin(void) { - Kaleidoscope.useLoopHook(loopHook); +kaleidoscope::EventHandlerResult NumPad_::onSetup(void) { originalNumLockState = !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK); + return kaleidoscope::EventHandlerResult::OK; } static void syncNumlock(bool state) { @@ -21,10 +21,7 @@ static void syncNumlock(bool state) { } } -void NumPad_::loopHook(bool postClear) { - if (!postClear) - return; - +kaleidoscope::EventHandlerResult NumPad_::afterEachCycle() { if (!Layer.isOn(numPadLayer)) { bool numState = !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK); if (!cleanupDone) { @@ -38,7 +35,8 @@ void NumPad_::loopHook(bool postClear) { } } originalNumLockState = numState; - return; + + return kaleidoscope::EventHandlerResult::OK; } cleanupDone = false; @@ -65,10 +63,26 @@ void NumPad_::loopHook(bool postClear) { } if (row > ROWS || col > COLS) - return; + return kaleidoscope::EventHandlerResult::OK; cRGB color = breath_compute(); LEDControl.setCrgbAt(row, col, color); + + return kaleidoscope::EventHandlerResult::OK; +} + +// Legacy V1 API +#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API +void NumPad_::begin() { + onSetup(); + Kaleidoscope.useLoopHook(legacyLoopHook); +} + +void NumPad_::legacyLoopHook(bool is_post_clear) { + if (!is_post_clear) + return; + NumPad.afterEachCycle(); } +#endif NumPad_ NumPad; diff --git a/src/Kaleidoscope-NumPad.h b/src/Kaleidoscope-NumPad.h index 1f3c9010..6371c534 100644 --- a/src/Kaleidoscope-NumPad.h +++ b/src/Kaleidoscope-NumPad.h @@ -4,17 +4,22 @@ #include "Kaleidoscope-Macros.h" #include "LEDUtils.h" -class NumPad_ : public KaleidoscopePlugin { +class NumPad_ : public kaleidoscope::Plugin { public: NumPad_(void) {} - void begin(void) final; - static uint8_t numPadLayer; - private: - static void loopHook(const bool postClear); + kaleidoscope::EventHandlerResult onSetup(void); + kaleidoscope::EventHandlerResult afterEachCycle(); +#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API + protected: + void begin(); + static void legacyLoopHook(bool is_post_clear); +#endif + + private: static byte row, col; static bool cleanupDone; static bool originalNumLockState;