From 0f32840a3a554e6425ada26fa1ac41a6acb0dbf3 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 13 May 2018 10:11:15 +0200 Subject: [PATCH] Updated to use the new plugin APIs Signed-off-by: Gergely Nagy --- README.md | 5 ++--- examples/MagicCombo/MagicCombo.ino | 12 ++++++------ src/Kaleidoscope/MagicCombo.cpp | 30 +++++++++++++++++++----------- src/Kaleidoscope/MagicCombo.h | 18 +++++++++++------- 4 files changed, 38 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 621fde69..ec713d59 100644 --- a/README.md +++ b/README.md @@ -41,11 +41,10 @@ void magicComboActions(uint8_t combo_index, uint32_t left_hand, uint32_t right_h } } +KALEIDOSCOPE_INIT_PLUGINS(MagicCombo); + void setup() { Serial.begin(9600); - - Kaleidoscope.use(&MagicCombo); - Kaleidoscope.setup(); MagicCombo.magic_combos = magic_combos; diff --git a/examples/MagicCombo/MagicCombo.ino b/examples/MagicCombo/MagicCombo.ino index 77e51103..4d0256f3 100644 --- a/examples/MagicCombo/MagicCombo.ino +++ b/examples/MagicCombo/MagicCombo.ino @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-MagicCombo -- Magic combo framework - * Copyright (C) 2016, 2017 Gergely Nagy + * Copyright (C) 2016, 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 @@ -35,7 +35,7 @@ static const kaleidoscope::MagicCombo::combo_t magic_combos[] PROGMEM = { {0, 0} }; - +// *INDENT-OFF* const Key keymaps[][ROWS][COLS] PROGMEM = { [0] = KEYMAP_STACKED ( @@ -49,18 +49,18 @@ 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* + +KALEIDOSCOPE_INIT_PLUGINS(MagicCombo); void setup() { Serial.begin(9600); - - Kaleidoscope.use(&MagicCombo); - Kaleidoscope.setup(); MagicCombo.magic_combos = magic_combos; diff --git a/src/Kaleidoscope/MagicCombo.cpp b/src/Kaleidoscope/MagicCombo.cpp index ef016687..b220717b 100644 --- a/src/Kaleidoscope/MagicCombo.cpp +++ b/src/Kaleidoscope/MagicCombo.cpp @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-MagicCombo -- Magic combo framework - * Copyright (C) 2016, 2017 Gergely Nagy + * Copyright (C) 2016, 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 @@ -34,16 +34,9 @@ const MagicCombo::combo_t *MagicCombo::magic_combos; uint16_t MagicCombo::min_interval = 500; uint32_t MagicCombo::end_time_; -MagicCombo::MagicCombo(void) { -} - -void MagicCombo::begin(void) { - Kaleidoscope.useLoopHook(loopHook); -} - -void MagicCombo::loopHook(bool is_post_clear) { - if (!magic_combos || is_post_clear) - return; +EventHandlerResult MagicCombo::beforeReportingState() { + if (!magic_combos) + return EventHandlerResult::OK; for (byte i = 0;; i++) { combo_t combo; @@ -63,8 +56,23 @@ void MagicCombo::loopHook(bool is_post_clear) { break; } } + + return EventHandlerResult::OK; } +// Legacy V1 API +#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API +void MagicCombo::begin() { + Kaleidoscope.useLoopHook(legacyLoopHook); +} + +void MagicCombo::legacyLoopHook(bool is_post_clear) { + if (is_post_clear) + return; + ::MagicCombo.beforeReportingState(); +} +#endif + }; __attribute__((weak)) void magicComboActions(uint8_t comboIndex, uint32_t left_hand, uint32_t right_hand) { diff --git a/src/Kaleidoscope/MagicCombo.h b/src/Kaleidoscope/MagicCombo.h index 2633ba91..8c8a3dc8 100644 --- a/src/Kaleidoscope/MagicCombo.h +++ b/src/Kaleidoscope/MagicCombo.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-MagicCombo -- Magic combo framework - * Copyright (C) 2016, 2017 Gergely Nagy + * Copyright (C) 2016, 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 @@ -22,23 +22,27 @@ namespace kaleidoscope { -class MagicCombo : public KaleidoscopePlugin { +class MagicCombo : public kaleidoscope::Plugin { public: typedef struct { uint32_t left_hand, right_hand; } combo_t; - MagicCombo(void); - - void begin(void) final; + MagicCombo(void) {} static const combo_t *magic_combos; static uint16_t min_interval; + EventHandlerResult beforeReportingState(); + +#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API + protected: + void begin(); + static void legacyLoopHook(bool is_post_clear); +#endif + private: static uint32_t end_time_; - - static void loopHook(bool is_post_clear); }; }