From 7ae4cae1e190759065d39ad20e1710e1fc5a0705 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Fri, 5 Oct 2018 14:53:08 +0200 Subject: [PATCH] Migrate to the new onFocusEvent APIs Signed-off-by: Gergely Nagy --- src/Kaleidoscope-LEDControl.cpp | 35 ++++++++++++++++++++------------- src/Kaleidoscope-LEDControl.h | 16 +++++++-------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/Kaleidoscope-LEDControl.cpp b/src/Kaleidoscope-LEDControl.cpp index c43c7918..4b215e55 100644 --- a/src/Kaleidoscope-LEDControl.cpp +++ b/src/Kaleidoscope-LEDControl.cpp @@ -15,7 +15,7 @@ */ #include "Kaleidoscope-LEDControl.h" -#include "Kaleidoscope-Focus.h" +#include "Kaleidoscope-FocusSerial.h" namespace kaleidoscope { @@ -175,7 +175,7 @@ kaleidoscope::EventHandlerResult LEDControl::beforeReportingState(void) { return kaleidoscope::EventHandlerResult::OK; } -bool LEDControl::focusHook(const char *command) { +EventHandlerResult FocusLEDCommand::onFocusEvent(const char *command) { enum { SETALL, MODE, @@ -183,8 +183,14 @@ bool LEDControl::focusHook(const char *command) { THEME, } subCommand; + if (::Focus.handleHelp(command, PSTR("led.at\n" + "led.setAll\n" + "led.mode\n" + "led.theme"))) + return EventHandlerResult::OK; + if (strncmp_P(command, PSTR("led."), 4) != 0) - return false; + return EventHandlerResult::OK; if (strcmp_P(command + 4, PSTR("at")) == 0) subCommand = AT; else if (strcmp_P(command + 4, PSTR("setAll")) == 0) @@ -194,14 +200,14 @@ bool LEDControl::focusHook(const char *command) { else if (strcmp_P(command + 4, PSTR("theme")) == 0) subCommand = THEME; else - return false; + return EventHandlerResult::OK; switch (subCommand) { case AT: { uint8_t idx = Serial.parseInt(); if (Serial.peek() == '\n') { - cRGB c = getCrgbAt(idx); + cRGB c = ::LEDControl.getCrgbAt(idx); ::Focus.printColor(c.r, c.g, c.b); Serial.println(); @@ -210,7 +216,7 @@ bool LEDControl::focusHook(const char *command) { ::Focus.readColor(c); - setCrgbAt(idx, c); + ::LEDControl.setCrgbAt(idx, c); } break; } @@ -219,31 +225,31 @@ bool LEDControl::focusHook(const char *command) { ::Focus.readColor(c); - set_all_leds_to(c); + ::LEDControl.set_all_leds_to(c); break; } case MODE: { char peek = Serial.peek(); if (peek == '\n') { - Serial.println(get_mode_index()); + Serial.println(::LEDControl.get_mode_index()); } else if (peek == 'n') { - next_mode(); + ::LEDControl.next_mode(); Serial.read(); } else if (peek == 'p') { - prev_mode(); + ::LEDControl.prev_mode(); Serial.read(); } else { uint8_t mode = Serial.parseInt(); - set_mode(mode); + ::LEDControl.set_mode(mode); } break; } case THEME: { if (Serial.peek() == '\n') { for (uint8_t idx = 0; idx < LED_COUNT; idx++) { - cRGB c = getCrgbAt(idx); + cRGB c = ::LEDControl.getCrgbAt(idx); ::Focus.printColor(c.r, c.g, c.b); ::Focus.printSpace(); @@ -258,16 +264,17 @@ bool LEDControl::focusHook(const char *command) { ::Focus.readColor(color); - setCrgbAt(idx, color); + ::LEDControl.setCrgbAt(idx, color); idx++; } break; } } - return true; + return EventHandlerResult::EVENT_CONSUMED; } } kaleidoscope::LEDControl LEDControl; +kaleidoscope::FocusLEDCommand FocusLEDCommand; diff --git a/src/Kaleidoscope-LEDControl.h b/src/Kaleidoscope-LEDControl.h index f14daf9d..853a11fc 100644 --- a/src/Kaleidoscope-LEDControl.h +++ b/src/Kaleidoscope-LEDControl.h @@ -142,8 +142,6 @@ class LEDControl : public kaleidoscope::Plugin { static uint16_t syncDelay; static bool paused; - static bool focusHook(const char *command); - kaleidoscope::EventHandlerResult onSetup(); kaleidoscope::EventHandlerResult onKeyswitchEvent(Key &mappedKey, byte row, byte col, uint8_t keyState); kaleidoscope::EventHandlerResult beforeReportingState(); @@ -154,12 +152,14 @@ class LEDControl : public kaleidoscope::Plugin { static uint8_t mode; }; +class FocusLEDCommand : public Plugin { +public: + FocusLEDCommand() {} + + EventHandlerResult onFocusEvent(const char *command); +}; + } extern kaleidoscope::LEDControl LEDControl; - -#define FOCUS_HOOK_LEDCONTROL FOCUS_HOOK (LEDControl.focusHook, \ - "led.at\n" \ - "led.setAll\n" \ - "led.theme\n" \ - "led.mode") +extern kaleidoscope::FocusLEDCommand FocusLEDCommand;