Updated to use the new plugin APIs

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/365/head
Gergely Nagy 7 years ago
parent dd9c3fa770
commit be659b4043

@ -18,11 +18,14 @@ To use the plugin, include the header, and tell `Kaleidoscope` to use the plugin
```c++ ```c++
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LEDEffect-BootGreeting.h> #include <Kaleidoscope-LEDEffect-BootGreeting.h>
void setup() { KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
Kaleidoscope.use(&BootGreetingEffect, &LEDOff); BootGreetingEffect
LEDOff);
void setup() {
Kaleidoscope.setup(); Kaleidoscope.setup();
} }
``` ```
@ -32,55 +35,69 @@ You may also set optional parameters.
### Specify by search key ### Specify by search key
```c++ ```c++
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LEDEffect-BootGreeting.h> #include <Kaleidoscope-LEDEffect-BootGreeting.h>
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
BootGreetingEffect
LEDOff);
void setup() { void setup() {
Kaleidoscope.use(&BootGreetingEffect, &LEDOff); Kaleidoscope.setup();
BootGreetingEffect.search_key = Key_M; BootGreetingEffect.search_key = Key_M;
Kaleidoscope.setup();
} }
``` ```
### Specify by position ### Specify by position
```c++ ```c++
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LEDEffect-BootGreeting.h> #include <Kaleidoscope-LEDEffect-BootGreeting.h>
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
BootGreetingEffect
LEDOff);
void setup() { void setup() {
Kaleidoscope.use(&BootGreetingEffect, &LEDOff); Kaleidoscope.setup();
//Butterfly key //Butterfly key
BootGreetingEffect.key_col = 7; BootGreetingEffect.key_col = 7;
BootGreetingEffect.key_row = 3; BootGreetingEffect.key_row = 3;
Kaleidoscope.setup();
} }
``` ```
### Specify longer timeout ### Specify longer timeout
```c++ ```c++
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LEDEffect-BootGreeting.h> #include <Kaleidoscope-LEDEffect-BootGreeting.h>
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
BootGreetingEffect
LEDOff);
void setup() { void setup() {
Kaleidoscope.use(&BootGreetingEffect, &LEDOff); Kaleidoscope.setup();
//Butterfly key //Butterfly key
BootGreetingEffect.timeout = 15000; BootGreetingEffect.timeout = 15000;
Kaleidoscope.setup();
} }
``` ```
### Specify different color ### Specify different color
```c++ ```c++
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LEDEffect-BootGreeting.h> #include <Kaleidoscope-LEDEffect-BootGreeting.h>
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
BootGreetingEffect
LEDOff);
void setup() { void setup() {
Kaleidoscope.use(&BootGreetingEffect, &LEDOff); Kaleidoscope.setup();
//Butterfly key //Butterfly key
BootGreetingEffect.hue = 90; BootGreetingEffect.hue = 90;
@ -112,7 +129,7 @@ properties:
### `.key_col` ### `.key_col`
> This is an optional override to explicitly set the selected key by exact row > 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 > second column is 1, etc. Must set `.key_row` property for this feature to
> be enabled. > be enabled.
@ -128,7 +145,7 @@ properties:
> This property sets the color hue that the LED pulsing effect. > 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 ## Dependencies

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-LEDEffect-BootGreeting -- Small greeting at boot time * 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 * 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 * 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; key_col = pos_col;
} }
void BootGreetingEffect::begin(void) {
//Use the loop hook
Kaleidoscope.useLoopHook(loopHook);
}
void BootGreetingEffect::findLed(void) { void BootGreetingEffect::findLed(void) {
// Find the LED key. // Find the LED key.
for (uint8_t r = 0; r < ROWS; r++) { for (uint8_t r = 0; r < ROWS; r++) {
@ -63,10 +58,10 @@ void BootGreetingEffect::findLed(void) {
done_ = true; 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 already done or we're not in a ready state, bail
if (!post_clear || done_) { if (done_) {
return; return EventHandlerResult::OK;
} }
//If the start time isn't set, set the start time and //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(); start_time = millis();
findLed(); findLed();
//the first time, don't do anything. //the first time, don't do anything.
return; return EventHandlerResult::OK;
} }
//Only run for 'timeout' milliseconds //Only run for 'timeout' milliseconds
if ((millis() - start_time) > timeout) { if ((millis() - start_time) > timeout) {
done_ = true; done_ = true;
::LEDControl.refreshAt(row_, col_); ::LEDControl.refreshAt(row_, col_);
return; return EventHandlerResult::OK;
} }
cRGB color = breath_compute(hue); cRGB color = breath_compute(hue);
::LEDControl.setCrgbAt(row_, col_, color); ::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; kaleidoscope::BootGreetingEffect BootGreetingEffect;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-LEDEffect-BootGreeting -- Small greeting at boot time * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -21,20 +21,26 @@
#include "Kaleidoscope-LEDControl.h" #include "Kaleidoscope-LEDControl.h"
namespace kaleidoscope { namespace kaleidoscope {
class BootGreetingEffect : public KaleidoscopePlugin { class BootGreetingEffect : public kaleidoscope::Plugin {
public: public:
BootGreetingEffect(void) {} BootGreetingEffect(void) {}
BootGreetingEffect(byte, byte); BootGreetingEffect(byte, byte);
void begin(void) final;
static byte key_row; static byte key_row;
static byte key_col; static byte key_col;
static Key search_key; static Key search_key;
static uint8_t hue; static uint8_t hue;
static uint16_t timeout; static uint16_t timeout;
EventHandlerResult afterEachCycle();
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
protected:
void begin();
static void legacyLoopHook(bool is_post_clear);
#endif
private: private:
static void loopHook(const bool post_clear);
static void findLed(void); static void findLed(void);
static bool done_; static bool done_;
static byte row_; static byte row_;

Loading…
Cancel
Save