From 74ae4c5c7a79ab77674c9f09fa3f02ce12d5381f Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Tue, 14 Nov 2023 15:23:53 +0100 Subject: [PATCH] Migrate and rename --- .../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_); \ + }