From d6178906ebe5062da6f91649c6d5cc92b7a08554 Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Wed, 13 Mar 2024 21:08:09 +0100 Subject: [PATCH] Add focus command for retreiving a list of installed LED effects (#1387) * Implement focus command `led.modes` for querying LED modes Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/Colormap.h | 3 +++ .../src/kaleidoscope/plugin/FingerPainter.h | 3 +++ .../src/kaleidoscope/plugin/FocusSerial.cpp | 19 +++++++++++----- .../src/kaleidoscope/plugin/FocusSerial.h | 2 +- .../src/kaleidoscope/plugin/Heatmap.h | 3 +++ .../plugin/LED-ActiveLayerColor.h | 3 +++ .../kaleidoscope/plugin/LED-ActiveLayerKeys.h | 3 +++ .../plugin/LED-AlphaSquare/Effect.h | 3 +++ .../src/kaleidoscope/plugin/LED-Stalker.h | 3 +++ .../src/kaleidoscope/plugin/LED-Wavepool.h | 3 +++ .../plugin/LEDBrightnessConfig.cpp | 2 +- .../kaleidoscope/plugin/LEDEffect-Breathe.h | 3 +++ .../src/kaleidoscope/plugin/LEDEffect-Chase.h | 3 +++ .../plugin/LEDEffect-DigitalRain.h | 3 ++- .../kaleidoscope/plugin/LEDEffect-Rainbow.h | 6 +++++ .../plugin/LEDEffect-SolidColor.h | 9 +++++++- .../src/kaleidoscope/plugin/Jukebox.cpp | 6 +++-- .../src/kaleidoscope/plugin/Miami.cpp | 3 ++- .../src/kaleidoscope/plugin/TriColor.cpp | 9 ++++---- .../src/kaleidoscope/plugin/TriColor.h | 8 +++++-- src/kaleidoscope/event_handlers.h | 18 +++++++++++++++ src/kaleidoscope/plugin/LEDControl/LED-Off.h | 5 +++-- src/kaleidoscope/plugin/LEDModeInterface.h | 22 +++++++++++++++++++ 23 files changed, 122 insertions(+), 20 deletions(-) diff --git a/plugins/Kaleidoscope-Colormap/src/kaleidoscope/plugin/Colormap.h b/plugins/Kaleidoscope-Colormap/src/kaleidoscope/plugin/Colormap.h index 0b2869c9e6..89a5868404 100644 --- a/plugins/Kaleidoscope-Colormap/src/kaleidoscope/plugin/Colormap.h +++ b/plugins/Kaleidoscope-Colormap/src/kaleidoscope/plugin/Colormap.h @@ -32,6 +32,9 @@ class ColormapEffect : public Plugin, public LEDModeInterface, public AccessTransientLEDMode { public: + ColormapEffect() { led_mode_name_ = "Colormap"; } + explicit ColormapEffect(const char *led_mode_name) { led_mode_name_ = led_mode_name; } + void max_layers(uint8_t max_); EventHandlerResult onLayerChange(); diff --git a/plugins/Kaleidoscope-FingerPainter/src/kaleidoscope/plugin/FingerPainter.h b/plugins/Kaleidoscope-FingerPainter/src/kaleidoscope/plugin/FingerPainter.h index fc287a974d..98e89b0ebe 100644 --- a/plugins/Kaleidoscope-FingerPainter/src/kaleidoscope/plugin/FingerPainter.h +++ b/plugins/Kaleidoscope-FingerPainter/src/kaleidoscope/plugin/FingerPainter.h @@ -33,6 +33,9 @@ namespace plugin { // class FingerPainter : public LEDMode { public: + FingerPainter() { led_mode_name_ = "FingerPainter"; } + explicit FingerPainter(const char *led_mode_name) { led_mode_name_ = led_mode_name; } + void toggle(); EventHandlerResult onKeyEvent(KeyEvent &event); diff --git a/plugins/Kaleidoscope-FocusSerial/src/kaleidoscope/plugin/FocusSerial.cpp b/plugins/Kaleidoscope-FocusSerial/src/kaleidoscope/plugin/FocusSerial.cpp index 19d3f1b2d9..9443d8b8ff 100644 --- a/plugins/Kaleidoscope-FocusSerial/src/kaleidoscope/plugin/FocusSerial.cpp +++ b/plugins/Kaleidoscope-FocusSerial/src/kaleidoscope/plugin/FocusSerial.cpp @@ -17,7 +17,7 @@ #include "kaleidoscope/plugin/FocusSerial.h" -#include // for PSTR, __FlashStringHelper, F, strcmp_P +#include // for PSTR, F, strcmp_P #include // for HardwareSerial #include // for memset @@ -77,18 +77,27 @@ EventHandlerResult FocusSerial::afterEachCycle() { return EventHandlerResult::OK; } +void sendLedModeCallback_(const char *name) { + Runtime.serialPort().println(name); +} + EventHandlerResult FocusSerial::onFocusEvent(const char *input) { - const char *cmd_help = PSTR("help"); - const char *cmd_reset = PSTR("device.reset"); - const char *cmd_plugins = PSTR("plugins"); + const char *cmd_help = PSTR("help"); + const char *cmd_reset = PSTR("device.reset"); + const char *cmd_led_modes = PSTR("led.modes"); + const char *cmd_plugins = PSTR("plugins"); if (inputMatchesHelp(input)) - return printHelp(cmd_help, cmd_reset, cmd_plugins); + return printHelp(cmd_help, cmd_reset, cmd_led_modes, cmd_plugins); if (inputMatchesCommand(input, cmd_reset)) { Runtime.device().rebootBootloader(); return EventHandlerResult::EVENT_CONSUMED; } + if (inputMatchesCommand(input, cmd_led_modes)) { + kaleidoscope::Hooks::onLedEffectQuery(sendLedModeCallback_); + return EventHandlerResult::EVENT_CONSUMED; + } if (inputMatchesCommand(input, cmd_plugins)) { kaleidoscope::Hooks::onNameQuery(); return EventHandlerResult::EVENT_CONSUMED; diff --git a/plugins/Kaleidoscope-FocusSerial/src/kaleidoscope/plugin/FocusSerial.h b/plugins/Kaleidoscope-FocusSerial/src/kaleidoscope/plugin/FocusSerial.h index 7b2633773b..ab0b956b01 100644 --- a/plugins/Kaleidoscope-FocusSerial/src/kaleidoscope/plugin/FocusSerial.h +++ b/plugins/Kaleidoscope-FocusSerial/src/kaleidoscope/plugin/FocusSerial.h @@ -17,7 +17,7 @@ #pragma once -#include // for delayMicroseconds +#include // for __FlashStringHelper, delayMicroseconds #include // for HardwareSerial #include // for uint8_t, uint16_t diff --git a/plugins/Kaleidoscope-Heatmap/src/kaleidoscope/plugin/Heatmap.h b/plugins/Kaleidoscope-Heatmap/src/kaleidoscope/plugin/Heatmap.h index 7f3f90a691..9ef450db12 100644 --- a/plugins/Kaleidoscope-Heatmap/src/kaleidoscope/plugin/Heatmap.h +++ b/plugins/Kaleidoscope-Heatmap/src/kaleidoscope/plugin/Heatmap.h @@ -34,6 +34,9 @@ class Heatmap : public Plugin, public LEDModeInterface, public AccessTransientLEDMode { public: + Heatmap() { led_mode_name_ = "Heatmap"; } + explicit Heatmap(const char *led_mode_name) { led_mode_name_ = led_mode_name; } + static uint16_t update_delay; static const cRGB *heat_colors; static uint8_t heat_colors_length; diff --git a/plugins/Kaleidoscope-LED-ActiveLayerColor/src/kaleidoscope/plugin/LED-ActiveLayerColor.h b/plugins/Kaleidoscope-LED-ActiveLayerColor/src/kaleidoscope/plugin/LED-ActiveLayerColor.h index 9ef51cbce7..88189a16c1 100644 --- a/plugins/Kaleidoscope-LED-ActiveLayerColor/src/kaleidoscope/plugin/LED-ActiveLayerColor.h +++ b/plugins/Kaleidoscope-LED-ActiveLayerColor/src/kaleidoscope/plugin/LED-ActiveLayerColor.h @@ -31,6 +31,9 @@ class LEDActiveLayerColorEffect : public Plugin, public LEDModeInterface, public AccessTransientLEDMode { public: + LEDActiveLayerColorEffect() { led_mode_name_ = "ActiveLayerColor"; } + explicit LEDActiveLayerColorEffect(const char *led_mode_name) { led_mode_name_ = led_mode_name; } + EventHandlerResult onLayerChange(); void setColormap(const cRGB colormap[]); diff --git a/plugins/Kaleidoscope-LED-ActiveLayerKeys/src/kaleidoscope/plugin/LED-ActiveLayerKeys.h b/plugins/Kaleidoscope-LED-ActiveLayerKeys/src/kaleidoscope/plugin/LED-ActiveLayerKeys.h index 1672ecbc8d..9e27e7b601 100644 --- a/plugins/Kaleidoscope-LED-ActiveLayerKeys/src/kaleidoscope/plugin/LED-ActiveLayerKeys.h +++ b/plugins/Kaleidoscope-LED-ActiveLayerKeys/src/kaleidoscope/plugin/LED-ActiveLayerKeys.h @@ -31,6 +31,9 @@ class LEDActiveLayerKeysEffect : public Plugin, public LEDModeInterface, public AccessTransientLEDMode { public: + LEDActiveLayerKeysEffect() { led_mode_name_ = "ActiveLayerKeys"; } + explicit LEDActiveLayerKeysEffect(const char *led_mode_name) { led_mode_name_ = led_mode_name; } + EventHandlerResult onLayerChange(); template void setColormap(cRGB const (&colormap)[_colormap_size]) { diff --git a/plugins/Kaleidoscope-LED-AlphaSquare/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.h b/plugins/Kaleidoscope-LED-AlphaSquare/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.h index 0857a976f7..e64fba7a57 100644 --- a/plugins/Kaleidoscope-LED-AlphaSquare/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.h +++ b/plugins/Kaleidoscope-LED-AlphaSquare/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.h @@ -34,6 +34,9 @@ class AlphaSquareEffect : public Plugin, public LEDModeInterface, public AccessTransientLEDMode { public: + AlphaSquareEffect() { led_mode_name_ = "AlphaSquare"; } + explicit AlphaSquareEffect(const char *led_mode_name) { led_mode_name_ = led_mode_name; } + static uint16_t length; EventHandlerResult onKeyEvent(KeyEvent &event); diff --git a/plugins/Kaleidoscope-LED-Stalker/src/kaleidoscope/plugin/LED-Stalker.h b/plugins/Kaleidoscope-LED-Stalker/src/kaleidoscope/plugin/LED-Stalker.h index 6f05f3cafe..19cfbcee6c 100644 --- a/plugins/Kaleidoscope-LED-Stalker/src/kaleidoscope/plugin/LED-Stalker.h +++ b/plugins/Kaleidoscope-LED-Stalker/src/kaleidoscope/plugin/LED-Stalker.h @@ -36,6 +36,9 @@ class StalkerEffect : public Plugin, public LEDModeInterface, public AccessTransientLEDMode { public: + StalkerEffect() { led_mode_name_ = "Stalker"; } + explicit StalkerEffect(const char *led_mode_name) { led_mode_name_ = led_mode_name; } + class ColorComputer { public: virtual cRGB compute(uint8_t *step) = 0; diff --git a/plugins/Kaleidoscope-LED-Wavepool/src/kaleidoscope/plugin/LED-Wavepool.h b/plugins/Kaleidoscope-LED-Wavepool/src/kaleidoscope/plugin/LED-Wavepool.h index d5749113fc..207356c350 100644 --- a/plugins/Kaleidoscope-LED-Wavepool/src/kaleidoscope/plugin/LED-Wavepool.h +++ b/plugins/Kaleidoscope-LED-Wavepool/src/kaleidoscope/plugin/LED-Wavepool.h @@ -41,6 +41,9 @@ class WavepoolEffect : public Plugin, public LEDModeInterface, public AccessTransientLEDMode { public: + WavepoolEffect() { led_mode_name_ = "Wavepool"; } + explicit WavepoolEffect(const char *led_mode_name) { led_mode_name_ = led_mode_name; } + EventHandlerResult onKeyEvent(KeyEvent &event); // ms before idle animation starts after last keypress diff --git a/plugins/Kaleidoscope-LEDBrightnessConfig/src/kaleidoscope/plugin/LEDBrightnessConfig.cpp b/plugins/Kaleidoscope-LEDBrightnessConfig/src/kaleidoscope/plugin/LEDBrightnessConfig.cpp index f5354a506f..a1aea26bc5 100644 --- a/plugins/Kaleidoscope-LEDBrightnessConfig/src/kaleidoscope/plugin/LEDBrightnessConfig.cpp +++ b/plugins/Kaleidoscope-LEDBrightnessConfig/src/kaleidoscope/plugin/LEDBrightnessConfig.cpp @@ -17,7 +17,7 @@ #include "kaleidoscope/plugin/LEDBrightnessConfig.h" -#include // for PSTR, strcmp_P, F, __FlashStringHelper +#include // for PSTR, strcmp_P, F #include // for EEPROMSettings #include // for Focus, FocusSerial #include // for uint8_t, uint16_t diff --git a/plugins/Kaleidoscope-LEDEffect-Breathe/src/kaleidoscope/plugin/LEDEffect-Breathe.h b/plugins/Kaleidoscope-LEDEffect-Breathe/src/kaleidoscope/plugin/LEDEffect-Breathe.h index fee01ceda3..bc2a2781f7 100644 --- a/plugins/Kaleidoscope-LEDEffect-Breathe/src/kaleidoscope/plugin/LEDEffect-Breathe.h +++ b/plugins/Kaleidoscope-LEDEffect-Breathe/src/kaleidoscope/plugin/LEDEffect-Breathe.h @@ -27,6 +27,9 @@ namespace plugin { class LEDBreatheEffect : public Plugin, public LEDModeInterface { public: + LEDBreatheEffect() { led_mode_name_ = "Breathe"; } + explicit LEDBreatheEffect(const char *led_mode_name) { led_mode_name_ = led_mode_name; } + uint8_t hue = 170; uint8_t saturation = 255; diff --git a/plugins/Kaleidoscope-LEDEffect-Chase/src/kaleidoscope/plugin/LEDEffect-Chase.h b/plugins/Kaleidoscope-LEDEffect-Chase/src/kaleidoscope/plugin/LEDEffect-Chase.h index 8ab77f4fbe..db1a7bde4d 100644 --- a/plugins/Kaleidoscope-LEDEffect-Chase/src/kaleidoscope/plugin/LEDEffect-Chase.h +++ b/plugins/Kaleidoscope-LEDEffect-Chase/src/kaleidoscope/plugin/LEDEffect-Chase.h @@ -28,6 +28,9 @@ namespace plugin { class LEDChaseEffect : public Plugin, public LEDModeInterface { public: + LEDChaseEffect() { led_mode_name_ = "Chase"; } + explicit LEDChaseEffect(const char *led_mode_name) { led_mode_name_ = led_mode_name; } + uint8_t update_delay() { return update_delay_; } diff --git a/plugins/Kaleidoscope-LEDEffect-DigitalRain/src/kaleidoscope/plugin/LEDEffect-DigitalRain.h b/plugins/Kaleidoscope-LEDEffect-DigitalRain/src/kaleidoscope/plugin/LEDEffect-DigitalRain.h index b068cf0549..43945c80ab 100644 --- a/plugins/Kaleidoscope-LEDEffect-DigitalRain/src/kaleidoscope/plugin/LEDEffect-DigitalRain.h +++ b/plugins/Kaleidoscope-LEDEffect-DigitalRain/src/kaleidoscope/plugin/LEDEffect-DigitalRain.h @@ -26,7 +26,8 @@ class LEDDigitalRainEffect : public Plugin, public LEDModeInterface, public AccessTransientLEDMode { public: - LEDDigitalRainEffect() {} + LEDDigitalRainEffect() { led_mode_name_ = "DigitalRain"; } + explicit LEDDigitalRainEffect(const char *led_mode_name) { led_mode_name_ = led_mode_name; } /** * Color channel enum. diff --git a/plugins/Kaleidoscope-LEDEffect-Rainbow/src/kaleidoscope/plugin/LEDEffect-Rainbow.h b/plugins/Kaleidoscope-LEDEffect-Rainbow/src/kaleidoscope/plugin/LEDEffect-Rainbow.h index b2495b595b..1a26aad6f1 100644 --- a/plugins/Kaleidoscope-LEDEffect-Rainbow/src/kaleidoscope/plugin/LEDEffect-Rainbow.h +++ b/plugins/Kaleidoscope-LEDEffect-Rainbow/src/kaleidoscope/plugin/LEDEffect-Rainbow.h @@ -27,6 +27,9 @@ namespace plugin { class LEDRainbowEffect : public Plugin, public LEDModeInterface { public: + LEDRainbowEffect() { led_mode_name_ = "Rainbow"; } + explicit LEDRainbowEffect(const char *led_mode_name) { led_mode_name_ = led_mode_name; } + void brightness(uint8_t); uint8_t brightness() { return rainbow_value; @@ -68,6 +71,9 @@ class LEDRainbowEffect : public Plugin, class LEDRainbowWaveEffect : public Plugin, public LEDModeInterface { public: + LEDRainbowWaveEffect() { led_mode_name_ = "RainbowWave"; } + explicit LEDRainbowWaveEffect(const char *led_mode_name) { led_mode_name_ = led_mode_name; } + void brightness(uint8_t); uint8_t brightness() { return rainbow_value; diff --git a/plugins/Kaleidoscope-LEDEffect-SolidColor/src/kaleidoscope/plugin/LEDEffect-SolidColor.h b/plugins/Kaleidoscope-LEDEffect-SolidColor/src/kaleidoscope/plugin/LEDEffect-SolidColor.h index 7ac5c39280..763764d686 100644 --- a/plugins/Kaleidoscope-LEDEffect-SolidColor/src/kaleidoscope/plugin/LEDEffect-SolidColor.h +++ b/plugins/Kaleidoscope-LEDEffect-SolidColor/src/kaleidoscope/plugin/LEDEffect-SolidColor.h @@ -29,7 +29,14 @@ class LEDSolidColor : public Plugin, public LEDModeInterface { public: LEDSolidColor(uint8_t r, uint8_t g, uint8_t b) - : r_(r), g_(g), b_(b) {} + : r_(r), g_(g), b_(b) { + led_mode_name_ = "SolidColor"; + } + + LEDSolidColor(const char *led_mode_name, uint8_t r, uint8_t g, uint8_t b) + : r_(r), g_(g), b_(b) { + led_mode_name_ = led_mode_name; + } // This class' instance has dynamic lifetime // diff --git a/plugins/Kaleidoscope-LEDEffects/src/kaleidoscope/plugin/Jukebox.cpp b/plugins/Kaleidoscope-LEDEffects/src/kaleidoscope/plugin/Jukebox.cpp index 6ceddecb64..ba202da9c4 100644 --- a/plugins/Kaleidoscope-LEDEffects/src/kaleidoscope/plugin/Jukebox.cpp +++ b/plugins/Kaleidoscope-LEDEffects/src/kaleidoscope/plugin/Jukebox.cpp @@ -20,10 +20,12 @@ #include "kaleidoscope/device/device.h" // for CRGB #include "kaleidoscope/plugin/TriColor.h" // for TriColor -kaleidoscope::plugin::TriColor JukeboxEffect(CRGB(0xc8, 0xe8, 0xee), /* TM */ +kaleidoscope::plugin::TriColor JukeboxEffect("Jukebox", + CRGB(0xc8, 0xe8, 0xee), /* TM */ CRGB(0xc3, 0xee, 0x8c), /* VCO */ CRGB(0x21, 0x38, 0xd7)); /* RN */ -kaleidoscope::plugin::TriColor JukeboxAlternateEffect(CRGB(0xc8, 0xe8, 0xee), /* TM */ +kaleidoscope::plugin::TriColor JukeboxAlternateEffect("JukeboxAlternate", + CRGB(0xc8, 0xe8, 0xee), /* TM */ CRGB(0x21, 0x38, 0xd7), /* RN */ CRGB(0xc3, 0xee, 0x8c)); /* VCO */ diff --git a/plugins/Kaleidoscope-LEDEffects/src/kaleidoscope/plugin/Miami.cpp b/plugins/Kaleidoscope-LEDEffects/src/kaleidoscope/plugin/Miami.cpp index 4d3799b186..f553a3803c 100644 --- a/plugins/Kaleidoscope-LEDEffects/src/kaleidoscope/plugin/Miami.cpp +++ b/plugins/Kaleidoscope-LEDEffects/src/kaleidoscope/plugin/Miami.cpp @@ -20,5 +20,6 @@ #include "kaleidoscope/device/device.h" // for CRGB #include "kaleidoscope/plugin/TriColor.h" // for TriColor -kaleidoscope::plugin::TriColor MiamiEffect(CRGB(0x4e, 0xd6, 0xd6), /* Cyan */ +kaleidoscope::plugin::TriColor MiamiEffect("Miami", + CRGB(0x4e, 0xd6, 0xd6), /* Cyan */ CRGB(0xaf, 0x67, 0xfa)); /* Magenta */ diff --git a/plugins/Kaleidoscope-LEDEffects/src/kaleidoscope/plugin/TriColor.cpp b/plugins/Kaleidoscope-LEDEffects/src/kaleidoscope/plugin/TriColor.cpp index 324361bf8c..e4c86c5d09 100644 --- a/plugins/Kaleidoscope-LEDEffects/src/kaleidoscope/plugin/TriColor.cpp +++ b/plugins/Kaleidoscope-LEDEffects/src/kaleidoscope/plugin/TriColor.cpp @@ -26,10 +26,11 @@ namespace kaleidoscope { namespace plugin { -TriColor::TriColor(cRGB base_color, cRGB mod_color, cRGB esc_color) { - base_color_ = base_color; - mod_color_ = mod_color; - esc_color_ = esc_color; +TriColor::TriColor(const char *led_mode_name, cRGB base_color, cRGB mod_color, cRGB esc_color) { + led_mode_name_ = led_mode_name; + base_color_ = base_color; + mod_color_ = mod_color; + esc_color_ = esc_color; } void TriColor::TransientLEDMode::update() { diff --git a/plugins/Kaleidoscope-LEDEffects/src/kaleidoscope/plugin/TriColor.h b/plugins/Kaleidoscope-LEDEffects/src/kaleidoscope/plugin/TriColor.h index 70da4c3949..143ba81048 100644 --- a/plugins/Kaleidoscope-LEDEffects/src/kaleidoscope/plugin/TriColor.h +++ b/plugins/Kaleidoscope-LEDEffects/src/kaleidoscope/plugin/TriColor.h @@ -27,9 +27,13 @@ namespace plugin { class TriColor : public Plugin, public LEDModeInterface { public: - TriColor(cRGB base_color, cRGB mod_color, cRGB esc_color); + TriColor(const char *led_mode_name, cRGB base_color, cRGB mod_color, cRGB esc_color); + TriColor(cRGB base_color, cRGB mod_color, cRGB esc_color) + : TriColor("TriColor", base_color, mod_color, esc_color) {} + TriColor(const char *led_mode_name, cRGB base_color, cRGB mod_color) + : TriColor(led_mode_name, base_color, mod_color, mod_color) {} TriColor(cRGB base_color, cRGB mod_color) - : TriColor(base_color, mod_color, mod_color) {} + : TriColor("TriColor", base_color, mod_color, mod_color) {} // This class' instance has dynamic lifetime // diff --git a/src/kaleidoscope/event_handlers.h b/src/kaleidoscope/event_handlers.h index da2230da1b..d5a222f2e4 100644 --- a/src/kaleidoscope/event_handlers.h +++ b/src/kaleidoscope/event_handlers.h @@ -37,6 +37,9 @@ #define _ABORTABLE true #define _NOT_ABORTABLE false +// Define the callback for the LED mode hook handler +typedef void (*LedModeCallback)(const char*); + #define _CURRENT_IMPLEMENTATION //****************************************************************************** @@ -125,6 +128,17 @@ class SignatureCheckDummy {}; (), (), (), __NL__ \ (), (), ##__VA_ARGS__) __NL__ \ __NL__ \ + /* Called by Focus, when handling the `led.modes` command. */ __NL__ \ + /* Is implemented in LEDModeInterface.h, but depends on */ __NL__ \ + /* the LED plugin to set `led_mode_name_`. */ __NL__ \ + OPERATION(onLedEffectQuery, __NL__ \ + 1, __NL__ \ + _CURRENT_IMPLEMENTATION, __NL__ \ + _NOT_ABORTABLE, __NL__ \ + (), (), (), /* non template */ __NL__ \ + (LedModeCallback callback), __NL__ \ + (callback), ##__VA_ARGS__) __NL__ \ + __NL__ \ OPERATION(onSetup, __NL__ \ 1, __NL__ \ _CURRENT_IMPLEMENTATION, __NL__ \ @@ -298,6 +312,10 @@ class SignatureCheckDummy {}; OP(onSetup, 1) __NL__ \ END(onSetup, 1) __NL__ \ __NL__ \ + START(onLedEffectQuery, 1) __NL__ \ + OP(onLedEffectQuery, 1) __NL__ \ + END(onLedEffectQuery, 1) __NL__ \ + __NL__ \ START(onNameQuery, 1) __NL__ \ OP(onNameQuery, 1) __NL__ \ END(onNameQuery, 1) __NL__ \ diff --git a/src/kaleidoscope/plugin/LEDControl/LED-Off.h b/src/kaleidoscope/plugin/LEDControl/LED-Off.h index 3462407890..7da51b4f3a 100644 --- a/src/kaleidoscope/plugin/LEDControl/LED-Off.h +++ b/src/kaleidoscope/plugin/LEDControl/LED-Off.h @@ -27,10 +27,11 @@ namespace plugin { // class LEDOff : public LEDMode { public: - LEDOff(void) {} + LEDOff() { led_mode_name_ = "Off"; } + explicit LEDOff(const char *led_mode_name) { led_mode_name_ = led_mode_name; } protected: - void onActivate(void) final; + void onActivate() final; void refreshAt(KeyAddr key_addr) final; }; } // namespace plugin diff --git a/src/kaleidoscope/plugin/LEDModeInterface.h b/src/kaleidoscope/plugin/LEDModeInterface.h index 2964760f86..45f408a1b6 100644 --- a/src/kaleidoscope/plugin/LEDModeInterface.h +++ b/src/kaleidoscope/plugin/LEDModeInterface.h @@ -16,13 +16,32 @@ #pragma once +#include // for PROGMEM + +#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult +#include "kaleidoscope/event_handlers.h" // for LedModeCallback + namespace kaleidoscope { namespace plugin { class LEDModeInterface { public: + LEDModeInterface() + : led_mode_name_{0} {} + explicit LEDModeInterface(const char *led_mode_name) + : led_mode_name_{led_mode_name} {} void activate(); + EventHandlerResult onLedEffectQuery(LedModeCallback callback) { + if (led_mode_name_ == 0) { + // If no name was defined, return a default string + callback("[unnamed led mode]"); + } else { + callback(led_mode_name_); + } + return EventHandlerResult::OK; + } + // This auxiliary class helps to generate a verbose error message // in case that there is no TransientLEDMode typedef or nested // class present in a derived class of LEDModeInterface. @@ -35,6 +54,9 @@ class LEDModeInterface { // lifetime is handled dynamically. // typedef NoLEDMode DynamicLEDMode; + + protected: + const char *led_mode_name_ PROGMEM; }; } // namespace plugin