Skip to content

Commit

Permalink
Store led mode names in sketch storage
Browse files Browse the repository at this point in the history
  • Loading branch information
EvyBongers committed Feb 25, 2024
1 parent 430819d commit 892d8b9
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class ColormapEffect : public Plugin,
public LEDModeInterface,
public AccessTransientLEDMode {
public:
ColormapEffect() { ledModeName = "Colormap"; }
explicit ColormapEffect(char *customName) { ledModeName = customName; }
ColormapEffect() { ledModeName = F("Colormap"); }
explicit ColormapEffect(__FlashStringHelper *customName) { ledModeName = customName; }

void max_layers(uint8_t max_);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ namespace plugin {
//
class FingerPainter : public LEDMode {
public:
FingerPainter() { ledModeName = "FingerPainter"; }
explicit FingerPainter(char *customName) { ledModeName = customName; }
FingerPainter() { ledModeName = F("FingerPainter"); }
explicit FingerPainter(__FlashStringHelper *customName) { ledModeName = customName; }

void toggle();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ EventHandlerResult FocusSerial::afterEachCycle() {
return EventHandlerResult::OK;
}

void ledModeHandler_(const char *name) {
void ledModeHandler_(const __FlashStringHelper *name) {
Runtime.serialPort().println(name);
}

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,8 +34,8 @@ class Heatmap : public Plugin,
public LEDModeInterface,
public AccessTransientLEDMode {
public:
Heatmap() { ledModeName = "Heatmap"; }
explicit Heatmap(char *customName) { ledModeName = customName; }
Heatmap() { ledModeName = F("Heatmap"); }
explicit Heatmap(__FlashStringHelper *customName) { ledModeName = customName; }

static uint16_t update_delay;
static const cRGB *heat_colors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class LEDActiveLayerColorEffect : public Plugin,
public LEDModeInterface,
public AccessTransientLEDMode {
public:
LEDActiveLayerColorEffect() { ledModeName = "ActiveLayerColor"; }
explicit LEDActiveLayerColorEffect(char *customName) { ledModeName = customName; }
LEDActiveLayerColorEffect() { ledModeName = F("ActiveLayerColor"); }
explicit LEDActiveLayerColorEffect(__FlashStringHelper *customName) { ledModeName = customName; }

EventHandlerResult onLayerChange();
void setColormap(const cRGB colormap[]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class LEDActiveLayerKeysEffect : public Plugin,
public LEDModeInterface,
public AccessTransientLEDMode {
public:
LEDActiveLayerKeysEffect() { ledModeName = "ActiveLayerKeys"; }
explicit LEDActiveLayerKeysEffect(char *customName) { ledModeName = customName; }
LEDActiveLayerKeysEffect() { ledModeName = F("ActiveLayerKeys"); }
explicit LEDActiveLayerKeysEffect(__FlashStringHelper *customName) { ledModeName = customName; }

EventHandlerResult onLayerChange();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class AlphaSquareEffect : public Plugin,
public LEDModeInterface,
public AccessTransientLEDMode {
public:
AlphaSquareEffect() { ledModeName = "AlphaSquare"; }
explicit AlphaSquareEffect(char *customName) { ledModeName = customName; }
AlphaSquareEffect() { ledModeName = F("AlphaSquare"); }
explicit AlphaSquareEffect(__FlashStringHelper *customName) { ledModeName = customName; }

static uint16_t length;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class StalkerEffect : public Plugin,
public LEDModeInterface,
public AccessTransientLEDMode {
public:
StalkerEffect() { ledModeName = "Stalker"; }
explicit StalkerEffect(char *customName) { ledModeName = customName; }
StalkerEffect() { ledModeName = F("Stalker"); }
explicit StalkerEffect(__FlashStringHelper *customName) { ledModeName = customName; }

class ColorComputer {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class WavepoolEffect : public Plugin,
public LEDModeInterface,
public AccessTransientLEDMode {
public:
WavepoolEffect() { ledModeName = "Wavepool"; }
explicit WavepoolEffect(char *customName) { ledModeName = customName; }
WavepoolEffect() { ledModeName = F("Wavepool"); }
explicit WavepoolEffect(__FlashStringHelper *customName) { ledModeName = customName; }

EventHandlerResult onKeyEvent(KeyEvent &event);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace plugin {
class LEDBreatheEffect : public Plugin,
public LEDModeInterface {
public:
LEDBreatheEffect() { ledModeName = "Breathe"; }
explicit LEDBreatheEffect(char *customName) { ledModeName = customName; }
LEDBreatheEffect() { ledModeName = F("Breathe"); }
explicit LEDBreatheEffect(__FlashStringHelper *customName) { ledModeName = customName; }

uint8_t hue = 170;
uint8_t saturation = 255;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace plugin {
class LEDChaseEffect : public Plugin,
public LEDModeInterface {
public:
LEDChaseEffect() { ledModeName = "Chase"; }
explicit LEDChaseEffect(char *customName) { ledModeName = customName; }
LEDChaseEffect() { ledModeName = F("Chase"); }
explicit LEDChaseEffect(__FlashStringHelper *customName) { ledModeName = customName; }

uint8_t update_delay() {
return update_delay_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class LEDDigitalRainEffect : public Plugin,
public LEDModeInterface,
public AccessTransientLEDMode {
public:
LEDDigitalRainEffect() { ledModeName = "DigitalRain"; }
explicit LEDDigitalRainEffect(char *customName) { ledModeName = customName; }
LEDDigitalRainEffect() { ledModeName = F("DigitalRain"); }
explicit LEDDigitalRainEffect(__FlashStringHelper *customName) { ledModeName = customName; }

/**
* Color channel enum.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace plugin {
class LEDRainbowEffect : public Plugin,
public LEDModeInterface {
public:
LEDRainbowEffect() { ledModeName = "Rainbow"; }
explicit LEDRainbowEffect(char *customName) { ledModeName = customName; }
LEDRainbowEffect() { ledModeName = F("Rainbow"); }
explicit LEDRainbowEffect(__FlashStringHelper *customName) { ledModeName = customName; }

void brightness(uint8_t);
uint8_t brightness() {
Expand Down Expand Up @@ -71,8 +71,8 @@ class LEDRainbowEffect : public Plugin,

class LEDRainbowWaveEffect : public Plugin, public LEDModeInterface {
public:
LEDRainbowWaveEffect() { ledModeName = "RainbowWave"; }
explicit LEDRainbowWaveEffect(char *customName) { ledModeName = customName; }
LEDRainbowWaveEffect() { ledModeName = F("RainbowWave"); }
explicit LEDRainbowWaveEffect(__FlashStringHelper *customName) { ledModeName = customName; }

void brightness(uint8_t);
uint8_t brightness() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class LEDSolidColor : public Plugin,
public:
LEDSolidColor(uint8_t r, uint8_t g, uint8_t b)
: r_(r), g_(g), b_(b) {
ledModeName = "SolidColor";
ledModeName = F("SolidColor");
}

LEDSolidColor(char *customName, uint8_t r, uint8_t g, uint8_t b)
LEDSolidColor(__FlashStringHelper *customName, uint8_t r, uint8_t g, uint8_t b)
: r_(r), g_(g), b_(b) {
ledModeName = customName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
#include "kaleidoscope/device/device.h" // for CRGB
#include "kaleidoscope/plugin/TriColor.h" // for TriColor

kaleidoscope::plugin::TriColor JukeboxEffect("Jukebox",
kaleidoscope::plugin::TriColor JukeboxEffect(F("Jukebox"),
CRGB(0xc8, 0xe8, 0xee), /* TM */
CRGB(0xc3, 0xee, 0x8c), /* VCO */
CRGB(0x21, 0x38, 0xd7)); /* RN */

kaleidoscope::plugin::TriColor JukeboxAlternateEffect("JukeboxAlternate",
kaleidoscope::plugin::TriColor JukeboxAlternateEffect(F("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,6 +20,6 @@
#include "kaleidoscope/device/device.h" // for CRGB
#include "kaleidoscope/plugin/TriColor.h" // for TriColor

kaleidoscope::plugin::TriColor MiamiEffect("Miami",
kaleidoscope::plugin::TriColor MiamiEffect(F("Miami"),
CRGB(0x4e, 0xd6, 0xd6), /* Cyan */
CRGB(0xaf, 0x67, 0xfa)); /* Magenta */
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
namespace kaleidoscope {
namespace plugin {

TriColor::TriColor(char *customName, cRGB base_color, cRGB mod_color, cRGB esc_color) {
TriColor::TriColor(__FlashStringHelper *customName, cRGB base_color, cRGB mod_color, cRGB esc_color) {
ledModeName = customName;
base_color_ = base_color;
mod_color_ = mod_color;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ namespace plugin {
class TriColor : public Plugin,
public LEDModeInterface {
public:
TriColor(char *customName, cRGB base_color, cRGB mod_color, cRGB esc_color);
TriColor(__FlashStringHelper *customName, 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(char *customName, cRGB base_color, cRGB mod_color)
: TriColor(F("TriColor"), base_color, mod_color, esc_color) {}
TriColor(__FlashStringHelper *customName, cRGB base_color, cRGB mod_color)
: TriColor(customName, base_color, mod_color, mod_color) {}
TriColor(cRGB base_color, cRGB mod_color)
: TriColor("TriColor", base_color, mod_color, mod_color) {}
: TriColor(F("TriColor"), base_color, mod_color, mod_color) {}

// This class' instance has dynamic lifetime
//
Expand Down
4 changes: 3 additions & 1 deletion src/kaleidoscope/event_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#pragma once

#include <Arduino.h> // for __FlashStringHelper

// This file defines the names and argument signatures for all event handlers
// in the Kaleidoscope core.
//
Expand All @@ -38,7 +40,7 @@
#define _NOT_ABORTABLE false

// Define the callback for the LED mode hook handler
typedef void (*LedModeCallback)(const char*);
typedef void (*LedModeCallback)(const __FlashStringHelper*);

#define _CURRENT_IMPLEMENTATION

Expand Down
4 changes: 2 additions & 2 deletions src/kaleidoscope/plugin/LEDControl/LED-Off.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace plugin {
//
class LEDOff : public LEDMode {
public:
LEDOff() { ledModeName = "Off"; }
explicit LEDOff(char *customName) { ledModeName = customName; }
LEDOff() { ledModeName = F("Off"); }
explicit LEDOff(__FlashStringHelper *customName) { ledModeName = customName; }

protected:
void onActivate() final;
Expand Down
8 changes: 5 additions & 3 deletions src/kaleidoscope/plugin/LEDModeInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#pragma once

#include <Arduino.h> // for __FlashStringHelper, F

#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/event_handlers.h" // for LedModeCallback

Expand All @@ -26,14 +28,14 @@ class LEDModeInterface {
public:
LEDModeInterface()
: ledModeName{0} {}
explicit LEDModeInterface(const char *_ledModeName)
explicit LEDModeInterface(const __FlashStringHelper *_ledModeName)
: ledModeName{_ledModeName} {}
void activate();

EventHandlerResult onLedEffectQuery(LedModeCallback callback) {
if (ledModeName == 0) {
// If no name was defined, return a default string
callback(const_cast<char *>("[unnamed led mode]"));
callback(F("[unnamed led mode]"));
} else {
callback(ledModeName);
}
Expand All @@ -54,7 +56,7 @@ class LEDModeInterface {
typedef NoLEDMode DynamicLEDMode;

protected:
const char *ledModeName;
const __FlashStringHelper *ledModeName;
};

} // namespace plugin
Expand Down

0 comments on commit 892d8b9

Please sign in to comment.