From e59eef624625c3a238361e95a02e3ee7e45ab139 Mon Sep 17 00:00:00 2001 From: Ben Gemperline Date: Sat, 10 Mar 2018 15:25:12 -0700 Subject: [PATCH] Updates to BootGreeting to allow better user customization Allow user to specify custom boot greeting key by Key_* or by specific row and column. Add ability to define custom duration of boot greet breathing effect, and add ability to change color hue of breathing effect. Finally, rework logic that happens when plugin is loaded to allow all user custom settings to be properly read and applied as expected. add hue to the header Updated readme to support new features astyle + change to allow custom settings --- README.md | 103 +++++++++++++++++++- src/Kaleidoscope-LEDEffect-BootGreeting.cpp | 40 +++++++- src/Kaleidoscope-LEDEffect-BootGreeting.h | 8 ++ 3 files changed, 145 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4fd9ccaf..b3b578d7 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,108 @@ void setup() { } ``` -The plugin provides no methods or properties, the above is all it can do. +You may also set optional parameters. + +### Specify by search key +```c++ +#include +#include + +void setup() { + Kaleidoscope.use(&BootGreetingEffect, &LEDOff); + + BootGreetingEffect.search_key = Key_M; + + Kaleidoscope.setup(); +} +``` + +### Specify by position +```c++ +#include +#include + +void setup() { + Kaleidoscope.use(&BootGreetingEffect, &LEDOff); + + //Butterfly key + BootGreetingEffect.key_col = 7; + BootGreetingEffect.key_row = 3; + + Kaleidoscope.setup(); +} +``` + +### Specify longer timeout +```c++ +#include +#include + +void setup() { + Kaleidoscope.use(&BootGreetingEffect, &LEDOff); + + //Butterfly key + BootGreetingEffect.timeout = 15000; + + Kaleidoscope.setup(); +} +``` + +### Specify different color +```c++ +#include +#include + +void setup() { + Kaleidoscope.use(&BootGreetingEffect, &LEDOff); + + //Butterfly key + BootGreetingEffect.hue = 90; + + Kaleidoscope.setup(); +} +``` + +## Plugin methods + +The plugin provides the `BootGreetingEffect` object, with the following methods and +properties: + +### `.search_key` + +> Set the key in the current keymap that should be activated with the pulsing +> LED on startup. The plugin will search from the top left to the bottom right +> of the keyboard, row by row, to find this key. The first matching key will +> be selected. +> +> Defaults to `Key_LEDEffectNext` + +### `.key_row` + +> This is an optional override to explicitly set the selected key by exact row +> and column. This number is 0-indexed, so the top row is 0, the second row is +> 1, etc. Must set `.key_col` property for this feature to be enabled. + +### `.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 +> second column is 1, etc. Must set `.key_row` property for this feature to +> be enabled. + +### `.timeout` + +> This property specifies the timeout (in milliseconds) for the effect to last. +> When the keyboard is first connected, the pulsing LED effect will last for +> this duration before turning off. +> +> Defaults to `9200` ms. + +### `.hue` + +> This property sets the color hue that the LED pulsing effect. +> +> 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 87c3749b..1e1f6e3a 100644 --- a/src/Kaleidoscope-LEDEffect-BootGreeting.cpp +++ b/src/Kaleidoscope-LEDEffect-BootGreeting.cpp @@ -21,19 +21,37 @@ namespace kaleidoscope { -bool BootGreetingEffect::done_; +bool BootGreetingEffect::done_ = false; byte BootGreetingEffect::row_; byte BootGreetingEffect::col_; +byte BootGreetingEffect::key_row = 255; +byte BootGreetingEffect::key_col = 255; +Key BootGreetingEffect::search_key = Key_LEDEffectNext; +uint8_t BootGreetingEffect::hue = 170; +uint16_t BootGreetingEffect::start_time = 0; +uint16_t BootGreetingEffect::timeout = 9200; + +BootGreetingEffect::BootGreetingEffect(byte pos_row, byte pos_col) { + key_row = pos_row; + 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++) { for (uint8_t c = 0; c < COLS; c++) { Key k = Layer.lookupOnActiveLayer(r, c); - if (k == Key_LEDEffectNext) { + if ( + //If key row and col explicitly set, ignore the search key + (k.raw == search_key.raw && key_row == 255 && key_row == 255) + || (key_row != 255 && key_col != 255 && key_row == r && key_col == c) + ) { row_ = r; col_ = c; return; @@ -46,16 +64,28 @@ void BootGreetingEffect::begin(void) { } void BootGreetingEffect::loopHook(const bool post_clear) { - if (!post_clear || done_) + //If already done or we're not in a ready state, bail + if (!post_clear || done_) { return; + } + + //If the start time isn't set, set the start time and + //find the LEDs. + if (start_time == 0) { + start_time = millis(); + findLed(); + //the first time, don't do anything. + return; + } - if (millis() > 9200) { + //Only run for 'timeout' milliseconds + if ((millis() - start_time) > timeout) { done_ = true; ::LEDControl.refreshAt(row_, col_); return; } - cRGB color = breath_compute(); + cRGB color = breath_compute(hue); ::LEDControl.setCrgbAt(row_, col_, color); } } diff --git a/src/Kaleidoscope-LEDEffect-BootGreeting.h b/src/Kaleidoscope-LEDEffect-BootGreeting.h index acd48fdb..b252db8d 100644 --- a/src/Kaleidoscope-LEDEffect-BootGreeting.h +++ b/src/Kaleidoscope-LEDEffect-BootGreeting.h @@ -24,14 +24,22 @@ namespace kaleidoscope { class BootGreetingEffect : public KaleidoscopePlugin { 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; private: static void loopHook(const bool post_clear); + static void findLed(void); static bool done_; static byte row_; static byte col_; + static uint16_t start_time; }; }