From 55c42928f94ac38bd39b5bc0949388c24c1b0916 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Fri, 21 Apr 2017 12:16:57 +0200 Subject: [PATCH] Add a `led.theme` Focus command Allows setting all of the LEDs to custom, distinct colors (as opposed to `led.setAll`, which sets them all to the same color). This allows one to upload a theme in one go, without having to set each LED one by one. Fixes #5. Signed-off-by: Gergely Nagy --- src/Kaleidoscope-LEDControl.cpp | 31 ++++++++++++++++++++++++++++++- src/Kaleidoscope-LEDControl.h | 1 + 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Kaleidoscope-LEDControl.cpp b/src/Kaleidoscope-LEDControl.cpp index 24047283..f91697b6 100644 --- a/src/Kaleidoscope-LEDControl.cpp +++ b/src/Kaleidoscope-LEDControl.cpp @@ -161,7 +161,8 @@ LEDControl_::focusHook (const char *command) { enum { SETALL, MODE, - AT + AT, + THEME, } subCommand; if (strncmp_P (command, PSTR ("led."), 4) != 0) @@ -172,6 +173,8 @@ LEDControl_::focusHook (const char *command) { subCommand = SETALL; else if (strcmp_P (command + 4, PSTR ("mode")) == 0) subCommand = MODE; + else if (strcmp_P (command + 4, PSTR ("theme")) == 0) + subCommand = THEME; else return false; @@ -226,6 +229,32 @@ LEDControl_::focusHook (const char *command) { } break; } + case THEME: + { + if (Serial.peek () == '\n') { + for (uint8_t idx = 0; idx < LED_COUNT; idx++) { + cRGB c = LEDControl.led_get_crgb_at (idx); + + Focus.printColor (c); + Focus.printSpace (); + } + Serial.println (); + break; + } + + uint8_t idx = 0; + while (idx < LED_COUNT && Serial.peek() != '\n') { + cRGB color; + + color.r = Serial.parseInt (); + color.g = Serial.parseInt (); + color.b = Serial.parseInt (); + + LEDControl.led_set_crgb_at (idx, color); + idx++; + } + break; + } } return true; diff --git a/src/Kaleidoscope-LEDControl.h b/src/Kaleidoscope-LEDControl.h index 6a25bfc8..49b0c8df 100644 --- a/src/Kaleidoscope-LEDControl.h +++ b/src/Kaleidoscope-LEDControl.h @@ -59,4 +59,5 @@ extern LEDControl_ LEDControl; #define FOCUS_HOOK_LEDCONTROL FOCUS_HOOK (LEDControl.focusHook, \ "led.at\n" \ "led.setAll\n" \ + "led.theme\n" \ "led.mode")