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
pull/365/head
Ben Gemperline 7 years ago
parent 89dea00e10
commit e59eef6246

@ -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 <Kaleidoscope.h>
#include <Kaleidoscope-LEDEffect-BootGreeting.h>
void setup() {
Kaleidoscope.use(&BootGreetingEffect, &LEDOff);
BootGreetingEffect.search_key = Key_M;
Kaleidoscope.setup();
}
```
### Specify by position
```c++
#include <Kaleidoscope.h>
#include <Kaleidoscope-LEDEffect-BootGreeting.h>
void setup() {
Kaleidoscope.use(&BootGreetingEffect, &LEDOff);
//Butterfly key
BootGreetingEffect.key_col = 7;
BootGreetingEffect.key_row = 3;
Kaleidoscope.setup();
}
```
### Specify longer timeout
```c++
#include <Kaleidoscope.h>
#include <Kaleidoscope-LEDEffect-BootGreeting.h>
void setup() {
Kaleidoscope.use(&BootGreetingEffect, &LEDOff);
//Butterfly key
BootGreetingEffect.timeout = 15000;
Kaleidoscope.setup();
}
```
### Specify different color
```c++
#include <Kaleidoscope.h>
#include <Kaleidoscope-LEDEffect-BootGreeting.h>
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

@ -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);
}
}

@ -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;
};
}

Loading…
Cancel
Save