diff --git a/README.md b/README.md index b3b578d7..2c0c21aa 100644 --- a/README.md +++ b/README.md @@ -18,11 +18,14 @@ To use the plugin, include the header, and tell `Kaleidoscope` to use the plugin ```c++ #include +#include #include -void setup() { - Kaleidoscope.use(&BootGreetingEffect, &LEDOff); +KALEIDOSCOPE_INIT_PLUGINS(LEDControl, + BootGreetingEffect + LEDOff); +void setup() { Kaleidoscope.setup(); } ``` @@ -32,55 +35,69 @@ You may also set optional parameters. ### Specify by search key ```c++ #include +#include #include +KALEIDOSCOPE_INIT_PLUGINS(LEDControl, + BootGreetingEffect + LEDOff); + void setup() { - Kaleidoscope.use(&BootGreetingEffect, &LEDOff); + Kaleidoscope.setup(); BootGreetingEffect.search_key = Key_M; - - Kaleidoscope.setup(); } ``` ### Specify by position ```c++ #include +#include #include +KALEIDOSCOPE_INIT_PLUGINS(LEDControl, + BootGreetingEffect + LEDOff); + void setup() { - Kaleidoscope.use(&BootGreetingEffect, &LEDOff); + Kaleidoscope.setup(); //Butterfly key BootGreetingEffect.key_col = 7; BootGreetingEffect.key_row = 3; - - Kaleidoscope.setup(); } ``` ### Specify longer timeout ```c++ #include +#include #include +KALEIDOSCOPE_INIT_PLUGINS(LEDControl, + BootGreetingEffect + LEDOff); + void setup() { - Kaleidoscope.use(&BootGreetingEffect, &LEDOff); + Kaleidoscope.setup(); //Butterfly key BootGreetingEffect.timeout = 15000; - - Kaleidoscope.setup(); } ``` ### Specify different color ```c++ #include +#include #include +KALEIDOSCOPE_INIT_PLUGINS(LEDControl, + BootGreetingEffect + LEDOff); + void setup() { - Kaleidoscope.use(&BootGreetingEffect, &LEDOff); + Kaleidoscope.setup(); //Butterfly key BootGreetingEffect.hue = 90; @@ -112,7 +129,7 @@ properties: ### `.key_col` > This is an optional override to explicitly set the selected key by exact row -> and column. This number is 0-indexed, so the left-most column is 0, the +> and column. This number is 0-indexed, so the left-most column is 0, the > second column is 1, etc. Must set `.key_row` property for this feature to > be enabled. @@ -128,7 +145,7 @@ properties: > This property sets the color hue that the LED pulsing effect. > -> The default is `170`, which is a blue color. +> The default is `170`, which is a blue color. ## Dependencies diff --git a/src/Kaleidoscope-LEDEffect-BootGreeting.cpp b/src/Kaleidoscope-LEDEffect-BootGreeting.cpp index 1e1f6e3a..348fb944 100644 --- a/src/Kaleidoscope-LEDEffect-BootGreeting.cpp +++ b/src/Kaleidoscope-LEDEffect-BootGreeting.cpp @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-LEDEffect-BootGreeting -- Small greeting at boot time - * 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 @@ -36,11 +36,6 @@ BootGreetingEffect::BootGreetingEffect(byte pos_row, byte pos_col) { key_col = pos_col; } -void BootGreetingEffect::begin(void) { - //Use the loop hook - Kaleidoscope.useLoopHook(loopHook); -} - void BootGreetingEffect::findLed(void) { // Find the LED key. for (uint8_t r = 0; r < ROWS; r++) { @@ -63,10 +58,10 @@ void BootGreetingEffect::findLed(void) { done_ = true; } -void BootGreetingEffect::loopHook(const bool post_clear) { +EventHandlerResult BootGreetingEffect::afterEachCycle() { //If already done or we're not in a ready state, bail - if (!post_clear || done_) { - return; + if (done_) { + return EventHandlerResult::OK; } //If the start time isn't set, set the start time and @@ -75,19 +70,35 @@ void BootGreetingEffect::loopHook(const bool post_clear) { start_time = millis(); findLed(); //the first time, don't do anything. - return; + return EventHandlerResult::OK; } //Only run for 'timeout' milliseconds if ((millis() - start_time) > timeout) { done_ = true; ::LEDControl.refreshAt(row_, col_); - return; + return EventHandlerResult::OK; } cRGB color = breath_compute(hue); ::LEDControl.setCrgbAt(row_, col_, color); + + return EventHandlerResult::OK; } + +// Legacy V1 API +#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API +void BootGreetingEffect::begin() { + Kaleidoscope.useLoopHook(legacyLoopHook); +} + +void BootGreetingEffect::legacyLoopHook(bool is_post_clear) { + if (!is_post_clear) + return; + ::BootGreetingEffect.afterEachCycle(); +} +#endif + } kaleidoscope::BootGreetingEffect BootGreetingEffect; diff --git a/src/Kaleidoscope-LEDEffect-BootGreeting.h b/src/Kaleidoscope-LEDEffect-BootGreeting.h index b252db8d..92e4ace9 100644 --- a/src/Kaleidoscope-LEDEffect-BootGreeting.h +++ b/src/Kaleidoscope-LEDEffect-BootGreeting.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-LEDEffect-BootGreeting -- Small greeting at boot time - * 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,20 +21,26 @@ #include "Kaleidoscope-LEDControl.h" namespace kaleidoscope { -class BootGreetingEffect : public KaleidoscopePlugin { +class BootGreetingEffect : public kaleidoscope::Plugin { public: BootGreetingEffect(void) {} BootGreetingEffect(byte, byte); - void begin(void) final; static byte key_row; static byte key_col; static Key search_key; static uint8_t hue; static uint16_t timeout; + EventHandlerResult afterEachCycle(); + +#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API + protected: + void begin(); + static void legacyLoopHook(bool is_post_clear); +#endif + private: - static void loopHook(const bool post_clear); static void findLed(void); static bool done_; static byte row_;