From 3ea49405c55a728215ac80c43c5c4794736806eb Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Tue, 14 Nov 2023 15:23:53 +0100 Subject: [PATCH 01/10] Migrate and rename Signed-off-by: Evy Bongers --- .../Kaleidoscope-Colormap-Overlay/README.md | 35 ++++++++ .../library.properties | 7 ++ .../src/Kaleidoscope-Colormap-Overlay.h | 19 +++++ .../kaleidoscope/plugin/Colormap-Overlay.cpp | 70 ++++++++++++++++ .../kaleidoscope/plugin/Colormap-Overlay.h | 82 +++++++++++++++++++ 5 files changed, 213 insertions(+) create mode 100644 plugins/Kaleidoscope-Colormap-Overlay/README.md create mode 100644 plugins/Kaleidoscope-Colormap-Overlay/library.properties create mode 100644 plugins/Kaleidoscope-Colormap-Overlay/src/Kaleidoscope-Colormap-Overlay.h create mode 100644 plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp create mode 100644 plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h diff --git a/plugins/Kaleidoscope-Colormap-Overlay/README.md b/plugins/Kaleidoscope-Colormap-Overlay/README.md new file mode 100644 index 0000000000..b9913e27d2 --- /dev/null +++ b/plugins/Kaleidoscope-Colormap-Overlay/README.md @@ -0,0 +1,35 @@ +# Colormap-Overlay + +The `Colormap-Overlay` extension provides an easier way to apply color to +specific keys and layers, regardless of the active LED mode. + +## Using the extension + +To use the extension, include the header, tell it the number of layers you have, +register the `Focus` hooks, and it will do the rest. We'll also set up a default +for both the palette, and the colormap. + +```c++ +#include +#include +#include + +KALEIDOSCOPE_INIT_PLUGINS(LEDControl, + ColormapOverlay); + +void setup() { + Kaleidoscope.setup(); + + COLORMAP_OVERLAYS( + // Make the any key red + kaleidoscope::plugin::Overlay(0, KeyAddr(0, 9), CRGB(0xff, 0x00, 0x00)), + // Disable leds on the palm keys + kaleidoscope::plugin::Overlay(0, KeyAddr(3, 6), CRGB(0x00, 0x00, 0x00)), + kaleidoscope::plugin::Overlay(0, KeyAddr(3, 9), CRGB(0x00, 0x00, 0x00)), + ) +} +``` + +## Plugin methods + +TODO diff --git a/plugins/Kaleidoscope-Colormap-Overlay/library.properties b/plugins/Kaleidoscope-Colormap-Overlay/library.properties new file mode 100644 index 0000000000..c6a1d8dac0 --- /dev/null +++ b/plugins/Kaleidoscope-Colormap-Overlay/library.properties @@ -0,0 +1,7 @@ +name=Kaleidoscope-Colormap-Overlay +version=0.0.0 +sentence=Per key colors overlaying active LED effect +maintainer=Kaleidoscope's Developers +url=https://github.com/keyboardio/Kaleidoscope +author=Keyboardio +paragraph= diff --git a/plugins/Kaleidoscope-Colormap-Overlay/src/Kaleidoscope-Colormap-Overlay.h b/plugins/Kaleidoscope-Colormap-Overlay/src/Kaleidoscope-Colormap-Overlay.h new file mode 100644 index 0000000000..bc3bbc3b67 --- /dev/null +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/Kaleidoscope-Colormap-Overlay.h @@ -0,0 +1,19 @@ +/* Kaleidoscope-Colormap-Overlay -- A LED plugin for Kaleidoscope. + * Copyright (C) 2017-2018 Keyboard.io, Inc. + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#pragma once + +#include "kaleidoscope/plugin/Colormap-Overlay.h" // IWYU pragma: export diff --git a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp new file mode 100644 index 0000000000..5e66b2626d --- /dev/null +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp @@ -0,0 +1,70 @@ +/* Kaleidoscope-Colormap-Overlay - A LED plugin for Kaleidoscope. + * Copyright (C) 2017-2018 Keyboard.io, Inc. + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "kaleidoscope/plugin/Colormap-Overlay.h" + +#include // for uint8_t + +#include "kaleidoscope/KeyAddr.h" // for KeyAddr, MatrixAddr, MatrixAddr<>::... +#include "kaleidoscope/device/device.h" // for cRGB, CRGB +#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult, EventHandlerRes... +#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 + +namespace kaleidoscope { +namespace plugin { + +bool ColormapOverlay::hasOverlay(KeyAddr k) { + uint8_t layer_index = Layer.lookupActiveLayer(k); + for (uint8_t i{0}; i < overlay_count_; ++i) { + Overlay overlay = overlays_[i]; + if (overlay.addr == k) { + if ((overlay.layer == layer_index) || + (overlay.layer == layer_wildcard)) { + selectedColor = &overlay.color; + return true; + } + } + } + + return false; +} + +EventHandlerResult ColormapOverlay::onSetup() { + return EventHandlerResult::OK; +} + +void ColormapOverlay::setKeyboardLEDColors() { + for (auto key_addr : KeyAddr::all()) { + if (ColormapOverlay::hasOverlay(key_addr)) { + ::LEDControl.setCrgbAt(KeyAddr(key_addr), *selectedColor); + } else { + ::LEDControl.refreshAt(KeyAddr(key_addr)); + } + } +} + +EventHandlerResult ColormapOverlay::afterEachCycle() { + setKeyboardLEDColors(); + + return EventHandlerResult::OK; +} + +} // namespace plugin +} // namespace kaleidoscope + +kaleidoscope::plugin::ColormapOverlay ColormapOverlay; diff --git a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h new file mode 100644 index 0000000000..7dcfc148f1 --- /dev/null +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h @@ -0,0 +1,82 @@ +/* Kaleidoscope-Colormap-Overlay - A LED plugin for Kaleidoscope. + * Copyright (C) 2017-2018 Keyboard.io, Inc. + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#pragma once + +#include // for uint8_t + +#include "kaleidoscope/KeyAddr.h" // for KeyAddr +#include "kaleidoscope/device/device.h" // for cRGB +#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult +#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 + +namespace kaleidoscope { +namespace plugin { + +// Data structure for an individual qukey +struct Overlay { + // The layer this qukey is mapped on. + int8_t layer; + // The keyswitch address of the qukey. + KeyAddr addr; + // The alternake Key value this qukey should use (when held). + cRGB color; + + // This is the constructor that should be used when creating a Overlay that + // will be used by ColormapOverlay + constexpr Overlay(int8_t layer, KeyAddr k, cRGB color) + : layer(layer), addr(k), color(color) {} +}; + +class ColormapOverlay : public kaleidoscope::Plugin { + public: + // Function for defining the array of overlays. It's a template function that + // takes as its sole argument an array reference of size `_overlay_count`, so + // there's no need to use `sizeof` to calculate the correct size, and pass it + // as a separate parameter. + template + void configureOverlays(Overlay const (&overlays)[_overlay_count]) { + overlays_ = overlays; + overlay_count_ = _overlay_count; + } + + // A wildcard value for a qukey that exists on every layer. + static constexpr int8_t layer_wildcard{-1}; + + EventHandlerResult onSetup(); + EventHandlerResult afterEachCycle(); + + private: + Overlay const *overlays_; + uint8_t overlay_count_; + cRGB *selectedColor; + + bool hasOverlay(KeyAddr k); + void setKeyboardLEDColors(); +}; + +} // namespace plugin +} // namespace kaleidoscope + +extern kaleidoscope::plugin::ColormapOverlay ColormapOverlay; + +#define COLORMAP_OVERLAYS(overlays...) \ + { \ + static kaleidoscope::plugin::Overlay const overlays_[] = {overlays}; \ + ColormapOverlay.configureOverlays(overlays_); \ + } From c0798e2ee47d28e703d9a2b8839cafe9c399c979 Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sat, 18 Nov 2023 18:12:30 +0100 Subject: [PATCH 02/10] Have the plugin use the LED palette Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/Colormap-Overlay.cpp | 5 +++-- .../src/kaleidoscope/plugin/Colormap-Overlay.h | 11 ++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp index 5e66b2626d..2f1d77a33a 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp @@ -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 { @@ -35,7 +36,7 @@ bool ColormapOverlay::hasOverlay(KeyAddr k) { if (overlay.addr == k) { if ((overlay.layer == layer_index) || (overlay.layer == layer_wildcard)) { - selectedColor = &overlay.color; + selectedColor = ::LEDPaletteTheme.lookupPaletteColor(overlay.palette_index); return true; } } @@ -51,7 +52,7 @@ EventHandlerResult ColormapOverlay::onSetup() { void ColormapOverlay::setKeyboardLEDColors() { for (auto key_addr : KeyAddr::all()) { if (ColormapOverlay::hasOverlay(key_addr)) { - ::LEDControl.setCrgbAt(KeyAddr(key_addr), *selectedColor); + ::LEDControl.setCrgbAt(KeyAddr(key_addr), selectedColor); } else { ::LEDControl.refreshAt(KeyAddr(key_addr)); } 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 7dcfc148f1..2e9b1413fe 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h @@ -30,17 +30,14 @@ namespace plugin { // Data structure for an individual qukey struct Overlay { - // The layer this qukey is mapped on. int8_t layer; - // The keyswitch address of the qukey. KeyAddr addr; - // The alternake Key value this qukey should use (when held). - cRGB color; + uint8_t palette_index; // This is the constructor that should be used when creating a Overlay that // will be used by ColormapOverlay - constexpr Overlay(int8_t layer, KeyAddr k, cRGB color) - : layer(layer), addr(k), color(color) {} + constexpr Overlay(int8_t layer, KeyAddr k, uint8_t palette_index) + : layer(layer), addr(k), palette_index(palette_index) {} }; class ColormapOverlay : public kaleidoscope::Plugin { @@ -64,7 +61,7 @@ class ColormapOverlay : public kaleidoscope::Plugin { private: Overlay const *overlays_; uint8_t overlay_count_; - cRGB *selectedColor; + cRGB selectedColor; bool hasOverlay(KeyAddr k); void setKeyboardLEDColors(); From 8967f5f8e666ddc7a75681d417e1e7a79b7132bd Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sat, 2 Dec 2023 16:10:06 +0100 Subject: [PATCH 03/10] Need to reserve space in EEPROM Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/Colormap-Overlay.cpp | 5 +++++ .../src/kaleidoscope/plugin/Colormap-Overlay.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp index 2f1d77a33a..590ae6423f 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp @@ -28,6 +28,11 @@ namespace kaleidoscope { namespace plugin { +uint16_t ColormapOverlay::map_base_; + +void ColormapOverlay::setup() { + map_base_ = ::LEDPaletteTheme.reserveThemes(1); +} bool ColormapOverlay::hasOverlay(KeyAddr k) { uint8_t layer_index = Layer.lookupActiveLayer(k); 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 2e9b1413fe..894481112a 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h @@ -42,6 +42,7 @@ struct Overlay { class ColormapOverlay : public kaleidoscope::Plugin { public: + static void setup(); // Function for defining the array of overlays. It's a template function that // takes as its sole argument an array reference of size `_overlay_count`, so // there's no need to use `sizeof` to calculate the correct size, and pass it @@ -59,6 +60,7 @@ class ColormapOverlay : public kaleidoscope::Plugin { EventHandlerResult afterEachCycle(); private: + static uint16_t map_base_; Overlay const *overlays_; uint8_t overlay_count_; cRGB selectedColor; From f899396565b05419dfc8c0318b69a82b37cb0f20 Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sat, 2 Dec 2023 16:11:45 +0100 Subject: [PATCH 04/10] Check if the runtime has leds Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/Colormap-Overlay.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp index 590ae6423f..b4ed22acb9 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp @@ -55,6 +55,9 @@ EventHandlerResult ColormapOverlay::onSetup() { } void ColormapOverlay::setKeyboardLEDColors() { + if (!Runtime.has_leds) + return; + for (auto key_addr : KeyAddr::all()) { if (ColormapOverlay::hasOverlay(key_addr)) { ::LEDControl.setCrgbAt(KeyAddr(key_addr), selectedColor); From bf63855efff78b3f94c784445a379e08ca6b416b Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sat, 2 Dec 2023 17:43:05 +0100 Subject: [PATCH 05/10] Update README Signed-off-by: Evy Bongers --- .../Kaleidoscope-Colormap-Overlay/README.md | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/plugins/Kaleidoscope-Colormap-Overlay/README.md b/plugins/Kaleidoscope-Colormap-Overlay/README.md index b9913e27d2..f28ce13b25 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/README.md +++ b/plugins/Kaleidoscope-Colormap-Overlay/README.md @@ -1,7 +1,19 @@ # Colormap-Overlay The `Colormap-Overlay` extension provides an easier way to apply color to -specific keys and layers, regardless of the active LED mode. +specific keys and layers, regardless of the active LED mode. Colors are picked +from a 16-color palette, provided by the [LED-Palette-Theme][plugin:l-p-t] +plugin. The color map is stored in `EEPROM`, and can be easily changed via the +[FocusSerial][plugin:focusserial] plugin, which also provides palette editing +capabilities. + + [plugin:focusserial]: Kaleidoscope-FocusSerial.md + [plugin:l-p-t]: Kaleidoscope-LED-Palette-Theme.md + +It is also possible to set up a default palette and colormap, using the +`DefaultColormap` plugin, provided by the [Colormap][plugin:colormap] package. + + [plugin:colormap]: Kaleidoscope-Colormap.md ## Using the extension @@ -12,24 +24,37 @@ for both the palette, and the colormap. ```c++ #include #include +#include +#include // DefaultColorMap #include -KALEIDOSCOPE_INIT_PLUGINS(LEDControl, - ColormapOverlay); +PALETTE( + /* A list of 16 cRGB colors... */ +) + +KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings, + LEDControl, + ColormapOverlay, + DefaultColormap); void setup() { Kaleidoscope.setup(); COLORMAP_OVERLAYS( - // Make the any key red - kaleidoscope::plugin::Overlay(0, KeyAddr(0, 9), CRGB(0xff, 0x00, 0x00)), - // Disable leds on the palm keys - kaleidoscope::plugin::Overlay(0, KeyAddr(3, 6), CRGB(0x00, 0x00, 0x00)), - kaleidoscope::plugin::Overlay(0, KeyAddr(3, 9), CRGB(0x00, 0x00, 0x00)), + // List of overlays, using kaleidoscope::plugin::Overlay + // kaleidoscope::plugin::Overlay({layer}, {key address}, {palette index}) ) + + ColormapOverlay.setup(); + DefaultColormap.setup(); } ``` ## Plugin methods -TODO +The extension only has a single method: + +### `.setup()` + +> Intended to be called from the `setup()` method of the sketch, it reserves the +> required space in EEPROM. From 3529b68a0b43d001f8df94c9c40602212ef755c1 Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sat, 2 Dec 2023 17:43:20 +0100 Subject: [PATCH 06/10] Add example sketch Signed-off-by: Evy Bongers --- .../Colormap-Overlay/Colormap-Overlay.ino | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 plugins/Kaleidoscope-Colormap-Overlay/examples/Colormap-Overlay/Colormap-Overlay.ino diff --git a/plugins/Kaleidoscope-Colormap-Overlay/examples/Colormap-Overlay/Colormap-Overlay.ino b/plugins/Kaleidoscope-Colormap-Overlay/examples/Colormap-Overlay/Colormap-Overlay.ino new file mode 100644 index 0000000000..284da7706c --- /dev/null +++ b/plugins/Kaleidoscope-Colormap-Overlay/examples/Colormap-Overlay/Colormap-Overlay.ino @@ -0,0 +1,112 @@ +// -*- mode: c++ -*- +/* Kaleidoscope - Firmware for computer input devices + * Copyright (C) 2017-2020 Bart Nagel + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include +#include +#include +#include // DefaultColorMap +#include + +// clang-format off + +KEYMAPS( + [0] = KEYMAP_STACKED + (XXX, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext, + Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, + Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, + Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape, + + Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, + XXX, + + XXX, Key_6, Key_7, Key_8, Key_9, Key_0, XXX, + Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, + Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, + Key_RightAlt, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, + + Key_RightShift, Key_LeftAlt, Key_Spacebar, Key_RightControl, + XXX) +) // KEYMAPS( + +// clang-format on + +enum { + PALETTE_RED, + PALETTE_GREEN, + PALETTE_BLUE, + PALETTE_BLACK, + PALETTE_UNUSED_1, + PALETTE_UNUSED_2, + PALETTE_UNUSED_3, + PALETTE_UNUSED_4, + PALETTE_UNUSED_5, + PALETTE_UNUSED_6, + PALETTE_UNUSED_7, + PALETTE_UNUSED_8, + PALETTE_UNUSED_9, + PALETTE_UNUSED_10, + PALETTE_UNUSED_11, + PALETTE_UNUSED_12, +}; + +PALETTE( + [PALETTE_RED] = CRGB(0xff, 0x00, 0x00), + [PALETTE_GREEN] = CRGB(0x00, 0xff, 0x00), + [PALETTE_YELLOW] = CRGB(0x00, 0x00, 0xff), + [PALETTE_BLACK] = CRGB(0x00, 0x00, 0x00), + // unused + [PALETTE_UNUSED_1] = CRGB(0x00, 0x00, 0x00), + [PALETTE_UNUSED_2] = CRGB(0x00, 0x00, 0x00), + [PALETTE_UNUSED_3] = CRGB(0x00, 0x00, 0x00), + [PALETTE_UNUSED_4] = CRGB(0x00, 0x00, 0x00), + [PALETTE_UNUSED_5] = CRGB(0x00, 0x00, 0x00), + [PALETTE_UNUSED_6] = CRGB(0x00, 0x00, 0x00), + [PALETTE_UNUSED_7] = CRGB(0x00, 0x00, 0x00), + [PALETTE_UNUSED_8] = CRGB(0x00, 0x00, 0x00), + [PALETTE_UNUSED_9] = CRGB(0x00, 0x00, 0x00), + [PALETTE_UNUSED_10] = CRGB(0x00, 0x00, 0x00), + [PALETTE_UNUSED_11] = CRGB(0x00, 0x00, 0x00), + [PALETTE_UNUSED_12] = CRGB(0x00, 0x00, 0x00) +) + +KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings, + LEDControl, + ColormapOverlay, + DefaultColormap); + +void setup() { + Kaleidoscope.setup(); + + COLORMAP_OVERLAYS( + // Make the any key green + kaleidoscope::plugin::Overlay(0, KeyAddr(0, 9), PALETTE_GREEN), + // Make numlock red + kaleidoscope::plugin::Overlay(0, KeyAddr(0, 15), PALETTE_RED), + // Make escape yellow + kaleidoscope::plugin::Overlay(0, KeyAddr(2, 6), PALETTE_YELLOW), + // Disable leds on the palm keys + kaleidoscope::plugin::Overlay(0, KeyAddr(3, 6), PALETTE_BLACK), + kaleidoscope::plugin::Overlay(0, KeyAddr(3, 9), PALETTE_BLACK), + ) + + ColormapOverlay.setup(); + DefaultColormap.setup(); +} + +void loop() { + Kaleidoscope.loop(); +} From b8a0ab4edc7f54fcca5176b711b6bf05da6d8439 Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sat, 2 Dec 2023 20:48:47 +0100 Subject: [PATCH 07/10] Code style Signed-off-by: Evy Bongers --- .../examples/Colormap-Overlay/Colormap-Overlay.ino | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/Kaleidoscope-Colormap-Overlay/examples/Colormap-Overlay/Colormap-Overlay.ino b/plugins/Kaleidoscope-Colormap-Overlay/examples/Colormap-Overlay/Colormap-Overlay.ino index 284da7706c..bb1c521175 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/examples/Colormap-Overlay/Colormap-Overlay.ino +++ b/plugins/Kaleidoscope-Colormap-Overlay/examples/Colormap-Overlay/Colormap-Overlay.ino @@ -80,8 +80,7 @@ PALETTE( [PALETTE_UNUSED_9] = CRGB(0x00, 0x00, 0x00), [PALETTE_UNUSED_10] = CRGB(0x00, 0x00, 0x00), [PALETTE_UNUSED_11] = CRGB(0x00, 0x00, 0x00), - [PALETTE_UNUSED_12] = CRGB(0x00, 0x00, 0x00) -) + [PALETTE_UNUSED_12] = CRGB(0x00, 0x00, 0x00)) KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings, LEDControl, @@ -100,8 +99,7 @@ void setup() { kaleidoscope::plugin::Overlay(0, KeyAddr(2, 6), PALETTE_YELLOW), // Disable leds on the palm keys kaleidoscope::plugin::Overlay(0, KeyAddr(3, 6), PALETTE_BLACK), - kaleidoscope::plugin::Overlay(0, KeyAddr(3, 9), PALETTE_BLACK), - ) + kaleidoscope::plugin::Overlay(0, KeyAddr(3, 9), PALETTE_BLACK)) ColormapOverlay.setup(); DefaultColormap.setup(); From 78989d746e7fb7a0547763de2a5f2b9c108a6e27 Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Tue, 26 Dec 2023 16:25:56 +0100 Subject: [PATCH 08/10] Use beforeSyncingLeds hook for overriding LED colors --- .../src/kaleidoscope/plugin/Colormap-Overlay.cpp | 2 +- .../src/kaleidoscope/plugin/Colormap-Overlay.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp index b4ed22acb9..b41f3679ba 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp @@ -67,7 +67,7 @@ void ColormapOverlay::setKeyboardLEDColors() { } } -EventHandlerResult ColormapOverlay::afterEachCycle() { +EventHandlerResult ColormapOverlay::beforeSyncingLeds() { setKeyboardLEDColors(); return EventHandlerResult::OK; 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 894481112a..9acb162aed 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h @@ -57,7 +57,7 @@ class ColormapOverlay : public kaleidoscope::Plugin { static constexpr int8_t layer_wildcard{-1}; EventHandlerResult onSetup(); - EventHandlerResult afterEachCycle(); + EventHandlerResult beforeSyncingLeds(); private: static uint16_t map_base_; From 1036f14a247d729235369d4d824642b1a7105c59 Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Tue, 26 Dec 2023 16:28:16 +0100 Subject: [PATCH 09/10] Improve method name --- .../src/kaleidoscope/plugin/Colormap-Overlay.cpp | 4 ++-- .../src/kaleidoscope/plugin/Colormap-Overlay.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp index b41f3679ba..d0cda221f4 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp @@ -54,7 +54,7 @@ EventHandlerResult ColormapOverlay::onSetup() { return EventHandlerResult::OK; } -void ColormapOverlay::setKeyboardLEDColors() { +void ColormapOverlay::setLEDOverlayColors() { if (!Runtime.has_leds) return; @@ -68,7 +68,7 @@ void ColormapOverlay::setKeyboardLEDColors() { } EventHandlerResult ColormapOverlay::beforeSyncingLeds() { - setKeyboardLEDColors(); + setLEDOverlayColors(); return EventHandlerResult::OK; } 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 9acb162aed..949eaaf9d5 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h +++ b/plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h @@ -66,7 +66,7 @@ class ColormapOverlay : public kaleidoscope::Plugin { cRGB selectedColor; bool hasOverlay(KeyAddr k); - void setKeyboardLEDColors(); + void setLEDOverlayColors(); }; } // namespace plugin From e1ce814fa66c8d0f4897f7b488d6afc84a82f03d Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sun, 10 Dec 2023 12:05:26 +0100 Subject: [PATCH 10/10] Update README --- .../Kaleidoscope-Colormap-Overlay/README.md | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/plugins/Kaleidoscope-Colormap-Overlay/README.md b/plugins/Kaleidoscope-Colormap-Overlay/README.md index f28ce13b25..8585344891 100644 --- a/plugins/Kaleidoscope-Colormap-Overlay/README.md +++ b/plugins/Kaleidoscope-Colormap-Overlay/README.md @@ -1,25 +1,37 @@ # Colormap-Overlay -The `Colormap-Overlay` extension provides an easier way to apply color to -specific keys and layers, regardless of the active LED mode. Colors are picked -from a 16-color palette, provided by the [LED-Palette-Theme][plugin:l-p-t] -plugin. The color map is stored in `EEPROM`, and can be easily changed via the -[FocusSerial][plugin:focusserial] plugin, which also provides palette editing -capabilities. +The `ColormapOverlay` extension provides an easier way to apply color to +specific combinations of keys and layers, regardless of the active LED mode. +Colors are picked from a 16-color palette, provided by the +[LED-Palette-Theme][plugin:l-p-t] plugin. The overlays are stored in `EEPROM`, +and can be easily changed via the [FocusSerial][plugin:focusserial] plugin, +which also provides palette editing capabilities. [plugin:focusserial]: Kaleidoscope-FocusSerial.md [plugin:l-p-t]: Kaleidoscope-LED-Palette-Theme.md -It is also possible to set up a default palette and colormap, using the -`DefaultColormap` plugin, provided by the [Colormap][plugin:colormap] package. +It is also possible to set up a default palette and overrides, using the +`PALETTE` macro provided by the LED-Palette-Theme package and the +`COLORMAP_OVERLAYS` provided by this package. See below for its documentation. - [plugin:colormap]: Kaleidoscope-Colormap.md ## Using the extension -To use the extension, include the header, tell it the number of layers you have, -register the `Focus` hooks, and it will do the rest. We'll also set up a default -for both the palette, and the colormap. +To use the extension, include the headers and, optionally, register the `Focus` +hooks. Use the macros mentioned above to set up a default for both the palette +and colormap overlays. Note that layers and key addresses are all zero-indexed, +and key addresses rows are top to bottom and columns are left to right. For the +key coordinates refer to the relevant header file: + +- [Model 01][Model01.h] +- [Model 100][Model100.h] +- [Atreus][Atreus2.h] +- [Imago][Imago.h] + + [Model01.h]: https://github.com/keyboardio/Kaleidoscope/blob/master/plugins/Kaleidoscope-Hardware-Keyboardio-Model01/src/kaleidoscope/device/keyboardio/Model01.h#L153 + [Model100.h]: https://github.com/keyboardio/Kaleidoscope/blob/master/plugins/Kaleidoscope-Hardware-Keyboardio-Model100/src/kaleidoscope/device/keyboardio/Model100.h#L175 + [Atreus2.h]: https://github.com/keyboardio/Kaleidoscope/blob/master/plugins/Kaleidoscope-Hardware-Keyboardio-Atreus/src/kaleidoscope/device/keyboardio/Atreus2.h#66 + [Imago.h]: https://github.com/keyboardio/Kaleidoscope/blob/master/plugins/Kaleidoscope-Hardware-Keyboardio-Imago/src/kaleidoscope/device/keyboardio/Imago.h#116 ```c++ #include @@ -27,6 +39,7 @@ for both the palette, and the colormap. #include #include // DefaultColorMap #include +#include PALETTE( /* A list of 16 cRGB colors... */ @@ -35,7 +48,8 @@ PALETTE( KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings, LEDControl, ColormapOverlay, - DefaultColormap); + DefaultColormap, + Focus); void setup() { Kaleidoscope.setup(); @@ -43,6 +57,8 @@ void setup() { COLORMAP_OVERLAYS( // List of overlays, using kaleidoscope::plugin::Overlay // kaleidoscope::plugin::Overlay({layer}, {key address}, {palette index}) + // A special value `ColormapOverlay::layer_wildcard` can be used in place of + // a layer number to apply the color overlay on all layers ) ColormapOverlay.setup(); @@ -50,6 +66,7 @@ void setup() { } ``` + ## Plugin methods The extension only has a single method: