From 043bc5a55a35b5de79a82d6675bdbf20f12f6452 Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Sun, 10 Dec 2023 12:19:16 +0100 Subject: [PATCH] Move palette logic to Kaleidoscope-LED-Palette-Theme Signed-off-by: Evy Bongers --- .../kaleidoscope/plugin/DefaultColormap.cpp | 27 +++------ .../src/kaleidoscope/plugin/DefaultColormap.h | 17 ------ .../src/Kaleidoscope-LED-Palette-Theme.h | 1 + .../kaleidoscope/plugin/DefaultPalette.cpp | 48 +++++++++++++++ .../src/kaleidoscope/plugin/DefaultPalette.h | 59 +++++++++++++++++++ 5 files changed, 115 insertions(+), 37 deletions(-) create mode 100644 plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.cpp create mode 100644 plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h diff --git a/plugins/Kaleidoscope-Colormap/src/kaleidoscope/plugin/DefaultColormap.cpp b/plugins/Kaleidoscope-Colormap/src/kaleidoscope/plugin/DefaultColormap.cpp index 2fd7f93fdd..16bb48a8ae 100644 --- a/plugins/Kaleidoscope-Colormap/src/kaleidoscope/plugin/DefaultColormap.cpp +++ b/plugins/Kaleidoscope-Colormap/src/kaleidoscope/plugin/DefaultColormap.cpp @@ -18,21 +18,18 @@ #include "kaleidoscope/plugin/Colormap.h" // for Colormap #include "kaleidoscope/plugin/DefaultColormap.h" -#include // for F, PSTR, __FlashStringHelper -#include // for Focus, FocusSerial -#include // for LEDControl -#include // for LEDPaletteTheme -#include // for uint8_t, uint16_t +#include // for PSTR +#include // for Focus +#include // for LEDControl +#include // for uint8_t -#include "kaleidoscope/KeyAddr.h" // for KeyAddr -#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ +#include "kaleidoscope/Runtime.h" // for Runtime +#include "kaleidoscope/plugin/DefaultPalette.h" namespace kaleidoscope { namespace plugin { namespace defaultcolormap { -__attribute__((weak)) extern const cRGB palette[] = {}; -__attribute__((weak)) extern bool palette_defined = false; __attribute__((weak)) extern const uint8_t colormaps[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns] = {}; __attribute__((weak)) extern uint8_t colormap_layers = 0; } // namespace defaultcolormap @@ -46,17 +43,7 @@ void DefaultColormap::setup() { } void DefaultColormap::install() { - if (!defaultcolormap::palette_defined) return; - - for (uint8_t i = 0; i < 16; i++) { - cRGB color; - - color.r = pgm_read_byte(&(defaultcolormap::palette[i].r)); - color.g = pgm_read_byte(&(defaultcolormap::palette[i].g)); - color.b = pgm_read_byte(&(defaultcolormap::palette[i].b)); - - ::LEDPaletteTheme.updatePaletteColor(i, color); - } + DefaultPalette::setup(); if (defaultcolormap::colormap_layers == 0) return; diff --git a/plugins/Kaleidoscope-Colormap/src/kaleidoscope/plugin/DefaultColormap.h b/plugins/Kaleidoscope-Colormap/src/kaleidoscope/plugin/DefaultColormap.h index 958c778f39..1403153b35 100644 --- a/plugins/Kaleidoscope-Colormap/src/kaleidoscope/plugin/DefaultColormap.h +++ b/plugins/Kaleidoscope-Colormap/src/kaleidoscope/plugin/DefaultColormap.h @@ -21,7 +21,6 @@ #include // for uint8_t #include "kaleidoscope_internal/device.h" // for device -#include "kaleidoscope/device/device.h" // for cRGB #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/plugin.h" // for Plugin @@ -59,25 +58,9 @@ namespace plugin { } #endif -#define PALETTE(p0, p1, p2, p3, p4, p5, p6, p7, \ - p8, p9, pa, pb, pc, pd, pe, pf) \ - namespace kaleidoscope { \ - namespace plugin { \ - namespace defaultcolormap { \ - const cRGB palette[] PROGMEM = { \ - p0, p1, p2, p3, p4, p5, p6, p7, \ - p8, p9, pa, pb, pc, pd, pe, pf \ - }; \ - bool palette_defined = true; \ - } /* defaultcolormap */ \ - } /* plugin */ \ - } /* kaleidoscope */ - // clang-format on namespace defaultcolormap { -extern bool palette_defined; -extern const cRGB palette[]; extern const uint8_t colormaps[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns]; extern uint8_t colormap_layers; } // namespace defaultcolormap diff --git a/plugins/Kaleidoscope-LED-Palette-Theme/src/Kaleidoscope-LED-Palette-Theme.h b/plugins/Kaleidoscope-LED-Palette-Theme/src/Kaleidoscope-LED-Palette-Theme.h index 5ce35f2edb..387caf504a 100644 --- a/plugins/Kaleidoscope-LED-Palette-Theme/src/Kaleidoscope-LED-Palette-Theme.h +++ b/plugins/Kaleidoscope-LED-Palette-Theme/src/Kaleidoscope-LED-Palette-Theme.h @@ -18,3 +18,4 @@ #pragma once #include "kaleidoscope/plugin/LED-Palette-Theme.h" // IWYU pragma: export +#include "kaleidoscope/plugin/DefaultPalette.h" // IWYU pragma: export diff --git a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.cpp b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.cpp new file mode 100644 index 0000000000..02ab271fff --- /dev/null +++ b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.cpp @@ -0,0 +1,48 @@ +/* -*- mode: c++ -*- + * Kaleidoscope-Colormap -- Per-layer colormap effect + * Copyright (C) 2022 Keyboard.io, Inc + * + * This program is free software: you can redistribute it and/or modify it under 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 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 along with + * this program. If not, see . + */ + +#include "kaleidoscope/plugin/DefaultPalette.h" +#include "kaleidoscope/plugin/LED-Palette-Theme.h" // for LEDPaletteTheme + +#include // for uint8_t + +namespace kaleidoscope { +namespace plugin { + +namespace ledpalette { +__attribute__((weak)) extern const cRGB palette[] = {}; +__attribute__((weak)) extern bool palette_defined = false; +} // namespace ledpalette + +void DefaultPalette::setup() { + if (!ledpalette::palette_defined) return; + + for (uint8_t i = 0; i < 16; i++) { + cRGB color; + + color.r = pgm_read_byte(&(ledpalette::palette[i].r)); + color.g = pgm_read_byte(&(ledpalette::palette[i].g)); + color.b = pgm_read_byte(&(ledpalette::palette[i].b)); + + ::LEDPaletteTheme.updatePaletteColor(i, color); + } +} + +} // namespace plugin +} // namespace kaleidoscope + +kaleidoscope::plugin::DefaultPalette DefaultPalette; diff --git a/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h new file mode 100644 index 0000000000..622b713d11 --- /dev/null +++ b/plugins/Kaleidoscope-LED-Palette-Theme/src/kaleidoscope/plugin/DefaultPalette.h @@ -0,0 +1,59 @@ +/* -*- mode: c++ -*- + * Kaleidoscope-Colormap -- Per-layer colormap effect + * Copyright (C) 2022 Keyboard.io, Inc + * + * This program is free software: you can redistribute it and/or modify it under 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 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 along with + * this program. If not, see . + */ + +#pragma once + +#include // for PROGMEM + +#include "kaleidoscope/device/device.h" // for cRGB +#include "kaleidoscope/plugin.h" // for Plugin + +namespace kaleidoscope { +namespace plugin { + +namespace ledpalette { +extern bool palette_defined; +extern const cRGB palette[]; +} // namespace ledpalette + +class DefaultPalette : public Plugin { + public: + static void setup(); +}; + +} // namespace plugin +} // namespace kaleidoscope + +// clang-format off + +#define PALETTE(p0, p1, p2, p3, p4, p5, p6, p7, \ + p8, p9, pa, pb, pc, pd, pe, pf) \ + 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 \ + }; \ + bool palette_defined = true; \ + } /* defaultcolormap */ \ + } /* plugin */ \ + } /* kaleidoscope */ + +// clang-format on + +extern kaleidoscope::plugin::DefaultPalette DefaultPalette;