leds: Guard most LED-related functions

LED related functions should be as close to no-op on LED-less hardware as
possible. For this reason, guard all relevant points with an early exit in the
LED-less case.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/432/head
Gergely Nagy 6 years ago
parent 3253f97c88
commit 8e7ff606d5
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -39,13 +39,16 @@ void ColormapEffect::max_layers(uint8_t max_) {
} }
void ColormapEffect::onActivate(void) { void ColormapEffect::onActivate(void) {
if (!Kaleidoscope.has_leds)
return;
last_highest_layer_ = Layer.top(); last_highest_layer_ = Layer.top();
if (last_highest_layer_ <= max_layers_) if (last_highest_layer_ <= max_layers_)
::LEDPaletteTheme.updateHandler(map_base_, last_highest_layer_); ::LEDPaletteTheme.updateHandler(map_base_, last_highest_layer_);
} }
void ColormapEffect::update(void) { void ColormapEffect::update(void) {
if (Layer.top() == last_highest_layer_) if (!Kaleidoscope.has_leds || Layer.top() == last_highest_layer_)
return; return;
onActivate(); onActivate();

@ -47,7 +47,7 @@ void FingerPainter::toggle(void) {
} }
EventHandlerResult FingerPainter::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state) { EventHandlerResult FingerPainter::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state) {
if (!edit_mode_) if (!Kaleidoscope.has_leds || !edit_mode_)
return EventHandlerResult::OK; return EventHandlerResult::OK;
if (!keyToggledOn(key_state)) { if (!keyToggledOn(key_state)) {

@ -125,6 +125,9 @@ void Heatmap::resetMap(void) {
} }
EventHandlerResult Heatmap::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state) { EventHandlerResult Heatmap::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state) {
if (!Kaleidoscope.has_leds)
return EventHandlerResult::OK;
// this methode is called frequently by Kaleidoscope // this methode is called frequently by Kaleidoscope
// even if the module isn't activated // even if the module isn't activated
@ -155,6 +158,9 @@ EventHandlerResult Heatmap::onKeyswitchEvent(Key &mapped_key, byte row, byte col
} }
EventHandlerResult Heatmap::beforeEachCycle() { EventHandlerResult Heatmap::beforeEachCycle() {
if (!Kaleidoscope.has_leds)
return EventHandlerResult::OK;
// this methode is called frequently by Kaleidoscope // this methode is called frequently by Kaleidoscope
// even if the module isn't activated // even if the module isn't activated
@ -171,6 +177,9 @@ EventHandlerResult Heatmap::beforeEachCycle() {
} }
void Heatmap::update(void) { void Heatmap::update(void) {
if (!Kaleidoscope.has_leds)
return;
// this methode is called frequently by the LEDControl::loopHook // this methode is called frequently by the LEDControl::loopHook
// do nothing if we didn't reach next_heatmap_comp_time_ yet // do nothing if we didn't reach next_heatmap_comp_time_ yet

@ -29,6 +29,9 @@ cRGB ActiveModColorEffect::highlight_color = (cRGB) {
cRGB ActiveModColorEffect::sticky_color = CRGB(0xff, 0x00, 0x00); cRGB ActiveModColorEffect::sticky_color = CRGB(0xff, 0x00, 0x00);
EventHandlerResult ActiveModColorEffect::beforeReportingState() { EventHandlerResult ActiveModColorEffect::beforeReportingState() {
if (!Kaleidoscope.has_leds)
return EventHandlerResult::OK;
for (byte r = 0; r < ROWS; r++) { for (byte r = 0; r < ROWS; r++) {
for (byte c = 0; c < COLS; c++) { for (byte c = 0; c < COLS; c++) {
Key k = Layer.lookupOnActiveLayer(r, c); Key k = Layer.lookupOnActiveLayer(r, c);

@ -64,6 +64,9 @@ static const uint16_t alphabet[] PROGMEM = {
cRGB AlphaSquare::color = {0x80, 0x80, 0x80}; cRGB AlphaSquare::color = {0x80, 0x80, 0x80};
void AlphaSquare::display(Key key, uint8_t row, uint8_t col, cRGB key_color) { void AlphaSquare::display(Key key, uint8_t row, uint8_t col, cRGB key_color) {
if (!Kaleidoscope.has_leds)
return;
if (key < Key_A || key > Key_0) if (key < Key_A || key > Key_0)
return; return;
@ -78,6 +81,9 @@ void AlphaSquare::display(Key key, uint8_t row, uint8_t col) {
} }
void AlphaSquare::display(uint16_t symbol, uint8_t row, uint8_t col, cRGB key_color) { void AlphaSquare::display(uint16_t symbol, uint8_t row, uint8_t col, cRGB key_color) {
if (!Kaleidoscope.has_leds)
return;
for (uint8_t r = 0; r < 4; r++) { for (uint8_t r = 0; r < 4; r++) {
for (uint8_t c = 0; c < 4; c++) { for (uint8_t c = 0; c < 4; c++) {
uint8_t pixel = bitRead(symbol, r * 4 + c); uint8_t pixel = bitRead(symbol, r * 4 + c);

@ -25,6 +25,9 @@ uint32_t AlphaSquareEffect::end_time_left_, AlphaSquareEffect::end_time_right_;
Key AlphaSquareEffect::last_key_left_, AlphaSquareEffect::last_key_right_; Key AlphaSquareEffect::last_key_left_, AlphaSquareEffect::last_key_right_;
void AlphaSquareEffect::update(void) { void AlphaSquareEffect::update(void) {
if (!Kaleidoscope.has_leds)
return;
if (end_time_left_ && millis() > end_time_left_) { if (end_time_left_ && millis() > end_time_left_) {
::AlphaSquare.clear(last_key_left_); ::AlphaSquare.clear(last_key_left_);
end_time_left_ = 0; end_time_left_ = 0;
@ -36,6 +39,9 @@ void AlphaSquareEffect::update(void) {
} }
EventHandlerResult AlphaSquareEffect::onKeyswitchEvent(Key &mappedKey, byte row, byte col, uint8_t keyState) { EventHandlerResult AlphaSquareEffect::onKeyswitchEvent(Key &mappedKey, byte row, byte col, uint8_t keyState) {
if (!Kaleidoscope.has_leds)
return EventHandlerResult::OK;
if (::LEDControl.get_mode() != &::AlphaSquareEffect) if (::LEDControl.get_mode() != &::AlphaSquareEffect)
return EventHandlerResult::OK; return EventHandlerResult::OK;

@ -37,6 +37,9 @@ uint16_t LEDPaletteTheme::reserveThemes(uint8_t max_themes) {
} }
void LEDPaletteTheme::updateHandler(uint16_t theme_base, uint8_t theme) { void LEDPaletteTheme::updateHandler(uint16_t theme_base, uint8_t theme) {
if (!Kaleidoscope.has_leds)
return;
uint16_t map_base = theme_base + (theme * ROWS * COLS / 2); uint16_t map_base = theme_base + (theme * ROWS * COLS / 2);
for (uint16_t pos = 0; pos < ROWS * COLS; pos++) { for (uint16_t pos = 0; pos < ROWS * COLS; pos++) {
@ -46,6 +49,9 @@ void LEDPaletteTheme::updateHandler(uint16_t theme_base, uint8_t theme) {
} }
void LEDPaletteTheme::refreshAt(uint16_t theme_base, uint8_t theme, byte row, byte col) { void LEDPaletteTheme::refreshAt(uint16_t theme_base, uint8_t theme, byte row, byte col) {
if (!Kaleidoscope.has_leds)
return;
uint16_t map_base = theme_base + (theme * ROWS * COLS / 2); uint16_t map_base = theme_base + (theme * ROWS * COLS / 2);
uint16_t pos = KeyboardHardware.getLedIndex(row, col); uint16_t pos = KeyboardHardware.getLedIndex(row, col);
@ -94,6 +100,9 @@ void LEDPaletteTheme::updateColorIndexAtPosition(uint16_t map_base, uint16_t pos
} }
EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) { EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) {
if (!Kaleidoscope.has_leds)
return EventHandlerResult::OK;
const char *cmd = PSTR("palette"); const char *cmd = PSTR("palette");
if (::Focus.handleHelp(command, cmd)) if (::Focus.handleHelp(command, cmd))
@ -135,6 +144,9 @@ EventHandlerResult LEDPaletteTheme::themeFocusEvent(const char *command,
const char *expected_command, const char *expected_command,
uint16_t theme_base, uint16_t theme_base,
uint8_t max_themes) { uint8_t max_themes) {
if (!Kaleidoscope.has_leds)
return EventHandlerResult::OK;
if (::Focus.handleHelp(command, expected_command)) if (::Focus.handleHelp(command, expected_command))
return EventHandlerResult::OK; return EventHandlerResult::OK;

@ -33,6 +33,9 @@ void StalkerEffect::onActivate(void) {
} }
EventHandlerResult StalkerEffect::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t keyState) { EventHandlerResult StalkerEffect::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t keyState) {
if (!Kaleidoscope.has_leds)
return EventHandlerResult::OK;
if (row >= ROWS || col >= COLS) if (row >= ROWS || col >= COLS)
return EventHandlerResult::OK; return EventHandlerResult::OK;
@ -44,6 +47,9 @@ EventHandlerResult StalkerEffect::onKeyswitchEvent(Key &mapped_key, byte row, by
} }
void StalkerEffect::update(void) { void StalkerEffect::update(void) {
if (!Kaleidoscope.has_leds)
return;
if (!variant) if (!variant)
return; return;

@ -101,6 +101,9 @@ int8_t LEDControl::mode_add(LEDMode *mode) {
} }
void LEDControl::set_all_leds_to(uint8_t r, uint8_t g, uint8_t b) { void LEDControl::set_all_leds_to(uint8_t r, uint8_t g, uint8_t b) {
if (!Kaleidoscope.has_leds)
return;
cRGB color; cRGB color;
color.r = r; color.r = r;
color.g = g; color.g = g;
@ -184,6 +187,9 @@ EventHandlerResult FocusLEDCommand::onFocusEvent(const char *command) {
THEME, THEME,
} subCommand; } subCommand;
if (!Kaleidoscope.has_leds)
return EventHandlerResult::OK;
if (::Focus.handleHelp(command, PSTR("led.at\n" if (::Focus.handleHelp(command, PSTR("led.at\n"
"led.setAll\n" "led.setAll\n"
"led.mode\n" "led.mode\n"

@ -109,10 +109,16 @@ class LEDControl : public kaleidoscope::Plugin {
static void prev_mode(void); static void prev_mode(void);
static void setup(void); static void setup(void);
static void update(void) { static void update(void) {
if (!Kaleidoscope.has_leds)
return;
if (modes[mode]) if (modes[mode])
modes[mode]->update(); modes[mode]->update();
} }
static void refreshAt(byte row, byte col) { static void refreshAt(byte row, byte col) {
if (!Kaleidoscope.has_leds)
return;
if (modes[mode]) if (modes[mode])
modes[mode]->refreshAt(row, col); modes[mode]->refreshAt(row, col);
} }
@ -120,6 +126,9 @@ class LEDControl : public kaleidoscope::Plugin {
static uint8_t get_mode_index(); static uint8_t get_mode_index();
static LEDMode *get_mode(); static LEDMode *get_mode();
static void refreshAll() { static void refreshAll() {
if (!Kaleidoscope.has_leds)
return;
if (paused) if (paused)
return; return;

@ -45,6 +45,9 @@ EventHandlerResult BootAnimationEffect::onSetup() {
} }
EventHandlerResult BootAnimationEffect::afterEachCycle() { EventHandlerResult BootAnimationEffect::afterEachCycle() {
if (!Kaleidoscope.has_leds)
return EventHandlerResult::OK;
//If already done or we're not in a ready state, bail //If already done or we're not in a ready state, bail
if (done_) { if (done_) {
return EventHandlerResult::OK; return EventHandlerResult::OK;

@ -61,6 +61,9 @@ void BootGreetingEffect::findLed(void) {
} }
EventHandlerResult BootGreetingEffect::afterEachCycle() { EventHandlerResult BootGreetingEffect::afterEachCycle() {
if (!Kaleidoscope.has_leds)
return EventHandlerResult::OK;
//If already done or we're not in a ready state, bail //If already done or we're not in a ready state, bail
if (done_) { if (done_) {
return EventHandlerResult::OK; return EventHandlerResult::OK;

@ -21,6 +21,9 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
void LEDBreatheEffect::update(void) { void LEDBreatheEffect::update(void) {
if (!Kaleidoscope.has_leds)
return;
uint16_t now = Kaleidoscope.millisAtCycleStart(); uint16_t now = Kaleidoscope.millisAtCycleStart();
if ((now - last_update_) < UPDATE_INTERVAL) if ((now - last_update_) < UPDATE_INTERVAL)
return; return;

@ -19,6 +19,9 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
void LEDChaseEffect::update(void) { void LEDChaseEffect::update(void) {
if (!Kaleidoscope.has_leds)
return;
// Check to see if it's time to change the positions of the red and blue lights // Check to see if it's time to change the positions of the red and blue lights
if (current_chase_counter++ < chase_threshold) { if (current_chase_counter++ < chase_threshold) {
return; return;

@ -20,6 +20,9 @@ namespace kaleidoscope {
namespace plugin { namespace plugin {
void LEDRainbowEffect::update(void) { void LEDRainbowEffect::update(void) {
if (!Kaleidoscope.has_leds)
return;
uint16_t now = millis(); uint16_t now = millis();
if ((now - rainbow_last_update) < rainbow_update_delay) { if ((now - rainbow_last_update) < rainbow_update_delay) {
return; return;
@ -48,6 +51,9 @@ void LEDRainbowEffect::update_delay(byte delay) {
// --------- // ---------
void LEDRainbowWaveEffect::update(void) { void LEDRainbowWaveEffect::update(void) {
if (!Kaleidoscope.has_leds)
return;
uint16_t now = millis(); uint16_t now = millis();
if ((now - rainbow_last_update) < rainbow_update_delay) { if ((now - rainbow_last_update) < rainbow_update_delay) {
return; return;

Loading…
Cancel
Save