Merge pull request #432 from keyboardio/f/led_count/int8_t

hardware: ROWS, COLS, LED_COUNT and a bit of int8_t
pull/434/head
Jesse Vincent 6 years ago committed by GitHub
commit edee6bfcda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -37,6 +37,13 @@ void setup();
#include <stdint.h> #include <stdint.h>
#include KALEIDOSCOPE_HARDWARE_H #include KALEIDOSCOPE_HARDWARE_H
extern HARDWARE_IMPLEMENTATION KeyboardHardware;
#define ROWS (KeyboardHardware.matrix_rows)
#define COLS (KeyboardHardware.matrix_columns)
#define LED_COUNT (KeyboardHardware.led_count)
#include "kaleidoscope/key_events.h" #include "kaleidoscope/key_events.h"
#include "kaleidoscope/hid.h" #include "kaleidoscope/hid.h"
#include "kaleidoscope/layers.h" #include "kaleidoscope/layers.h"
@ -47,8 +54,6 @@ void setup();
#define HOOK_MAX 64 #define HOOK_MAX 64
extern HARDWARE_IMPLEMENTATION KeyboardHardware;
#ifndef VERSION #ifndef VERSION
#define VERSION "locally-built" #define VERSION "locally-built"
#endif #endif
@ -92,6 +97,8 @@ class Kaleidoscope_ {
void setup(void); void setup(void);
void loop(void); void loop(void);
static constexpr bool has_leds = (KeyboardHardware.led_count > 0);
/** Detaching from / attaching to the host. /** Detaching from / attaching to the host.
* *
* These two functions wrap the hardware plugin's similarly named functions. * These two functions wrap the hardware plugin's similarly named functions.

@ -37,10 +37,6 @@ struct cRGB {
uint8_t r, g, b; uint8_t r, g, b;
}; };
#define COLS 11
#define ROWS 4
#define LED_COUNT 0
#define CRGB(r,g,b) (cRGB){b, g, r} #define CRGB(r,g,b) (cRGB){b, g, r}
namespace kaleidoscope { namespace kaleidoscope {
@ -50,14 +46,18 @@ class Atreus {
public: public:
Atreus(void) {} Atreus(void) {}
static constexpr byte matrix_columns = 11;
static constexpr byte matrix_rows = 4;
static constexpr int8_t led_count = 0;
void syncLeds(void) {} void syncLeds(void) {}
void setCrgbAt(byte row, byte col, cRGB color) {} void setCrgbAt(byte row, byte col, cRGB color) {}
void setCrgbAt(uint8_t i, cRGB crgb) {} void setCrgbAt(int8_t i, cRGB crgb) {}
cRGB getCrgbAt(uint8_t i) { cRGB getCrgbAt(int8_t i) {
return CRGB(0, 0, 0); return CRGB(0, 0, 0);
} }
uint8_t getLedIndex(byte row, byte col) { int8_t getLedIndex(byte row, byte col) {
return 0; return -1;
} }
void scanMatrix(void); void scanMatrix(void);
@ -127,16 +127,16 @@ class Atreus {
static uint8_t debounce; static uint8_t debounce;
private: private:
static uint16_t previousKeyState_[ROWS]; static uint16_t previousKeyState_[matrix_rows];
static uint16_t keyState_[ROWS]; static uint16_t keyState_[matrix_rows];
static uint16_t masks_[ROWS]; static uint16_t masks_[matrix_rows];
static void readMatrixRow(uint8_t row); static void readMatrixRow(uint8_t row);
static uint16_t readCols(); static uint16_t readCols();
static void selectRow(uint8_t row); static void selectRow(uint8_t row);
static void unselectRow(uint8_t row); static void unselectRow(uint8_t row);
static uint8_t debounce_matrix_[ROWS][COLS]; static uint8_t debounce_matrix_[matrix_rows][matrix_columns];
static uint16_t debounceMaskForRow(uint8_t row); static uint16_t debounceMaskForRow(uint8_t row);
static void debounceRow(uint16_t change, uint8_t row); static void debounceRow(uint16_t change, uint8_t row);
}; };
@ -183,7 +183,7 @@ class Atreus {
* user-facing code. * user-facing code.
*/ */
constexpr byte keyIndex(byte row, byte col) { constexpr byte keyIndex(byte row, byte col) {
return row * COLS + col + 1; return row * kaleidoscope::hardware::Atreus::matrix_columns + col + 1;
} }
constexpr byte R0C0 = keyIndex(0, 0); constexpr byte R0C0 = keyIndex(0, 0);

@ -40,10 +40,6 @@ struct cRGB {
uint8_t r, g, b; uint8_t r, g, b;
}; };
#define COLS 6
#define ROWS 14
#define LED_COUNT 0
#define CRGB(r,g,b) (cRGB){b, g, r} #define CRGB(r,g,b) (cRGB){b, g, r}
namespace kaleidoscope { namespace kaleidoscope {
@ -53,14 +49,18 @@ class ErgoDox {
public: public:
ErgoDox(void) {} ErgoDox(void) {}
static constexpr byte matrix_columns = 6;
static constexpr byte matrix_rows = 14;
static constexpr int8_t led_count = 0;
void syncLeds(void) {} void syncLeds(void) {}
void setCrgbAt(byte row, byte col, cRGB color) {} void setCrgbAt(byte row, byte col, cRGB color) {}
void setCrgbAt(uint8_t i, cRGB crgb) {} void setCrgbAt(int8_t i, cRGB crgb) {}
cRGB getCrgbAt(uint8_t i) { cRGB getCrgbAt(int8_t i) {
return CRGB(0, 0, 0); return CRGB(0, 0, 0);
} }
uint8_t getLedIndex(byte row, byte col) { int8_t getLedIndex(byte row, byte col) {
return 0; return -1;
} }
void scanMatrix(void); void scanMatrix(void);
@ -135,10 +135,10 @@ class ErgoDox {
private: private:
static ErgoDoxScanner scanner_; static ErgoDoxScanner scanner_;
static uint8_t previousKeyState_[ROWS]; static uint8_t previousKeyState_[matrix_rows];
static uint8_t keyState_[ROWS]; static uint8_t keyState_[matrix_rows];
static uint8_t masks_[ROWS]; static uint8_t masks_[matrix_rows];
static uint8_t debounce_matrix_[ROWS][COLS]; static uint8_t debounce_matrix_[matrix_rows][matrix_columns];
static uint8_t debounceMaskForRow(uint8_t row); static uint8_t debounceMaskForRow(uint8_t row);
static void debounceRow(uint8_t change, uint8_t row); static void debounceRow(uint8_t change, uint8_t row);
@ -196,7 +196,7 @@ class ErgoDox {
* user-facing code. * user-facing code.
*/ */
constexpr byte keyIndex(byte row, byte col) { constexpr byte keyIndex(byte row, byte col) {
return row * COLS + col + 1; return row * kaleidoscope::hardware::ErgoDox::matrix_columns + col + 1;
} }
constexpr byte R0C0 = keyIndex(0, 0); constexpr byte R0C0 = keyIndex(0, 0);

@ -30,7 +30,7 @@ bool Model01::isLEDChanged = true;
keydata_t Model01::leftHandMask; keydata_t Model01::leftHandMask;
keydata_t Model01::rightHandMask; keydata_t Model01::rightHandMask;
static constexpr uint8_t key_led_map[4][16] PROGMEM = { static constexpr int8_t key_led_map[4][16] PROGMEM = {
{3, 4, 11, 12, 19, 20, 26, 27, 36, 37, 43, 44, 51, 52, 59, 60}, {3, 4, 11, 12, 19, 20, 26, 27, 36, 37, 43, 44, 51, 52, 59, 60},
{2, 5, 10, 13, 18, 21, 25, 28, 35, 38, 42, 45, 50, 53, 58, 61}, {2, 5, 10, 13, 18, 21, 25, 28, 35, 38, 42, 45, 50, 53, 58, 61},
{1, 6, 9, 14, 17, 22, 24, 29, 34, 39, 41, 46, 49, 54, 57, 62}, {1, 6, 9, 14, 17, 22, 24, 29, 34, 39, 41, 46, 49, 54, 57, 62},
@ -85,7 +85,7 @@ void Model01::setup(void) {
} }
void Model01::setCrgbAt(uint8_t i, cRGB crgb) { void Model01::setCrgbAt(int8_t i, cRGB crgb) {
if (i < 32) { if (i < 32) {
cRGB oldColor = getCrgbAt(i); cRGB oldColor = getCrgbAt(i);
isLEDChanged |= !(oldColor.r == crgb.r && oldColor.g == crgb.g && oldColor.b == crgb.b); isLEDChanged |= !(oldColor.r == crgb.r && oldColor.g == crgb.g && oldColor.b == crgb.b);
@ -107,11 +107,11 @@ void Model01::setCrgbAt(byte row, byte col, cRGB color) {
setCrgbAt(getLedIndex(row, col), color); setCrgbAt(getLedIndex(row, col), color);
} }
uint8_t Model01::getLedIndex(byte row, byte col) { int8_t Model01::getLedIndex(byte row, byte col) {
return pgm_read_byte(&(key_led_map[row][col])); return pgm_read_byte(&(key_led_map[row][col]));
} }
cRGB Model01::getCrgbAt(uint8_t i) { cRGB Model01::getCrgbAt(int8_t i) {
if (i < 32) { if (i < 32) {
return leftHand.ledData.leds[i]; return leftHand.ledData.leds[i];
} else if (i < 64) { } else if (i < 64) {

@ -27,9 +27,6 @@
#include "kaleidoscope/macro_helpers.h" #include "kaleidoscope/macro_helpers.h"
#define COLS 16
#define ROWS 4
#define CRGB(r,g,b) (cRGB){b, g, r} #define CRGB(r,g,b) (cRGB){b, g, r}
namespace kaleidoscope { namespace kaleidoscope {
@ -38,11 +35,16 @@ namespace hardware {
class Model01 { class Model01 {
public: public:
Model01(void); Model01(void);
static constexpr byte matrix_rows = 4;
static constexpr byte matrix_columns = 16;
static constexpr int8_t led_count = 64;
void syncLeds(void); void syncLeds(void);
void setCrgbAt(byte row, byte col, cRGB color); void setCrgbAt(byte row, byte col, cRGB color);
void setCrgbAt(uint8_t i, cRGB crgb); void setCrgbAt(int8_t i, cRGB crgb);
cRGB getCrgbAt(uint8_t i); cRGB getCrgbAt(int8_t i);
uint8_t getLedIndex(byte row, byte col); int8_t getLedIndex(byte row, byte col);
void scanMatrix(void); void scanMatrix(void);
void readMatrix(void); void readMatrix(void);
@ -50,7 +52,6 @@ class Model01 {
void setup(); void setup();
void rebootBootloader(); void rebootBootloader();
/** Detaching from / attaching to the host. /** Detaching from / attaching to the host.
* *
* These two functions should detach the device from (or attach it to) the * These two functions should detach the device from (or attach it to) the
@ -147,7 +148,7 @@ class Model01 {
* user-facing code. * user-facing code.
*/ */
constexpr byte keyIndex(byte row, byte col) { constexpr byte keyIndex(byte row, byte col) {
return row * COLS + col + 1; return row * kaleidoscope::hardware::Model01::matrix_columns + col + 1;
} }
constexpr byte R0C0 = keyIndex(0, 0); constexpr byte R0C0 = keyIndex(0, 0);
@ -216,9 +217,6 @@ constexpr byte R3C13 = keyIndex(3, 13);
constexpr byte R3C14 = keyIndex(3, 14); constexpr byte R3C14 = keyIndex(3, 14);
constexpr byte R3C15 = keyIndex(3, 15); constexpr byte R3C15 = keyIndex(3, 15);
#define LED_COUNT 64
#endif /* DOXYGEN_SHOULD_SKIP_THIS */ #endif /* DOXYGEN_SHOULD_SKIP_THIS */

@ -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;
@ -109,12 +112,12 @@ void LEDControl::set_all_leds_to(uint8_t r, uint8_t g, uint8_t b) {
} }
void LEDControl::set_all_leds_to(cRGB color) { void LEDControl::set_all_leds_to(cRGB color) {
for (uint8_t i = 0; i < LED_COUNT; i++) { for (int8_t i = 0; i < LED_COUNT; i++) {
setCrgbAt(i, color); setCrgbAt(i, color);
} }
} }
void LEDControl::setCrgbAt(uint8_t i, cRGB crgb) { void LEDControl::setCrgbAt(int8_t i, cRGB crgb) {
KeyboardHardware.setCrgbAt(i, crgb); KeyboardHardware.setCrgbAt(i, crgb);
} }
@ -122,7 +125,7 @@ void LEDControl::setCrgbAt(byte row, byte col, cRGB color) {
KeyboardHardware.setCrgbAt(row, col, color); KeyboardHardware.setCrgbAt(row, col, color);
} }
cRGB LEDControl::getCrgbAt(uint8_t i) { cRGB LEDControl::getCrgbAt(int8_t i) {
return KeyboardHardware.getCrgbAt(i); return KeyboardHardware.getCrgbAt(i);
} }
@ -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"
@ -249,7 +255,7 @@ EventHandlerResult FocusLEDCommand::onFocusEvent(const char *command) {
} }
case THEME: { case THEME: {
if (Serial.peek() == '\n') { if (Serial.peek() == '\n') {
for (uint8_t idx = 0; idx < LED_COUNT; idx++) { for (int8_t idx = 0; idx < LED_COUNT; idx++) {
cRGB c = ::LEDControl.getCrgbAt(idx); cRGB c = ::LEDControl.getCrgbAt(idx);
::Focus.printColor(c.r, c.g, c.b); ::Focus.printColor(c.r, c.g, c.b);
@ -259,7 +265,7 @@ EventHandlerResult FocusLEDCommand::onFocusEvent(const char *command) {
break; break;
} }
uint8_t idx = 0; int8_t idx = 0;
while (idx < LED_COUNT && Serial.peek() != '\n') { while (idx < LED_COUNT && Serial.peek() != '\n') {
cRGB color; cRGB color;

@ -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;
@ -130,9 +139,9 @@ class LEDControl : public kaleidoscope::Plugin {
static int8_t mode_add(LEDMode *mode); static int8_t mode_add(LEDMode *mode);
static void setCrgbAt(uint8_t i, cRGB crgb); static void setCrgbAt(int8_t i, cRGB crgb);
static void setCrgbAt(byte row, byte col, cRGB color); static void setCrgbAt(byte row, byte col, cRGB color);
static cRGB getCrgbAt(uint8_t i); static cRGB getCrgbAt(int8_t i);
static void syncLeds(void); static void syncLeds(void);
static void set_all_leds_to(uint8_t r, uint8_t g, uint8_t b); static void set_all_leds_to(uint8_t r, uint8_t g, uint8_t b);

@ -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;
@ -27,7 +30,7 @@ void LEDChaseEffect::update(void) {
// The red LED is at `pos`; the blue one follows behind. `chase_sign` is either +1 or // The red LED is at `pos`; the blue one follows behind. `chase_sign` is either +1 or
// -1; `chase_pixels` is the gap between them. // -1; `chase_pixels` is the gap between them.
byte pos2 = pos - (chase_sign * chase_pixels); int8_t pos2 = pos - (chase_sign * chase_pixels);
// First, we turn off the LEDs that were turned on in the previous update. `pos` is // First, we turn off the LEDs that were turned on in the previous update. `pos` is
// always in the valid range (0 <= pos < LED_COUNT), but after it changes direction, for // always in the valid range (0 <= pos < LED_COUNT), but after it changes direction, for

@ -28,7 +28,7 @@ class LEDChaseEffect : public LEDMode {
void update(void) final; void update(void) final;
private: private:
uint8_t pos = 0; int8_t pos = 0;
int8_t chase_sign = 1; //negative values when it's going backwar int8_t chase_sign = 1; //negative values when it's going backwar
uint8_t chase_pixels = 5; uint8_t chase_pixels = 5;
uint8_t current_chase_counter = 0; uint8_t current_chase_counter = 0;

@ -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;
@ -55,7 +61,7 @@ void LEDRainbowWaveEffect::update(void) {
rainbow_last_update = now; rainbow_last_update = now;
} }
for (uint8_t i = 0; i < LED_COUNT; i++) { for (int8_t i = 0; i < LED_COUNT; i++) {
uint16_t key_hue = rainbow_hue + 16 * (i / 4); uint16_t key_hue = rainbow_hue + 16 * (i / 4);
if (key_hue >= 255) { if (key_hue >= 255) {
key_hue -= 255; key_hue -= 255;

Loading…
Cancel
Save