From 8b1fb19bd06f9684b620fba2eccaec1dcec2f793 Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sun, 26 May 2024 20:47:45 +0200 Subject: [PATCH 1/8] Fix data type Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/Colormap-Overlay.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h index 949eaaf9d5..e70255b433 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h @@ -30,7 +30,7 @@ namespace plugin { // Data structure for an individual qukey struct Overlay { - int8_t layer; + uint8_t layer; KeyAddr addr; uint8_t palette_index; From bea3089d1195d0d0afa2f046b30f78e606a71e4c Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sun, 26 May 2024 20:48:10 +0200 Subject: [PATCH 2/8] First draft for overlays macro Signed-off-by: Evy Bongers --- .../kaleidoscope/plugin/Colormap-Overlay.h | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h index e70255b433..d560a610b0 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h @@ -53,6 +53,17 @@ class ColormapOverlay : public kaleidoscope::Plugin { overlay_count_ = _overlay_count; } + template + void configureOverlays(uint8_t const (&overlays)[_layer_count][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns]) { + overlays_ = Overlay[]; + overlay_count_ = 0; + for (int layer_ = 0; layer_ < _layer_count; layer_++) { + for (int key_index_ = 0; key_index_ < kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns; key_index_++) { + overlays_[overlay_count_] = Overlay(layer_, /* TODO(EvyBongers) */, overlays[layer_][key_index_]); + overlay_count_++; + } + } + } // A wildcard value for a qukey that exists on every layer. static constexpr int8_t layer_wildcard{-1}; @@ -69,6 +80,37 @@ class ColormapOverlay : public kaleidoscope::Plugin { void setLEDOverlayColors(); }; +// clang-format off + +#define COLORMAP_OVERLAYS_MAP(layers...) \ + namespace kaleidoscope { \ + namespace plugin { \ + namespace defaultcolormap { \ + const uint8_t overlays_[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns] = { \ + layers \ + }; \ + ColormapOverlay.configureOverlays(overlays_); \ + } /* plugin */ \ + } /* kaleidoscope */ + +#define __IDENTITY__(X) X + +#ifdef PER_KEY_DATA_STACKED +#define COLORMAP_OVERLAY_STACKED(...) \ + { \ + MAP_LIST(__IDENTITY__, PER_KEY_DATA_STACKED(0, __VA_ARGS__)) \ + } +#endif + +#ifdef PER_KEY_DATA +#define COLORMAP_OVERLAY(...) \ + { \ + MAP_LIST(__IDENTITY__, PER_KEY_DATA(0, __VA_ARGS__)) \ + } +#endif + +// clang-format on + } // namespace plugin } // namespace kaleidoscope From f1e2f68a2028d4a901bd0a2401fa5e4bf6e3e847 Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sun, 26 May 2024 20:57:00 +0200 Subject: [PATCH 3/8] Add todo for validating the colormap index Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/Colormap-Overlay.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h index d560a610b0..757868dce3 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h @@ -59,7 +59,9 @@ class ColormapOverlay : public kaleidoscope::Plugin { overlay_count_ = 0; for (int layer_ = 0; layer_ < _layer_count; layer_++) { for (int key_index_ = 0; key_index_ < kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns; key_index_++) { - overlays_[overlay_count_] = Overlay(layer_, /* TODO(EvyBongers) */, overlays[layer_][key_index_]); + color_index_ = overlays[layer_][key_index_]; + // TODO(EvyBongers): validate the color index? + overlays_[overlay_count_] = Overlay(layer_, /* TODO(EvyBongers) */, color_index_); overlay_count_++; } } From e081290b83cb34740d178a6c016c48292f54b859 Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sun, 26 May 2024 21:09:39 +0200 Subject: [PATCH 4/8] Fix namespaces Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/Colormap-Overlay.h | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h index 757868dce3..e8a2856c1e 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h @@ -87,7 +87,6 @@ class ColormapOverlay : public kaleidoscope::Plugin { #define COLORMAP_OVERLAYS_MAP(layers...) \ namespace kaleidoscope { \ namespace plugin { \ - namespace defaultcolormap { \ const uint8_t overlays_[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns] = { \ layers \ }; \ From 4a0fda19ad796c6003a66a97b115f3ff9553faa3 Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sat, 15 Jun 2024 12:28:18 +0200 Subject: [PATCH 5/8] Pass key addresses correctly Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/Colormap-Overlay.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h index e8a2856c1e..c20fc9edda 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h @@ -59,14 +59,14 @@ class ColormapOverlay : public kaleidoscope::Plugin { overlay_count_ = 0; for (int layer_ = 0; layer_ < _layer_count; layer_++) { for (int key_index_ = 0; key_index_ < kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns; key_index_++) { - color_index_ = overlays[layer_][key_index_]; + uint8_t color_index_ = overlays[layer_][key_index_]; // TODO(EvyBongers): validate the color index? - overlays_[overlay_count_] = Overlay(layer_, /* TODO(EvyBongers) */, color_index_); + overlays_[overlay_count_] = Overlay(layer_, KeyAddr(key_index_), color_index_); overlay_count_++; } } } - // A wildcard value for a qukey that exists on every layer. + // A wildcard value for an overlay that applies on every layer. static constexpr int8_t layer_wildcard{-1}; EventHandlerResult onSetup(); From 1b48824ef3c2faee9fb41cd893f4aa8c8ae616de Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sat, 15 Jun 2024 12:30:41 +0200 Subject: [PATCH 6/8] Finalize first draft Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/Colormap-Overlay.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h index c20fc9edda..ac41ca3f85 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h @@ -59,15 +59,17 @@ class ColormapOverlay : public kaleidoscope::Plugin { overlay_count_ = 0; for (int layer_ = 0; layer_ < _layer_count; layer_++) { for (int key_index_ = 0; key_index_ < kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns; key_index_++) { - uint8_t color_index_ = overlays[layer_][key_index_]; - // TODO(EvyBongers): validate the color index? - overlays_[overlay_count_] = Overlay(layer_, KeyAddr(key_index_), color_index_); - overlay_count_++; + int8_t color_index_ = overlays[layer_][key_index_]; + if (color_index_ != no_color_overlay) { + overlays_[overlay_count_] = Overlay(layer_, KeyAddr(key_index_), color_index_); + overlay_count_++; + } } } } // A wildcard value for an overlay that applies on every layer. static constexpr int8_t layer_wildcard{-1}; + static constexpr int8_t no_color_overlay{-1}; EventHandlerResult onSetup(); EventHandlerResult beforeSyncingLeds(); @@ -87,7 +89,7 @@ class ColormapOverlay : public kaleidoscope::Plugin { #define COLORMAP_OVERLAYS_MAP(layers...) \ namespace kaleidoscope { \ namespace plugin { \ - const uint8_t overlays_[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns] = { \ + const int8_t overlays_[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns] = { \ layers \ }; \ ColormapOverlay.configureOverlays(overlays_); \ From 4485255723c3828760a4c2a306ce2073c2459bdf Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sat, 22 Jun 2024 10:55:07 +0200 Subject: [PATCH 7/8] Validate color index against colormap boundaries Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/Colormap-Overlay.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h index ac41ca3f85..e894b65eec 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h @@ -24,6 +24,7 @@ #include "kaleidoscope/key_defs.h" // for Key, KEY_FLAGS, Key_NoKey, LockLayer #include "kaleidoscope/layers.h" // for Layer, Layer_ #include "kaleidoscope/plugin/LEDControl.h" // for LEDControl +#include // for LEDPaletteTheme namespace kaleidoscope { namespace plugin { @@ -60,7 +61,8 @@ class ColormapOverlay : public kaleidoscope::Plugin { for (int layer_ = 0; layer_ < _layer_count; layer_++) { for (int key_index_ = 0; key_index_ < kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns; key_index_++) { int8_t color_index_ = overlays[layer_][key_index_]; - if (color_index_ != no_color_overlay) { + if (color_index_ >= 0 && color_index_ < ::LEDPaletteTheme.getPaletteSize() && + color_index_ != no_color_overlay) { overlays_[overlay_count_] = Overlay(layer_, KeyAddr(key_index_), color_index_); overlay_count_++; } From cba8718757fc830e96baaf3e6485f7bdd2661725 Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sat, 22 Jun 2024 10:55:57 +0200 Subject: [PATCH 8/8] Fix error Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/Colormap-Overlay.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h index e894b65eec..16a8d4a396 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h @@ -55,8 +55,8 @@ class ColormapOverlay : public kaleidoscope::Plugin { } template - void configureOverlays(uint8_t const (&overlays)[_layer_count][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns]) { - overlays_ = Overlay[]; + void configureOverlays(uint8_t **overlays) { + overlays_ = nullptr; overlay_count_ = 0; for (int layer_ = 0; layer_ < _layer_count; layer_++) { for (int key_index_ = 0; key_index_ < kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns; key_index_++) {