From c07288cc5edb2b60e10c4568a1d563f5fed11d94 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Mon, 27 Mar 2017 16:54:15 +0200 Subject: [PATCH] Add an (optional) Focus hook Signed-off-by: Gergely Nagy --- src/Kaleidoscope-LEDControl.cpp | 76 +++++++++++++++++++++++++++++++++ src/Kaleidoscope-LEDControl.h | 7 +++ 2 files changed, 83 insertions(+) diff --git a/src/Kaleidoscope-LEDControl.cpp b/src/Kaleidoscope-LEDControl.cpp index 7e440afc..24047283 100644 --- a/src/Kaleidoscope-LEDControl.cpp +++ b/src/Kaleidoscope-LEDControl.cpp @@ -1,4 +1,5 @@ #include "Kaleidoscope-LEDControl.h" +#include "Kaleidoscope-Focus.h" LEDMode *LEDControl_::modes[LED_MAX_MODES]; uint8_t LEDControl_::previousMode, LEDControl_::mode; @@ -155,4 +156,79 @@ LEDControl_::loopHook (bool postClear) { update(); } +bool +LEDControl_::focusHook (const char *command) { + enum { + SETALL, + MODE, + AT + } subCommand; + + if (strncmp_P (command, PSTR ("led."), 4) != 0) + return false; + if (strcmp_P (command + 4, PSTR ("at")) == 0) + subCommand = AT; + else if (strcmp_P (command + 4, PSTR ("setAll")) == 0) + subCommand = SETALL; + else if (strcmp_P (command + 4, PSTR ("mode")) == 0) + subCommand = MODE; + else + return false; + + switch (subCommand) { + case AT: + { + uint8_t idx = Serial.parseInt (); + + if (Serial.peek () == '\n') { + cRGB c = LEDControl.led_get_crgb_at (idx); + + Focus.printColor (c); + Serial.println (); + } else { + cRGB c; + + c.r = Serial.parseInt (); + c.g = Serial.parseInt (); + c.b = Serial.parseInt (); + + LEDControl.led_set_crgb_at (idx, c); + } + break; + } + case SETALL: + { + cRGB c; + + c.r = Serial.parseInt (); + c.g = Serial.parseInt (); + c.b = Serial.parseInt (); + + LEDControl.set_all_leds_to (c); + + break; + } + case MODE: + { + char peek = Serial.peek (); + if (peek == '\n') { + Serial.println (LEDControl.get_mode ()); + } else if (peek == 'n') { + LEDControl.next_mode (); + Serial.read (); + } else if (peek == 'p') { + // TODO + Serial.read (); + } else { + uint8_t mode = Serial.parseInt (); + + LEDControl.set_mode (mode); + } + break; + } + } + + return true; +} + LEDControl_ LEDControl; diff --git a/src/Kaleidoscope-LEDControl.h b/src/Kaleidoscope-LEDControl.h index 81280b58..6a25bfc8 100644 --- a/src/Kaleidoscope-LEDControl.h +++ b/src/Kaleidoscope-LEDControl.h @@ -43,6 +43,8 @@ class LEDControl_ : public KaleidoscopePlugin { static uint16_t syncDelay; + static bool focusHook (const char *command); + private: static uint32_t syncTimer; static LEDMode *modes[LED_MAX_MODES]; @@ -53,3 +55,8 @@ class LEDControl_ : public KaleidoscopePlugin { }; extern LEDControl_ LEDControl; + +#define FOCUS_HOOK_LEDCONTROL FOCUS_HOOK (LEDControl.focusHook, \ + "led.at\n" \ + "led.setAll\n" \ + "led.mode")