Updated to use the new plugin APIs

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

@ -19,11 +19,12 @@ 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>
void setup (){
Kaleidoscope.use(&StalkerEffect);
KALEIDOSCOPE_INIT_PLUGINS(LEDControl, StalkerEffect);
void setup (){
Kaleidoscope.setup();
StalkerEffect.variant = STALKER(Haunt, (CRGB(0, 128, 0)));

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* Kaleidoscope-LED-Stalker -- Stalk keys pressed by lighting up and fading back the LED under them
* Copyright (C) 2017 Gergely Nagy
* Copyright (C) 2017, 2018 Gergely Nagy
*
* 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
@ -17,9 +17,11 @@
*/
#include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LED-Stalker.h>
#include "LED-Off.h"
// *INDENT-OFF*
const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED
(
@ -39,10 +41,13 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_NoKey),
};
// *INDENT-ON*
void setup() {
Kaleidoscope.use(&LEDOff, &StalkerEffect);
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
LEDOff,
StalkerEffect);
void setup() {
Kaleidoscope.setup();
StalkerEffect.variant = STALKER(BlazingTrail);

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* Kaleidoscope-LED-Stalker -- Stalk keys pressed by lighting up and fading back the LED under them
* Copyright (C) 2017 Gergely Nagy
* Copyright (C) 2017, 2018 Gergely Nagy
*
* 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
@ -26,23 +26,19 @@ StalkerEffect::ColorComputer *StalkerEffect::variant;
uint16_t StalkerEffect::step_length = 50;
uint16_t StalkerEffect::step_start_time_;
void StalkerEffect::setup(void) {
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
}
void StalkerEffect::onActivate(void) {
memset(map_, 0, sizeof(map_));
}
Key StalkerEffect::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
EventHandlerResult StalkerEffect::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t keyState) {
if (row >= ROWS || col >= COLS)
return mapped_key;
return EventHandlerResult::OK;
if (keyIsPressed(key_state)) {
if (keyIsPressed(keyState)) {
map_[row][col] = 0xff;
}
return mapped_key;
return EventHandlerResult::OK;
}
void StalkerEffect::update(void) {
@ -143,6 +139,20 @@ cRGB Rainbow::compute(uint8_t *step) {
}
// Legacy V1 API
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void StalkerEffect::setup(void) {
Kaleidoscope.useEventHandlerHook(legacyEventHandler);
}
Key StalkerEffect::legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state) {
EventHandlerResult r = ::StalkerEffect.onKeyswitchEvent(mapped_key, row, col, key_state);
if (r == EventHandlerResult::OK)
return mapped_key;
return Key_NoKey;
}
#endif
}
kaleidoscope::StalkerEffect StalkerEffect;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* Kaleidoscope-LED-Stalker -- Stalk keys pressed by lighting up and fading back the LED under them
* Copyright (C) 2017 Gergely Nagy
* Copyright (C) 2017, 2018 Gergely Nagy
*
* 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
@ -36,16 +36,19 @@ class StalkerEffect : public LEDMode {
static ColorComputer *variant;
static uint16_t step_length;
EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t keyState);
protected:
void setup(void) final;
void onActivate(void) final;
void update(void) final;
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void setup(void) final;
static Key legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state);
#endif
private:
static uint16_t step_start_time_;
static uint8_t map_[ROWS][COLS];
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
};
namespace stalker {

Loading…
Cancel
Save