Skip to content

Commit

Permalink
Initial implementation in all LED effect plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
EvyBongers committed Feb 13, 2024
1 parent d70a15b commit fb579dc
Show file tree
Hide file tree
Showing 24 changed files with 92 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ EventHandlerResult ColormapEffect::onNameQuery() {
return ::Focus.sendName(F("ColormapEffect"));
}

EventHandlerResult ColormapEffect::onLedEffectQuery() {
return ::Focus.sendName(F("ColormapEffect"));
}

bool ColormapEffect::isUninitialized() {
return ::LEDPaletteTheme.isThemeUninitialized(map_base_, max_layers_);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ColormapEffect : public Plugin,
EventHandlerResult onLayerChange();
EventHandlerResult onNameQuery();
EventHandlerResult onFocusEvent(const char *input);
EventHandlerResult onLedEffectQuery();

static bool isUninitialized();
static void updateColorIndexAtPosition(uint8_t layer, uint16_t position, uint8_t palette_index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ EventHandlerResult FingerPainter::onNameQuery() {
return ::Focus.sendName(F("FingerPainter"));
}

EventHandlerResult FingerPainter::onLedEffectQuery() {
return ::Focus.sendName(F("FingerPainterEffect"));
}

EventHandlerResult FingerPainter::onSetup() {
color_base_ = ::LEDPaletteTheme.reserveThemes(1);
return EventHandlerResult::OK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class FingerPainter : public LEDMode {
EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult onFocusEvent(const char *input);
EventHandlerResult onSetup();
EventHandlerResult onLedEffectQuery();
EventHandlerResult onNameQuery();
EventHandlerResult onLedEffectQuery();

protected:
void update() final;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

#include "kaleidoscope/plugin/Heatmap.h"

#include <Arduino.h> // for pgm_read_byte, PROGMEM
#include <stdint.h> // for uint16_t, uint8_t, INT16_MAX
#include <Arduino.h> // for pgm_read_byte, PROGMEM
#include <Kaleidoscope-FocusSerial.h> // for Focus
#include <stdint.h> // for uint16_t, uint8_t, INT16_MAX

#include "kaleidoscope/KeyAddr.h" // for MatrixAddr, MatrixAddr<>::Range, KeyAddr
#include "kaleidoscope/KeyEvent.h" // for KeyEvent
Expand All @@ -44,6 +45,10 @@ uint16_t Heatmap::update_delay = 1000;
uint16_t Heatmap::highest_ = 1;
uint16_t Heatmap::heatmap_[];

EventHandlerResult Heatmap::onLedEffectQuery() {
return ::Focus.sendName(F("HeatmapEffect"));
}

Heatmap::TransientLEDMode::TransientLEDMode(const Heatmap *parent)
: // last heatmap computation time
last_heatmap_comp_time_(Runtime.millisAtCycleStart()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Heatmap : public Plugin,
void resetMap();

EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult onLedEffectQuery();
EventHandlerResult beforeEachCycle();

// This class' instance has dynamic lifetime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

#include "kaleidoscope/plugin/LED-ActiveLayerColor.h"

#include <Arduino.h> // for pgm_read_byte
#include <stdint.h> // for uint8_t
#include <Arduino.h> // for pgm_read_byte
#include <Kaleidoscope-FocusSerial.h> // for Focus
#include <stdint.h> // for uint8_t

#include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
Expand All @@ -31,6 +32,10 @@ namespace plugin {

const cRGB *LEDActiveLayerColorEffect::colormap_;

EventHandlerResult LEDActiveLayerColorEffect::onLedEffectQuery() {
return ::Focus.sendName(F("LEDActiveLayerColorEffect"));
}

LEDActiveLayerColorEffect::TransientLEDMode::TransientLEDMode(
const LEDActiveLayerColorEffect *parent)
: parent_(parent),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class LEDActiveLayerColorEffect : public Plugin,
public AccessTransientLEDMode {
public:
EventHandlerResult onLayerChange();
EventHandlerResult onLedEffectQuery();
void setColormap(const cRGB colormap[]);

// This class' instance has dynamic lifetime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

#include "kaleidoscope/plugin/LED-AlphaSquare/Effect.h"

#include <stdint.h> // for uint16_t, uint8_t
#include <Kaleidoscope-FocusSerial.h> // for Focus
#include <stdint.h> // for uint16_t, uint8_t

#include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/KeyEvent.h" // for KeyEvent
Expand All @@ -34,6 +35,10 @@ namespace plugin {

uint16_t AlphaSquareEffect::length = 1000;

EventHandlerResult AlphaSquareEffect::onLedEffectQuery() {
return ::Focus.sendName(F("AlphaSquareEffect"));
}

AlphaSquareEffect::TransientLEDMode::TransientLEDMode(AlphaSquareEffect * /*parent*/) // NOLINT(readability/casting)
: last_key_left_(Key_NoKey),
last_key_right_(Key_NoKey) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class AlphaSquareEffect : public Plugin,
static uint16_t length;

EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult onLedEffectQuery();

// This class' instance has dynamic lifetime
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

#include "kaleidoscope/plugin/LED-Stalker.h"

#include <Arduino.h> // for min
#include <stdint.h> // for uint8_t, uint16_t, uint32_t
#include <Arduino.h> // for min
#include <Kaleidoscope-FocusSerial.h> // for Focus
#include <stdint.h> // for uint8_t, uint16_t, uint32_t

#include "kaleidoscope/KeyAddr.h" // for MatrixAddr, KeyAddr, MatrixAddr<>::...
#include "kaleidoscope/KeyEvent.h" // for KeyEvent
Expand All @@ -36,6 +37,10 @@ uint16_t StalkerEffect::step_length = 50;
cRGB StalkerEffect::inactive_color = (cRGB){
0, 0, 0};

EventHandlerResult StalkerEffect::onLedEffectQuery() {
return ::Focus.sendName(F("StalkerEffect"));
}

StalkerEffect::TransientLEDMode::TransientLEDMode(const StalkerEffect *parent)
: parent_(parent),
step_start_time_(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class StalkerEffect : public Plugin,
static cRGB inactive_color;

EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult onLedEffectQuery();

// This class' instance has dynamic lifetime
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

#include "kaleidoscope/plugin/LED-Wavepool.h"

#include <Arduino.h> // for pgm_read_byte, PROGMEM, abs
#include <stdint.h> // for int8_t, uint8_t, int16_t, intptr_t
#include <Arduino.h> // for pgm_read_byte, PROGMEM, abs
#include <Kaleidoscope-FocusSerial.h> // for Focus
#include <stdint.h> // for int8_t, uint8_t, int16_t, intptr_t

#include "kaleidoscope/KeyAddr.h" // for MatrixAddr, KeyAddr, MatrixAddr<>::...
#include "kaleidoscope/KeyEvent.h" // for KeyEvent
Expand All @@ -42,6 +43,10 @@ namespace plugin {
uint16_t WavepoolEffect::idle_timeout = 5000; // 5 seconds
int16_t WavepoolEffect::ripple_hue = WavepoolEffect::rainbow_hue; // automatic hue

EventHandlerResult WavepoolEffect::onLedEffectQuery() {
return ::Focus.sendName(F("WavepoolEffect"));
}

// map native keyboard coordinates (16x4) into geometric space (14x5)
PROGMEM const uint8_t WavepoolEffect::TransientLEDMode::rc2pos[Runtime.device().numKeys()] = {
// clang-format off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class WavepoolEffect : public Plugin,
public AccessTransientLEDMode {
public:
EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult onLedEffectQuery();

// ms before idle animation starts after last keypress
static uint16_t idle_timeout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

#include "kaleidoscope/plugin/LEDEffect-Breathe.h"

#include <stdint.h> // for uint8_t
#include <Kaleidoscope-FocusSerial.h> // for Focus
#include <stdint.h> // for uint8_t

#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "kaleidoscope/device/device.h" // for cRGB
Expand All @@ -25,6 +26,11 @@

namespace kaleidoscope {
namespace plugin {

EventHandlerResult LEDBreatheEffect::onLedEffectQuery() {
return ::Focus.sendName(F("LEDBreatheEffect"));
}

void LEDBreatheEffect::TransientLEDMode::update() {
if (!Runtime.has_leds)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class LEDBreatheEffect : public Plugin,
uint8_t hue = 170;
uint8_t saturation = 255;

EventHandlerResult onLedEffectQuery();

// This class' instance has dynamic lifetime
//
class TransientLEDMode : public LEDMode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

#include "kaleidoscope/plugin/LEDEffect-Chase.h"

#include <stdint.h> // for uint16_t, uint8_t
#include <Kaleidoscope-FocusSerial.h> // for Focus
#include <stdint.h> // for uint16_t, uint8_t

#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "kaleidoscope/device/device.h" // for CRGB, Device, Base<>::LEDRangeIterator
Expand All @@ -25,6 +26,10 @@
namespace kaleidoscope {
namespace plugin {

EventHandlerResult LEDChaseEffect::onLedEffectQuery() {
return ::Focus.sendName(F("LEDChaseEffect"));
}

void LEDChaseEffect::TransientLEDMode::update() {
if (!Runtime.has_leds)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace plugin {
class LEDChaseEffect : public Plugin,
public LEDModeInterface {
public:
EventHandlerResult onLedEffectQuery();

uint8_t update_delay() {
return update_delay_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

#include "kaleidoscope/plugin/LEDEffect-Rainbow.h"

#include <Arduino.h> // for byte
#include <stdint.h> // for uint8_t, uint16_t
#include <Arduino.h> // for byte
#include <Kaleidoscope-FocusSerial.h> // for Focus
#include <stdint.h> // for uint8_t, uint16_t

#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "kaleidoscope/device/device.h" // for Base<>::LEDRangeIterator, Base<>::L...
Expand Down Expand Up @@ -47,6 +48,10 @@ void LEDRainbowEffect::TransientLEDMode::update() {
::LEDControl.set_all_leds_to(rainbow);
}

EventHandlerResult LEDRainbowEffect::onLedEffectQuery() {
return ::Focus.sendName(F("LEDRainbowEffect"));
}

void LEDRainbowEffect::brightness(byte brightness) {
rainbow_value = brightness;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace plugin {
class LEDRainbowEffect : public Plugin,
public LEDModeInterface {
public:
EventHandlerResult onLedEffectQuery();

void brightness(uint8_t);
uint8_t brightness() {
return rainbow_value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@

#include "kaleidoscope/plugin/LEDEffect-SolidColor.h"

#include <Kaleidoscope-FocusSerial.h> // for Focus

#include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/device/device.h" // for CRGB
#include "kaleidoscope/plugin/LEDControl.h" // for LEDControl

namespace kaleidoscope {
namespace plugin {

EventHandlerResult LEDSolidColor::onLedEffectQuery() {
return ::Focus.sendName(F("SolidColor"));
}

void LEDSolidColor::TransientLEDMode::onActivate() {
::LEDControl.set_all_leds_to(parent_->r_,
parent_->g_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace plugin {
class LEDSolidColor : public Plugin,
public LEDModeInterface {
public:
EventHandlerResult onLedEffectQuery();

LEDSolidColor(uint8_t r, uint8_t g, uint8_t b)
: r_(r), g_(g), b_(b) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "kaleidoscope/plugin/TriColor.h"

#include <Kaleidoscope-FocusSerial.h> // for Focus

#include "kaleidoscope/KeyAddr.h" // for KeyAddr, MatrixAddr, MatrixAddr<>::Range
#include "kaleidoscope/device/device.h" // for cRGB
#include "kaleidoscope/key_defs.h" // for Key, Key_0, Key_A, Key_Escape, Key_F1, Key_F12
Expand All @@ -26,6 +28,10 @@
namespace kaleidoscope {
namespace plugin {

EventHandlerResult TriColor::onLedEffectQuery() {
return ::Focus.sendName(F("TriColor"));
}

TriColor::TriColor(cRGB base_color, cRGB mod_color, cRGB esc_color) {
base_color_ = base_color;
mod_color_ = mod_color;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace plugin {
class TriColor : public Plugin,
public LEDModeInterface {
public:
EventHandlerResult onLedEffectQuery();

TriColor(cRGB base_color, cRGB mod_color, cRGB esc_color);
TriColor(cRGB base_color, cRGB mod_color)
: TriColor(base_color, mod_color, mod_color) {}
Expand Down

0 comments on commit fb579dc

Please sign in to comment.