Merge remote-tracking branch 'plugin/LED-Stalker/f/monorepo' into f/monorepo

pull/365/head
Gergely Nagy 6 years ago
commit a99f00cb89
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -0,0 +1,84 @@
# Kaleidoscope-LED-Stalker
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
trail of ghostly white lights, or a blazing trail of fire.
## Using the plugin
To use the plugin, one needs to include the header and select the effect.
```c++
#include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LED-Stalker.h>
KALEIDOSCOPE_INIT_PLUGINS(LEDControl, StalkerEffect);
void setup (){
Kaleidoscope.setup();
StalkerEffect.variant = STALKER(Haunt, (CRGB(0, 128, 0)));
StalkerEffect.activate();
}
```
It is recommended to place the activation of the plugin (the `Kaleidoscope.use`
call) as early as possible, so the plugin can catch all relevant key presses.
The configuration can happen at any time and should use the `STALKER` macro to
do so.
## Plugin methods
The plugin provides the `StalkerEffect` object, which has the following
properties:
### `.variant`
> 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.
### `.step_length`
> The length - in milliseconds - of each step of the animation. An animation
> lasts 256 steps.
>
> Defaults to 50.
## Plugin helpers
### `STALKER(effect, params)`
> Returns an effect, to be used to assign a value the `.variant` property of the
> `StalkerEffect` object. Any arguments given to the macro are passed on
> to the effect. If the effect takes no arguments, use an empty `params` list.
## Plugin effects
The plugin provides the following effects:
### `Haunt([color])`
> A ghostly haunt effect, that trails the key taps with a ghostly white color
> (or any other color, if specified). Use the `CRGB(r,g,b)` macro to specify the
> color, if you want something else than the ghostly white.
### `BlazingTrail()`
> A blazing trail of fire will follow our fingers!
### `Rainbow()`
> Leave a rainbow behind, where your fingers has been!
## Dependencies
* [Kaleidoscope-LEDControl](LEDControl.md)
## Further reading
Starting from the [example][plugin:example] is the recommended way of getting
started with the plugin.
[plugin:example]: ../../examples/LED-Stalker/LED-Stalker.ino

