From e9b9d41626a4cb572edb2e98c1fa886522a56cd4 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Mon, 14 May 2018 06:27:18 +0200 Subject: [PATCH] Updated to use the new plugin APIs Signed-off-by: Gergely Nagy --- README.md | 5 +++-- examples/LED-Stalker/LED-Stalker.ino | 13 +++++++++---- src/Kaleidoscope/LED-Stalker.cpp | 28 +++++++++++++++++++--------- src/Kaleidoscope/LED-Stalker.h | 11 +++++++---- 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index debffaa6..4dfaa7f0 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,12 @@ To use the plugin, one needs to include the header and select the effect. ```c++ #include +#include #include -void setup (){ - Kaleidoscope.use(&StalkerEffect); +KALEIDOSCOPE_INIT_PLUGINS(LEDControl, StalkerEffect); +void setup (){ Kaleidoscope.setup(); StalkerEffect.variant = STALKER(Haunt, (CRGB(0, 128, 0))); diff --git a/examples/LED-Stalker/LED-Stalker.ino b/examples/LED-Stalker/LED-Stalker.ino index bbab98f8..d5721429 100644 --- a/examples/LED-Stalker/LED-Stalker.ino +++ b/examples/LED-Stalker/LED-Stalker.ino @@ -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 +#include #include #include "LED-Off.h" +// *INDENT-OFF* const Key keymaps[][ROWS][COLS] PROGMEM = { [0] = KEYMAP_STACKED ( @@ -33,16 +35,19 @@ const Key keymaps[][ROWS][COLS] PROGMEM = { 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_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* -void setup() { - Kaleidoscope.use(&LEDOff, &StalkerEffect); +KALEIDOSCOPE_INIT_PLUGINS(LEDControl, + LEDOff, + StalkerEffect); +void setup() { Kaleidoscope.setup(); StalkerEffect.variant = STALKER(BlazingTrail); diff --git a/src/Kaleidoscope/LED-Stalker.cpp b/src/Kaleidoscope/LED-Stalker.cpp index 5e667c3f..57b55304 100644 --- a/src/Kaleidoscope/LED-Stalker.cpp +++ b/src/Kaleidoscope/LED-Stalker.cpp @@ -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; diff --git a/src/Kaleidoscope/LED-Stalker.h b/src/Kaleidoscope/LED-Stalker.h index 1d867659..9f5041f9 100644 --- a/src/Kaleidoscope/LED-Stalker.h +++ b/src/Kaleidoscope/LED-Stalker.h @@ -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 {