From 7aef9b7e6c22a4cc842b1a7586239bf6dd97d20b Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Fri, 19 Apr 2024 21:55:53 +0200 Subject: [PATCH 1/6] Expand palette to 24 colors Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/DefaultPalette.cpp | 2 +- .../src/kaleidoscope/plugin/DefaultPalette.h | 10 ++++++---- .../src/kaleidoscope/plugin/LED-Palette-Theme.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.cpp b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.cpp index 02ab271fff..a5b99fc05e 100644 --- a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.cpp +++ b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.cpp @@ -31,7 +31,7 @@ __attribute__((weak)) extern bool palette_defined = false; void DefaultPalette::setup() { if (!ledpalette::palette_defined) return; - for (uint8_t i = 0; i < 16; i++) { + for (uint8_t i = 0; i < 24; i++) { cRGB color; color.r = pgm_read_byte(&(ledpalette::palette[i].r)); diff --git a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h index 622b713d11..998b65802a 100644 --- a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h +++ b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h @@ -40,14 +40,16 @@ class DefaultPalette : public Plugin { // clang-format off -#define PALETTE(p0, p1, p2, p3, p4, p5, p6, p7, \ - p8, p9, pa, pb, pc, pd, pe, pf) \ +#define PALETTE(p00, p01, p02, p03, p04, p05, p06, p07, \ + p08, p09, p0a, p0b, p0c, p0d, p0e, p0f, \ + p10, p11, p12, p13, p14, p15, p16, p17) \ namespace kaleidoscope { \ namespace plugin { \ namespace ledpalette { \ const cRGB palette[] PROGMEM = { \ - p0, p1, p2, p3, p4, p5, p6, p7, \ - p8, p9, pa, pb, pc, pd, pe, pf \ + p00, p01, p02, p03, p04, p05, p06, p07, \ + p08, p09, p0a, p0b, p0c, p0d, p0e, p0f, \ + p10, p11, p12, p13, p14, p15, p16, p17 \ }; \ bool palette_defined = true; \ } /* defaultcolormap */ \ diff --git a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.cpp b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.cpp index 1f64451f31..04109d80b5 100644 --- a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.cpp +++ b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.cpp @@ -35,7 +35,7 @@ uint16_t LEDPaletteTheme::palette_base_; uint16_t LEDPaletteTheme::reserveThemes(uint8_t max_themes) { if (!palette_base_) - palette_base_ = ::EEPROMSettings.requestSlice(16 * sizeof(cRGB)); + palette_base_ = ::EEPROMSettings.requestSlice(24 * sizeof(cRGB)); return ::EEPROMSettings.requestSlice(max_themes * Runtime.device().led_count / 2); } @@ -116,7 +116,7 @@ void LEDPaletteTheme::updatePaletteColor(uint8_t palette_index, cRGB color) { } bool LEDPaletteTheme::isThemeUninitialized(uint16_t theme_base, uint8_t max_themes) { - bool paletteEmpty = Runtime.storage().isSliceUninitialized(palette_base_, 16 * sizeof(cRGB)); + bool paletteEmpty = Runtime.storage().isSliceUninitialized(palette_base_, 24 * sizeof(cRGB)); bool themeEmpty = Runtime.storage().isSliceUninitialized(theme_base, max_themes * Runtime.device().led_count / 2); return paletteEmpty && themeEmpty; @@ -135,7 +135,7 @@ EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *input) { return EventHandlerResult::OK; if (::Focus.isEOL()) { - for (uint8_t i = 0; i < 16; i++) { + for (uint8_t i = 0; i < 24; i++) { cRGB color; color = lookupPaletteColor(i); @@ -145,7 +145,7 @@ EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *input) { } uint8_t i = 0; - while (i < 16 && !::Focus.isEOL()) { + while (i < 24 && !::Focus.isEOL()) { cRGB color; ::Focus.read(color); From 96d61e5f8bc1075183df1d9b5d5d3d785b36289e Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sun, 21 Apr 2024 11:01:05 +0200 Subject: [PATCH 2/6] Define palette size only once Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/DefaultPalette.cpp | 2 +- .../src/kaleidoscope/plugin/LED-Palette-Theme.cpp | 13 +++++++++---- .../src/kaleidoscope/plugin/LED-Palette-Theme.h | 3 +++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.cpp b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.cpp index a5b99fc05e..0f43874b0f 100644 --- a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.cpp +++ b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.cpp @@ -31,7 +31,7 @@ __attribute__((weak)) extern bool palette_defined = false; void DefaultPalette::setup() { if (!ledpalette::palette_defined) return; - for (uint8_t i = 0; i < 24; i++) { + for (uint8_t i = 0; i < LEDPaletteTheme::getPaletteSize(); i++) { cRGB color; color.r = pgm_read_byte(&(ledpalette::palette[i].r)); diff --git a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.cpp b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.cpp index 04109d80b5..2df03f8e8f 100644 --- a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.cpp +++ b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.cpp @@ -32,10 +32,11 @@ namespace kaleidoscope { namespace plugin { uint16_t LEDPaletteTheme::palette_base_; +uint8_t LEDPaletteTheme::palette_size_ = 24; uint16_t LEDPaletteTheme::reserveThemes(uint8_t max_themes) { if (!palette_base_) - palette_base_ = ::EEPROMSettings.requestSlice(24 * sizeof(cRGB)); + palette_base_ = ::EEPROMSettings.requestSlice(palette_size_ * sizeof(cRGB)); return ::EEPROMSettings.requestSlice(max_themes * Runtime.device().led_count / 2); } @@ -116,12 +117,16 @@ void LEDPaletteTheme::updatePaletteColor(uint8_t palette_index, cRGB color) { } bool LEDPaletteTheme::isThemeUninitialized(uint16_t theme_base, uint8_t max_themes) { - bool paletteEmpty = Runtime.storage().isSliceUninitialized(palette_base_, 24 * sizeof(cRGB)); + bool paletteEmpty = Runtime.storage().isSliceUninitialized(palette_base_, palette_size_ * sizeof(cRGB)); bool themeEmpty = Runtime.storage().isSliceUninitialized(theme_base, max_themes * Runtime.device().led_count / 2); return paletteEmpty && themeEmpty; } +uint8_t LEDPaletteTheme::getPaletteSize() { + return LEDPaletteTheme::palette_size_; +} + EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *input) { if (!Runtime.has_leds) return EventHandlerResult::OK; @@ -135,7 +140,7 @@ EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *input) { return EventHandlerResult::OK; if (::Focus.isEOL()) { - for (uint8_t i = 0; i < 24; i++) { + for (uint8_t i = 0; i < palette_size_; i++) { cRGB color; color = lookupPaletteColor(i); @@ -145,7 +150,7 @@ EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *input) { } uint8_t i = 0; - while (i < 24 && !::Focus.isEOL()) { + while (i < palette_size_ && !::Focus.isEOL()) { cRGB color; ::Focus.read(color); diff --git a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.h b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.h index 8612e2904c..18793fb7ac 100644 --- a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.h +++ b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/LED-Palette-Theme.h @@ -47,8 +47,11 @@ class LEDPaletteTheme : public kaleidoscope::Plugin { uint8_t max_themes); static bool isThemeUninitialized(uint16_t theme_base, uint8_t max_themes); + static uint8_t getPaletteSize(); + private: static uint16_t palette_base_; + static uint8_t palette_size_; }; } // namespace plugin From 0a39cc6c4caa19d8f51b5b3a2cbab950eadf1617 Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sun, 21 Apr 2024 12:31:44 +0200 Subject: [PATCH 3/6] Prepare support for dynamic palette size Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/DefaultPalette.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h index 998b65802a..b443a579e2 100644 --- a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h +++ b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h @@ -19,8 +19,9 @@ #include // for PROGMEM -#include "kaleidoscope/device/device.h" // for cRGB -#include "kaleidoscope/plugin.h" // for Plugin +#include "kaleidoscope/device/device.h" // for cRGB, CRGB +#include "kaleidoscope/plugin.h" // for Plugin +#include "kaleidoscope/plugin/LED-Palette-Theme.h" // for LEDPaletteTheme namespace kaleidoscope { namespace plugin { @@ -28,6 +29,18 @@ namespace plugin { namespace ledpalette { extern bool palette_defined; extern const cRGB palette[]; + +template +void configurePalette(cRGB const (&colors)[_color_count]) { + for (uint8_t i = 0; i < LEDPaletteTheme::getPaletteSize(); i++) { + if (i < _color_count) { + palette[i] = colors[i]; + } else { + palette[i] = CRGB(0x00, 0x00, 0x00); + } + } + bool palette_defined = true; +} } // namespace ledpalette class DefaultPalette : public Plugin { From ff8e3b25a450091d4e660efe32646c97f57647d2 Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Thu, 2 May 2024 21:01:07 +0200 Subject: [PATCH 4/6] Have PALETTE support 16 or more arguments Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/DefaultPalette.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h index b443a579e2..8e41ea05f4 100644 --- a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h +++ b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h @@ -55,14 +55,14 @@ class DefaultPalette : public Plugin { #define PALETTE(p00, p01, p02, p03, p04, p05, p06, p07, \ p08, p09, p0a, p0b, p0c, p0d, p0e, p0f, \ - p10, p11, p12, p13, p14, p15, p16, p17) \ + ...) \ namespace kaleidoscope { \ namespace plugin { \ namespace ledpalette { \ const cRGB palette[] PROGMEM = { \ p00, p01, p02, p03, p04, p05, p06, p07, \ - p08, p09, p0a, p0b, p0c, p0d, p0e, p0f, \ - p10, p11, p12, p13, p14, p15, p16, p17 \ + p08, p09, p0a, p0b, p0c, p0d, p0e, p0f \ + __VA_OPT__(,) __VA_ARGS__ \ }; \ bool palette_defined = true; \ } /* defaultcolormap */ \ From 01f9a9e39d7fa1851b9c6992ec9624c5d90c3c5c Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Fri, 3 May 2024 19:05:03 +0200 Subject: [PATCH 5/6] Fix the dynamic palette size Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/DefaultPalette.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h index 8e41ea05f4..c3a32fb1cf 100644 --- a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h +++ b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h @@ -54,15 +54,13 @@ class DefaultPalette : public Plugin { // clang-format off #define PALETTE(p00, p01, p02, p03, p04, p05, p06, p07, \ - p08, p09, p0a, p0b, p0c, p0d, p0e, p0f, \ - ...) \ + p08, p09, p0a, p0b, p0c, p0d, p0e, ...) \ namespace kaleidoscope { \ namespace plugin { \ namespace ledpalette { \ const cRGB palette[] PROGMEM = { \ p00, p01, p02, p03, p04, p05, p06, p07, \ - p08, p09, p0a, p0b, p0c, p0d, p0e, p0f \ - __VA_OPT__(,) __VA_ARGS__ \ + p08, p09, p0a, p0b, p0c, p0d, p0e, ##__VA_ARGS__ \ }; \ bool palette_defined = true; \ } /* defaultcolormap */ \ From 9a120c0d1ae0ae5e85a0647247ec1cede237bf72 Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sat, 4 May 2024 14:21:38 +0200 Subject: [PATCH 6/6] Clean up unneeded changes Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/DefaultPalette.h | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h index c3a32fb1cf..7a25c48c1d 100644 --- a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h +++ b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h @@ -19,9 +19,8 @@ #include // for PROGMEM -#include "kaleidoscope/device/device.h" // for cRGB, CRGB -#include "kaleidoscope/plugin.h" // for Plugin -#include "kaleidoscope/plugin/LED-Palette-Theme.h" // for LEDPaletteTheme +#include "kaleidoscope/device/device.h" // for cRGB +#include "kaleidoscope/plugin.h" // for Plugin namespace kaleidoscope { namespace plugin { @@ -29,18 +28,6 @@ namespace plugin { namespace ledpalette { extern bool palette_defined; extern const cRGB palette[]; - -template -void configurePalette(cRGB const (&colors)[_color_count]) { - for (uint8_t i = 0; i < LEDPaletteTheme::getPaletteSize(); i++) { - if (i < _color_count) { - palette[i] = colors[i]; - } else { - palette[i] = CRGB(0x00, 0x00, 0x00); - } - } - bool palette_defined = true; -} } // namespace ledpalette class DefaultPalette : public Plugin { @@ -53,14 +40,14 @@ class DefaultPalette : public Plugin { // clang-format off -#define PALETTE(p00, p01, p02, p03, p04, p05, p06, p07, \ - p08, p09, p0a, p0b, p0c, p0d, p0e, ...) \ +#define PALETTE(p0, p1, p2, p3, p4, p5, p6, p7, \ + p8, p9, pa, pb, pc, pd, pe, ...) \ namespace kaleidoscope { \ namespace plugin { \ namespace ledpalette { \ const cRGB palette[] PROGMEM = { \ - p00, p01, p02, p03, p04, p05, p06, p07, \ - p08, p09, p0a, p0b, p0c, p0d, p0e, ##__VA_ARGS__ \ + p0, p1, p2, p3, p4, p5, p6, p7, \ + p8, p9, pa, pb, pc, pd, pe, ##__VA_ARGS__ \ }; \ bool palette_defined = true; \ } /* defaultcolormap */ \