From bb6f5e8188e7710b0574df6e17dd2284b22059f8 Mon Sep 17 00:00:00 2001 From: Florian Fleissner Date: Thu, 16 Jan 2020 12:00:38 +0100 Subject: [PATCH] Added remote call capabilities for some LED-Palette-Theme features Signed-off-by: Florian Fleissner --- src/kaleidoscope/plugin/LED-Palette-Theme.cpp | 7 ++++ src/kaleidoscope/plugin/LED-Palette-Theme.h | 37 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/kaleidoscope/plugin/LED-Palette-Theme.cpp b/src/kaleidoscope/plugin/LED-Palette-Theme.cpp index cbeffb5920..d4c2dc87bb 100644 --- a/src/kaleidoscope/plugin/LED-Palette-Theme.cpp +++ b/src/kaleidoscope/plugin/LED-Palette-Theme.cpp @@ -84,6 +84,13 @@ const cRGB LEDPaletteTheme::lookupPaletteColor(uint8_t color_index) { return color; } +void LEDPaletteTheme::setPaletteColor(uint8_t palette_index, cRGB color) { + color.r ^= 0xff; + color.g ^= 0xff; + color.b ^= 0xff; + Runtime.storage().put(palette_base_ + palette_index * sizeof(color), color); +} + void LEDPaletteTheme::updateColorIndexAtPosition(uint16_t map_base, uint16_t position, uint8_t color_index) { uint8_t indexes; diff --git a/src/kaleidoscope/plugin/LED-Palette-Theme.h b/src/kaleidoscope/plugin/LED-Palette-Theme.h index 54f45c452a..c4c240329b 100644 --- a/src/kaleidoscope/plugin/LED-Palette-Theme.h +++ b/src/kaleidoscope/plugin/LED-Palette-Theme.h @@ -19,6 +19,7 @@ #include "kaleidoscope/Runtime.h" #include +#include "kaleidoscope/remote_call.h" namespace kaleidoscope { namespace plugin { @@ -39,6 +40,7 @@ class LEDPaletteTheme : public kaleidoscope::Plugin { static void updateColorIndexAtPosition(uint16_t theme_base, uint16_t position, uint8_t color_index); static const cRGB lookupPaletteColor(uint8_t palette_index); + static void setPaletteColor(uint8_t palette_index, cRGB color); EventHandlerResult onFocusEvent(const char *command); EventHandlerResult themeFocusEvent(const char *command, @@ -53,3 +55,38 @@ class LEDPaletteTheme : public kaleidoscope::Plugin { } extern kaleidoscope::plugin::LEDPaletteTheme LEDPaletteTheme; + +KALEIDOSCOPE_REMOTE_CALL( + KRC_ROOT_PACKAGE(plugin, + KRC_PACKAGE(LEDPaletteTheme, + KRC_F(getPaletteColor, + ((uint8_t, red), (uint8_t, green), (uint8_t, blue)), + ((uint8_t, palette_index)), + ( + cRGB color; + color = LEDPaletteTheme.lookupPaletteColor(args->palette_index); + results->red = color.r; + results->green = color.g; + results->blue = color.b; + ), + KRC_DESCRIPTION("Retrieves the RGB value of a palette color") + ) + KRC_F(setPaletteColor, KRC_NO_RESULTS, + ((uint8_t, palette_index), (uint8_t, red), (uint8_t, green), (uint8_t, blue)), + ( + LEDPaletteTheme.setPaletteColor(args->palette_index, + cRGB{args->red, args->green, args->blue}); + ), + KRC_DESCRIPTION("Sets the RGB value of a palette color") + ) + KRC_F(commitPalette, KRC_NO_RESULTS, KRC_NO_ARGS, + ( + Runtime.storage().commit(); + ::LEDControl.refreshAll(); + ), + KRC_DESCRIPTION("Sets the RGB value of a palette color") + ) + ) + ) +) +