Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add focus command for retreiving a list of installed LED effects #1387

Merged
merged 51 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
1a00ff1
Implement focus command for querying LED modes
EvyBongers Feb 9, 2024
e8e23d6
First onLedEffectQuery implementation
EvyBongers Feb 13, 2024
f1a988b
Initial implementation in all LED effect plugins
EvyBongers Feb 13, 2024
6a2a608
Implement onLedEffectQuery on both rainbow effects
EvyBongers Feb 13, 2024
c137e4a
Implement onLedEffectQuery in LEDOff as well
EvyBongers Feb 13, 2024
f0351c2
Implement onLedEffectQuery in LEDModeInterface
EvyBongers Feb 17, 2024
ec7bf20
Implement new design in ActiveLayerKeys
EvyBongers Feb 17, 2024
1ad9749
Implement new design in LEDOff
EvyBongers Feb 17, 2024
43fe544
Implement new design in FingerPainterEffect
EvyBongers Feb 17, 2024
ff729f3
Implement new design in HeatmapEffect
EvyBongers Feb 17, 2024
04fda4f
Implement new design in Colormap
EvyBongers Feb 17, 2024
690843d
Implement new design in LEDActiveLayerColor
EvyBongers Feb 17, 2024
f9f4d81
Implement new design in AlphaSquareEffect
EvyBongers Feb 17, 2024
f45c4f4
Implement new design in StalkerEffect
EvyBongers Feb 17, 2024
af109f8
Implement new design in WavepoolEffect
EvyBongers Feb 17, 2024
312aacd
Implement new design in TriColorEffect
EvyBongers Feb 17, 2024
22c6f64
Implement new design in LEDBreatheEffect
EvyBongers Feb 17, 2024
0f11dee
Implement new design in LEDChaseEffect
EvyBongers Feb 17, 2024
0e41496
Implement new design in rainbow effects
EvyBongers Feb 17, 2024
4cab81a
Implement new design in SolidColorEffect
EvyBongers Feb 17, 2024
ca320fc
Implement new design in DigitalRain
EvyBongers Feb 18, 2024
ad6dae5
Fix cpplint errors
EvyBongers Feb 18, 2024
835290a
Fix code style errors
EvyBongers Feb 18, 2024
9aefde8
At least get the color right
EvyBongers Feb 18, 2024
cb761e0
Allow user to set a custom name for led modes
EvyBongers Feb 19, 2024
5f00677
Rename focus command to led_modes
EvyBongers Feb 19, 2024
a1e7d6a
Drop lost onLedEffectQuery methods
EvyBongers Feb 19, 2024
b42ebb8
Clean up unused imports
EvyBongers Feb 19, 2024
54a1428
We like consistency
EvyBongers Feb 19, 2024
ee6904b
Another update to led modes focus command :)
EvyBongers Feb 19, 2024
4017c89
Strip the Effect suffix of led mode names
EvyBongers Feb 19, 2024
947453c
Mark single-parameter constructors as explicit
EvyBongers Feb 19, 2024
297a4dd
Send a default string for unnamed led modes
EvyBongers Feb 20, 2024
9e30b1e
Remove FocusSerial dependency in LEDModeInterface
EvyBongers Feb 21, 2024
853f6ca
Make cpplint happy
EvyBongers Feb 21, 2024
c4e7094
Send over focus differently
EvyBongers Feb 21, 2024
f235ce6
Use a callback to send led mode names over focus
EvyBongers Feb 25, 2024
9b61e7f
Consistent use of const char*
EvyBongers Feb 25, 2024
bae2088
Fix led mode names for TriColor effects
EvyBongers Feb 25, 2024
4122d6f
Strip "LED" prefix from led mode names
EvyBongers Feb 25, 2024
dd93a06
Store led mode names in sketch storage
EvyBongers Feb 25, 2024
b08125e
Fix oversight in Tricolor
EvyBongers Feb 25, 2024
77e3d69
Fix remaining constructors
EvyBongers Feb 25, 2024
aa905ae
Rename callback method
EvyBongers Feb 26, 2024
1807e14
Rename member variables to according to style guide
EvyBongers Feb 26, 2024
c6cf3a8
Rename constructor arguments
EvyBongers Feb 26, 2024
b7e0ce7
Code style
EvyBongers Feb 26, 2024
b59aef2
Merge branch 'keyboardio:master' into feat/LedEffectNames
EvyBongers Feb 26, 2024
41c6052
Merge remote-tracking branch 'upstream/master' into feat/LedEffectNames
EvyBongers Mar 5, 2024
5c51f43
Stop using F()
EvyBongers Mar 1, 2024
165b179
Remove duplicate code
EvyBongers Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "kaleidoscope/plugin/FocusSerial.h"

#include <Arduino.h> // for PSTR, __FlashStringHelper, F, strcmp_P
#include <Arduino.h> // for PSTR, F, strcmp_P
#include <HardwareSerial.h> // for HardwareSerial
#include <string.h> // for memset

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#pragma once

#include <Arduino.h> // for delayMicroseconds
#include <Arduino.h> // for __FlashStringHelper, delayMicroseconds
#include <HardwareSerial.h> // for HardwareSerial
#include <stdint.h> // for uint8_t, uint16_t

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t _colormap_size>
void setColormap(cRGB const (&colormap)[_colormap_size]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "kaleidoscope/plugin/LEDBrightnessConfig.h"

#include <Arduino.h> // for PSTR, strcmp_P, F, __FlashStringHelper
#include <Arduino.h> // for PSTR, strcmp_P, F
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint8_t, uint16_t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
18 changes: 18 additions & 0 deletions src/kaleidoscope/event_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

//******************************************************************************
Expand Down Expand Up @@ -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__ \
Expand Down Expand Up @@ -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__ \
Expand Down
5 changes: 3 additions & 2 deletions src/kaleidoscope/plugin/LEDControl/LED-Off.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions src/kaleidoscope/plugin/LEDModeInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,32 @@

#pragma once

#include <Arduino.h> // 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]");
obra marked this conversation as resolved.
Show resolved Hide resolved
} 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.
Expand All @@ -35,6 +54,9 @@ class LEDModeInterface {
// lifetime is handled dynamically.
//
typedef NoLEDMode DynamicLEDMode;

protected:
const char *led_mode_name_ PROGMEM;
};

} // namespace plugin
Expand Down
Loading