@ -0,0 +1,57 @@
/* -*- mode: c++ -*-
* Kaleidoscope-LED-Stalker -- Stalk keys pressed by lighting up and fading back the LED under them
* Copyright (C) 2017, 2018 Keyboard.io, Inc
*
* 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 the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LED-Stalker.h>
// *INDENT-OFF*
const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED
(
Key_LEDEffectNext, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext,
Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab,
Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G,
Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
Key_NoKey,
Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip,
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals,
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_NoKey),
};
// *INDENT-ON*
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
LEDOff,
StalkerEffect);
void setup() {
Kaleidoscope.setup();
StalkerEffect.variant = STALKER(BlazingTrail);
StalkerEffect.activate();
}
void loop() {
Kaleidoscope.loop();
}

@ -0,0 +1,20 @@
/* -*- mode: c++ -*-
* Kaleidoscope-LED-Stalker -- Stalk keys pressed by lighting up and fading back the LED under them
* Copyright (C) 2017 Keyboard.io, Inc
*
* 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 the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <kaleidoscope/plugin/LED-Stalker.h>

@ -0,0 +1,144 @@
/* -*- mode: c++ -*-
* Kaleidoscope-LED-Stalker -- Stalk keys pressed by lighting up and fading back the LED under them
* Copyright (C) 2017, 2018 Keyboard.io, Inc
*
* 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 the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Kaleidoscope-LED-Stalker.h>
namespace kaleidoscope {
namespace plugin {
uint8_t StalkerEffect::map_[ROWS][COLS];
StalkerEffect::ColorComputer *StalkerEffect::variant;
uint16_t StalkerEffect::step_length = 50;
uint16_t StalkerEffect::step_start_time_;
void StalkerEffect::onActivate(void) {
memset(map_, 0, sizeof(map_));
}
EventHandlerResult StalkerEffect::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t keyState) {
if (row >= ROWS || col >= COLS)
return EventHandlerResult::OK;
if (keyIsPressed(keyState)) {
map_[row][col] = 0xff;
}
return EventHandlerResult::OK;
}
void StalkerEffect::update(void) {
if (!variant)
return;
uint16_t now = millis();
uint16_t elapsed = Kaleidoscope.millisAtCycleStart() - step_start_time_;
for (byte r = 0; r < ROWS; r++) {
for (byte c = 0; c < COLS; c++) {
uint8_t step = map_[r][c];
if (step) {
::LEDControl.setCrgbAt(r, c, variant->compute(&step));
}
if (elapsed > step_length) {
map_[r][c] = step;
}
if (!map_[r][c])
::LEDControl.setCrgbAt(r, c, (cRGB) {
0, 0, 0
});
}
}
if (elapsed > step_length)
step_start_time_ = Kaleidoscope.millisAtCycleStart();
}
namespace stalker {
cRGB Haunt::highlight_color_;
// Haunt
Haunt::Haunt(const cRGB highlight_color) {
highlight_color_ = highlight_color;
}
cRGB Haunt::compute(uint8_t *step) {
cRGB color = CRGB((uint8_t)min(*step * highlight_color_.r / 255, 255),
(uint8_t)min(*step * highlight_color_.g / 255, 255),
(uint8_t)min(*step * highlight_color_.b / 255, 255));
if (*step >= 0xf0)
*step -= 1;
else if (*step >= 0x40)
*step -= 16;
else if (*step >= 32)
*step -= 32;
else
*step = 0;
return color;
}
// BlazingTrail
BlazingTrail::BlazingTrail(void) {
}
cRGB BlazingTrail::compute(uint8_t *step) {
cRGB color;
if (*step >= 0xff - 30) {
color = hsvToRgb(0xff - *step, 255, 255);
} else {
color = hsvToRgb(30, 255, 255);
color.r = min(*step * color.r / 255, 255);
color.g = min(*step * color.g / 255, 255);
}
if (*step >= 0xff - 30)
*step -= 1;
else if (*step >= 0x40)
*step -= 16;
else if (*step >= 32)
*step -= 32;
else
*step = 0;
return color;
}
// Rainbow
Rainbow::Rainbow(void) {
}
cRGB Rainbow::compute(uint8_t *step) {
if (*step > 0)
*step -= 1;
else
*step = 0;
return hsvToRgb(255 - *step, 255, *step);
}
}
}
}
kaleidoscope::plugin::StalkerEffect StalkerEffect;

@ -0,0 +1,80 @@
/* -*- mode: c++ -*-
* Kaleidoscope-LED-Stalker -- Stalk keys pressed by lighting up and fading back the LED under them
* Copyright (C) 2017, 2018 Keyboard.io, Inc
*
* 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 the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#define STALKER(v, ...) ({static kaleidoscope::plugin::stalker::v _effect __VA_ARGS__; &_effect;})
namespace kaleidoscope {
namespace plugin {
class StalkerEffect : public LEDMode {
public:
class ColorComputer {
public:
virtual cRGB compute(uint8_t *step) = 0;
};
StalkerEffect(void) {}
static ColorComputer *variant;
static uint16_t step_length;
EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t keyState);
protected:
void onActivate(void) final;
void update(void) final;
private:
static uint16_t step_start_time_;
static uint8_t map_[ROWS][COLS];
};
namespace stalker {
class Haunt : public StalkerEffect::ColorComputer {
public:
explicit Haunt(const cRGB highlight_color);
Haunt(void) : Haunt(CRGB(0x40, 0x80, 0x80)) {}
cRGB compute(uint8_t *step) final;
private:
static cRGB highlight_color_;
};
class BlazingTrail : public StalkerEffect::ColorComputer {
public:
BlazingTrail(void);
cRGB compute(uint8_t *step) final;
};
class Rainbow : public StalkerEffect::ColorComputer {
public:
Rainbow(void);
cRGB compute(uint8_t *step) final;
};
}
}
}
extern kaleidoscope::plugin::StalkerEffect StalkerEffect;
Loading…
Cancel
Save