Turn hardware::led_count into an int8_t

This allows us to do `i < LED_COUNT` comparisons on boards with no LEDs. All
places that did this comparison have been updated to use `int8_t`, as were all
places that use a LED index.

Together with the previous commits, fixes #385.

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

@ -48,16 +48,16 @@ class Atreus {
static constexpr byte matrix_columns = 11; static constexpr byte matrix_columns = 11;
static constexpr byte matrix_rows = 4; static constexpr byte matrix_rows = 4;
static constexpr uint8_t led_count = 0; 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);

@ -51,16 +51,16 @@ class ErgoDox {
static constexpr byte matrix_columns = 6; static constexpr byte matrix_columns = 6;
static constexpr byte matrix_rows = 14; static constexpr byte matrix_rows = 14;
static constexpr uint8_t led_count = 0; 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);

@ -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) {

@ -38,13 +38,13 @@ class Model01 {
static constexpr byte matrix_rows = 4; static constexpr byte matrix_rows = 4;
static constexpr byte matrix_columns = 16; static constexpr byte matrix_columns = 16;
static constexpr uint8_t led_count = 64; 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);

@ -112,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);
} }
@ -125,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);
} }
@ -255,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);
@ -265,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;

@ -139,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);

@ -30,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;

@ -61,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