From 6a5a7166c18a44a972f223f3d80d69c912398034 Mon Sep 17 00:00:00 2001 From: "James N. V. Cash" Date: Mon, 13 Nov 2017 16:31:21 -0500 Subject: [PATCH] Add theme focus handler for layerwise themes --- src/Kaleidoscope/LED-Palette-Theme.cpp | 40 ++++++++++++++++++++++++++ src/Kaleidoscope/LED-Palette-Theme.h | 4 +++ 2 files changed, 44 insertions(+) diff --git a/src/Kaleidoscope/LED-Palette-Theme.cpp b/src/Kaleidoscope/LED-Palette-Theme.cpp index d2275a07..bde22f7d 100644 --- a/src/Kaleidoscope/LED-Palette-Theme.cpp +++ b/src/Kaleidoscope/LED-Palette-Theme.cpp @@ -158,6 +158,46 @@ bool LEDPaletteTheme::themeFocusHandler(const char *command, const char *expecte return true; } +bool LEDPaletteTheme::themeFocusHandlerLayerwise(const char *command, + const char *expected_command, + uint16_t theme_base, + uint8_t max_themes) { + if (strcmp_P(command, expected_command) != 0) + return false; + + uint16_t count_per_layer = (ROWS * COLS) / 2; + + uint8_t layer = Serial.parseInt(); + + uint16_t offset = theme_base + (layer * count_per_layer); + + if (Serial.peek() == '\n') { + for (uint16_t pos = 0; pos < count_per_layer; pos++) { + uint8_t indexes = EEPROM.read(offset + pos); + + ::Focus.printNumber(indexes >> 4); + ::Focus.printSpace(); + ::Focus.printNumber(indexes & ~0xf0); + ::Focus.printSpace(); + } + Serial.println(); + return true; + } + + uint16_t pos = 0; + + while ((Serial.peek() != '\n') && (pos < count_per_layer)) { + uint8_t idx1 = Serial.parseInt(); + uint8_t idx2 = Serial.parseInt(); + uint8_t indexes = (idx1 << 4) + idx2; + + EEPROM.update(offset + pos, indexes); + pos++; + } + + return true; +} + } kaleidoscope::LEDPaletteTheme LEDPaletteTheme; diff --git a/src/Kaleidoscope/LED-Palette-Theme.h b/src/Kaleidoscope/LED-Palette-Theme.h index a1dc6fb6..0b1e2219 100644 --- a/src/Kaleidoscope/LED-Palette-Theme.h +++ b/src/Kaleidoscope/LED-Palette-Theme.h @@ -43,6 +43,10 @@ class LEDPaletteTheme : public KaleidoscopePlugin { static bool themeFocusHandler(const char *command, const char *expected_command, uint16_t theme_base, uint8_t max_themes); + static bool themeFocusHandlerLayerwise(const char *command, + const char *expected_command, + uint16_t theme_base, + uint8_t max_themes); private: static uint16_t palette_base_; };