From 962d959a7fbad3e3b83ec0ce55ed7d0ad81e203e Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 12 May 2018 18:26:35 +0200 Subject: [PATCH] Updated to use the new plugin APIs Signed-off-by: Gergely Nagy --- README.md | 6 ++-- .../LED-ActiveModColor/LED-ActiveModColor.ino | 8 ++++-- src/Kaleidoscope/LED-ActiveModColor.cpp | 28 +++++++++++++------ src/Kaleidoscope/LED-ActiveModColor.h | 15 ++++++---- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index a0706e5c..58148553 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,13 @@ is also possible to use a custom color instead of the white default. ```c++ #include +#include #include -void setup () { - Kaleidoscope.use(&ActiveModColorEffect); +KALEIDOSCOPE_INIT_PLUGINS(LEDControl, + ActiveModColorEffect); +void setup () { Kaleidoscope.setup (); ActiveModColorEffect.highlight_color = CRGB(0x00, 0xff, 0xff); diff --git a/examples/LED-ActiveModColor/LED-ActiveModColor.ino b/examples/LED-ActiveModColor/LED-ActiveModColor.ino index 7653ad06..2750d363 100644 --- a/examples/LED-ActiveModColor/LED-ActiveModColor.ino +++ b/examples/LED-ActiveModColor/LED-ActiveModColor.ino @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-LED-ActiveModColor -- Light up the LEDs under the active modifiers - * Copyright (C) 2016, 2017 Gergely Nagy + * Copyright (C) 2016, 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 @@ -17,6 +17,7 @@ */ #include +#include #include const Key keymaps[][ROWS][COLS] PROGMEM = { @@ -39,9 +40,10 @@ const Key keymaps[][ROWS][COLS] PROGMEM = { Key_skip), }; -void setup() { - Kaleidoscope.use(&ActiveModColorEffect); +KALEIDOSCOPE_INIT_PLUGINS(LEDControl, + ActiveModColorEffect); +void setup() { Kaleidoscope.setup(); ActiveModColorEffect.highlight_color = CRGB(0x00, 0xff, 0xff); diff --git a/src/Kaleidoscope/LED-ActiveModColor.cpp b/src/Kaleidoscope/LED-ActiveModColor.cpp index a0054fcb..3f9e1f73 100644 --- a/src/Kaleidoscope/LED-ActiveModColor.cpp +++ b/src/Kaleidoscope/LED-ActiveModColor.cpp @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-LED-ActiveModColor -- Light up the LEDs under the active modifiers - * Copyright (C) 2016, 2017 Gergely Nagy + * Copyright (C) 2016, 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 @@ -28,14 +28,7 @@ cRGB ActiveModColorEffect::highlight_color = (cRGB) { cRGB ActiveModColorEffect::sticky_color = CRGB(0xff, 0x00, 0x00); -void ActiveModColorEffect::begin(void) { - Kaleidoscope.useLoopHook(loopHook); -} - -void ActiveModColorEffect::loopHook(bool is_post_clear) { - if (is_post_clear) - return; - +EventHandlerResult ActiveModColorEffect::beforeReportingState() { for (byte r = 0; r < ROWS; r++) { for (byte c = 0; c < COLS; c++) { Key k = Layer.lookupOnActiveLayer(r, c); @@ -64,8 +57,25 @@ void ActiveModColorEffect::loopHook(bool is_post_clear) { } } } + + return EventHandlerResult::OK; +} + +// Legacy API +#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API +void ActiveModColorEffect::begin() { + Kaleidoscope.useLoopHook(legacyLoopHook); } +void ActiveModColorEffect::legacyLoopHook(bool is_post_clear) { + if (is_post_clear) + return; + + ::ActiveModColorEffect.beforeReportingState(); +} +#endif + + } kaleidoscope::ActiveModColorEffect ActiveModColorEffect; diff --git a/src/Kaleidoscope/LED-ActiveModColor.h b/src/Kaleidoscope/LED-ActiveModColor.h index 569dd135..36650646 100644 --- a/src/Kaleidoscope/LED-ActiveModColor.h +++ b/src/Kaleidoscope/LED-ActiveModColor.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-LED-ActiveModColor -- Light up the LEDs under the active modifiers - * Copyright (C) 2016, 2017 Gergely Nagy + * Copyright (C) 2016, 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,17 +22,20 @@ #include namespace kaleidoscope { -class ActiveModColorEffect : public KaleidoscopePlugin { +class ActiveModColorEffect : public kaleidoscope::Plugin { public: ActiveModColorEffect(void) {} - void begin(void) final; - static cRGB highlight_color; static cRGB sticky_color; - private: - static void loopHook(bool is_post_clear); + EventHandlerResult beforeReportingState(); + +#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API + protected: + void begin(); + static void legacyLoopHook(bool is_post_clear); +#endif }; }