Kaleidoscope Style Guide conformance

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 8 years ago
parent 16ecc25dbe
commit 7ddb1130b4

@ -5,9 +5,9 @@
[travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-LED-Stalker.svg?branch=master [travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-LED-Stalker.svg?branch=master
[travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-LED-Stalker [travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-LED-Stalker
[st:stable]: https://img.shields.io/badge/stable-✔-black.png?style=flat&colorA=44cc11&colorB=494e52 [st:stable]: https://img.shields.io/badge/stable-✔-black.svg?style=flat&colorA=44cc11&colorB=494e52
[st:broken]: https://img.shields.io/badge/broken-X-black.png?style=flat&colorA=e05d44&colorB=494e52 [st:broken]: https://img.shields.io/badge/broken-X-black.svg?style=flat&colorA=e05d44&colorB=494e52
[st:experimental]: https://img.shields.io/badge/experimental----black.png?style=flat&colorA=dfb317&colorB=494e52 [st:experimental]: https://img.shields.io/badge/experimental----black.svg?style=flat&colorA=dfb317&colorB=494e52
The `StalkerEffect` plugin provides an interesting new typing experience: the The `StalkerEffect` plugin provides an interesting new typing experience: the
LEDs light up as you tap keys, and play one of the selected effects: a haunting LEDs light up as you tap keys, and play one of the selected effects: a haunting
@ -21,12 +21,13 @@ To use the plugin, one needs to include the header, and select the effect.
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LED-Stalker.h> #include <Kaleidoscope-LED-Stalker.h>
void setup () { void setup (){
Kaleidoscope.setup (); USE_PLUGINS(&StalkerEffect);
StalkerEffect.configure (STALKER (Haunt, {0xff, 0, 0})); Kaleidoscope.setup();
USE_PLUGINS (&StalkerEffect);
StalkerEffect.activate (); StalkerEffect.variant = STALKER(Haunt, (CRGB(0, 128, 0)));
StalkerEffect.activate();
} }
``` ```
@ -40,11 +41,13 @@ recommended.
The plugin provides the `StalkerEffect` object, which has the following The plugin provides the `StalkerEffect` object, which has the following
method: method:
### `.configure(effect)` ### `.variant`
> Set the effect to use with the plugin. See below for a list. > Set the effect to use with the plugin. See below for a list.
> >
> It is recommended to use the `STALKER` macro to declare the effect itself. > It is recommended to use the `STALKER` macro to declare the effect itself.
>
> Not a method itself, but a changeable value.
### `.stepLength` ### `.stepLength`
@ -57,11 +60,11 @@ method:
## Plugin helpers ## Plugin helpers
### `STALKER(effect, params...)` ### `STALKER(effect, params)`
> Returns an effect, to be used by the `.configure` method of the > Returns an effect, to be used to assign a value the `.variant` property of the
> `StalkerEffect` object. Any arguments given to the macro, are also passed on > `StalkerEffect` object. Any arguments given to the macro, are also passed on
> to the effect. If the effect takes no arguments, use `NULL`. > to the effect. If the effect takes no arguments, use an empty `params` list.
## Plugin effects ## Plugin effects

@ -20,7 +20,6 @@
#include <Kaleidoscope-LED-Stalker.h> #include <Kaleidoscope-LED-Stalker.h>
#include "LED-Off.h" #include "LED-Off.h"
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED [0] = KEYMAP_STACKED
( (
@ -38,16 +37,15 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_NoKey Key_NoKey),
),
}; };
void setup() { void setup() {
Kaleidoscope.setup();
StalkerEffect.configure(STALKER(BlazingTrail, NULL));
USE_PLUGINS(&LEDOff, &StalkerEffect); USE_PLUGINS(&LEDOff, &StalkerEffect);
Kaleidoscope.setup();
StalkerEffect.variant = STALKER(BlazingTrail);
StalkerEffect.activate(); StalkerEffect.activate();
} }

@ -19,89 +19,79 @@
#include <Kaleidoscope-LED-Stalker.h> #include <Kaleidoscope-LED-Stalker.h>
#include <LEDUtils.h> #include <LEDUtils.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
namespace LEDEffects {
uint8_t StalkerEffect::map[ROWS][COLS];
StalkerEffect::ColorComputer *StalkerEffect::colorComputer;
uint16_t StalkerEffect::stepLength = 50;
uint32_t StalkerEffect::stepEndTime;
StalkerEffect::StalkerEffect(void) { uint8_t StalkerEffect::map_[ROWS][COLS];
} StalkerEffect::ColorComputer *StalkerEffect::variant;
uint16_t StalkerEffect::step_length = 50;
uint32_t StalkerEffect::step_end_time_;
void StalkerEffect::StalkerEffect(void) {
StalkerEffect::configure(ColorComputer *colorComputer_) {
colorComputer = colorComputer_;
} }
void void StalkerEffect::begin(void) {
StalkerEffect::begin(void) {
event_handler_hook_use(eventHandlerHook); event_handler_hook_use(eventHandlerHook);
LEDMode::begin(); LEDMode::begin();
} }
void void StalkerEffect::init(void) {
StalkerEffect::init(void) { memset(map_, 0, sizeof(map_));
memset(map, 0, sizeof(map));
} }
Key Key StalkerEffect::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
StalkerEffect::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (row >= ROWS || col >= COLS) if (row >= ROWS || col >= COLS)
return mappedKey; return mapped_key;
if (key_is_pressed(keyState)) { if (key_is_pressed(key_state)) {
map[row][col] = 0xff; map_[row][col] = 0xff;
} }
return mappedKey; return mapped_key;
} }
void void StalkerEffect::update(void) {
StalkerEffect::update(void) { if (!variant)
if (!colorComputer)
return; return;
bool timeOut = millis() >= stepEndTime; bool time_out = millis() >= step_end_time_;
for (byte r = 0; r < ROWS; r++) { for (byte r = 0; r < ROWS; r++) {
for (byte c = 0; c < COLS; c++) { for (byte c = 0; c < COLS; c++) {
uint8_t step = map[r][c]; uint8_t step = map_[r][c];
if (step) { if (step) {
LEDControl.led_set_crgb_at(r, c, colorComputer->compute(&step)); LEDControl.led_set_crgb_at(r, c, variant->compute(&step));
} }
bool wasZero = (map[r][c] == 0); bool was_zero = (map_[r][c] == 0);
if (timeOut) { if (time_out) {
map[r][c] = step; map_[r][c] = step;
} }
if (!wasZero && !map[r][c]) if (!was_zero && !map_[r][c])
LEDControl.led_set_crgb_at(r, c, (cRGB) { LEDControl.led_set_crgb_at(r, c, (cRGB) {
0, 0, 0 0, 0, 0
}); });
} }
} }
if (timeOut) if (time_out)
stepEndTime = millis() + stepLength; step_end_time_ = millis() + step_length;
} }
namespace Stalker { namespace stalker {
cRGB Haunt::highlightColor; cRGB Haunt::highlight_color_;
// Haunt // Haunt
Haunt::Haunt(const cRGB highlightColor_) { Haunt::Haunt(const cRGB highlight_color) {
highlightColor = highlightColor_; highlight_color_ = highlight_color;
} }
cRGB cRGB Haunt::compute(uint8_t *step) {
Haunt::compute(uint8_t *step) { cRGB color = CRGB((uint8_t)min(*step * highlight_color_.r / 255, 255),
cRGB color = CRGB((uint8_t)min(*step * highlightColor.r / 255, 255), (uint8_t)min(*step * highlight_color_.g / 255, 255),
(uint8_t)min(*step * highlightColor.g / 255, 255), (uint8_t)min(*step * highlight_color_.b / 255, 255));
(uint8_t)min(*step * highlightColor.b / 255, 255));
if (*step >= 0xf0) if (*step >= 0xf0)
*step -= 1; *step -= 1;
@ -116,11 +106,10 @@ Haunt::compute(uint8_t *step) {
} }
// BlazingTrail // BlazingTrail
BlazingTrail::BlazingTrail(...) { BlazingTrail::BlazingTrail(void) {
} }
cRGB cRGB BlazingTrail::compute(uint8_t *step) {
BlazingTrail::compute(uint8_t *step) {
cRGB color; cRGB color;
if (*step >= 0xff - 30) { if (*step >= 0xff - 30) {
@ -144,9 +133,8 @@ BlazingTrail::compute(uint8_t *step) {
return color; return color;
} }
}; }
}; }
};
KaleidoscopePlugins::LEDEffects::StalkerEffect StalkerEffect; kaleidoscope::StalkerEffect StalkerEffect;

@ -16,13 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
#define STALKER(n, ...) (({static KaleidoscopePlugins::LEDEffects::Stalker::n _effect (__VA_ARGS__); &_effect;})) #define STALKER(v, ...) ({static kaleidoscope::stalker::v _effect __VA_ARGS__; &_effect;})
namespace KaleidoscopePlugins { namespace kaleidoscope {
namespace LEDEffects {
class StalkerEffect : public LEDMode { class StalkerEffect : public LEDMode {
public: public:
class ColorComputer { class ColorComputer {
@ -33,45 +34,39 @@ class StalkerEffect : public LEDMode {
StalkerEffect(void); StalkerEffect(void);
void begin(void) final; void begin(void) final;
virtual void init(void) final; void init(void) final;
virtual void update(void) final; void update(void) final;
static void configure(ColorComputer *colorComputer); static ColorComputer *variant;
static uint16_t stepLength; static uint16_t step_length;
private: private:
static uint32_t stepEndTime; static uint32_t step_end_time_;
static ColorComputer *colorComputer; static uint8_t map_[ROWS][COLS];
static uint8_t map[ROWS][COLS];
static Key eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState); static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
}; };
namespace Stalker { namespace stalker {
class Haunt : public StalkerEffect::ColorComputer { class Haunt : public StalkerEffect::ColorComputer {
public: public:
Haunt(const cRGB highlightColor); explicit Haunt(const cRGB highlight_color);
Haunt(void) : Haunt( { Haunt(void) : Haunt(CRGB(0x40, 0x80, 0x80)) {}
0x40, 0x80, 0x80
}) {};
Haunt(void *) : Haunt() {};
virtual cRGB compute(uint8_t *step) final; cRGB compute(uint8_t *step) final;
private: private:
static cRGB highlightColor; static cRGB highlight_color_;
}; };
class BlazingTrail : public StalkerEffect::ColorComputer { class BlazingTrail : public StalkerEffect::ColorComputer {
public: public:
BlazingTrail(...); BlazingTrail(void);
virtual cRGB compute(uint8_t *step) final;
};
cRGB compute(uint8_t *step) final;
}; };
}; }
}; }
extern KaleidoscopePlugins::LEDEffects::StalkerEffect StalkerEffect; extern kaleidoscope::StalkerEffect StalkerEffect;

Loading…
Cancel
Save