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_rows = 4;
static constexpr uint8_t led_count = 0;
static constexpr int8_t led_count = 0;
void syncLeds(void) {}
void setCrgbAt(byte row, byte col, cRGB color) {}
void setCrgbAt(uint8_t i, cRGB crgb) {}
cRGB getCrgbAt(uint8_t i) {
void setCrgbAt(int8_t i, cRGB crgb) {}
cRGB getCrgbAt(int8_t i) {
return CRGB(0, 0, 0);
}
uint8_t getLedIndex(byte row, byte col) {
return 0;
int8_t getLedIndex(byte row, byte col) {
return -1;
}
void scanMatrix(void);

@ -51,16 +51,16 @@ class ErgoDox {
static constexpr byte matrix_columns = 6;
static constexpr byte matrix_rows = 14;
static constexpr uint8_t led_count = 0;
static constexpr int8_t led_count = 0;
void syncLeds(void) {}
void setCrgbAt(byte row, byte col, cRGB color) {}
void setCrgbAt(uint8_t i, cRGB crgb) {}
cRGB getCrgbAt(uint8_t i) {
void setCrgbAt(int8_t i, cRGB crgb) {}
cRGB getCrgbAt(int8_t i) {
return CRGB(0, 0, 0);
}
uint8_t getLedIndex(byte row, byte col) {
return 0;
int8_t getLedIndex(byte row, byte col) {
return -1;
}
void scanMatrix(void);

@ -30,7 +30,7 @@ bool Model01::isLEDChanged = true;
keydata_t Model01::leftHandMask;
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},
{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},
@ -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) {
cRGB oldColor = getCrgbAt(i);
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);
}
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]));
}
cRGB Model01::getCrgbAt(uint8_t i) {
cRGB Model01::getCrgbAt(int8_t i) {
if (i < 32) {
return leftHand.ledData.leds[i];
} else if (i < 64) {

@ -38,13 +38,13 @@ class Model01 {
static constexpr byte matrix_rows = 4;
static constexpr byte matrix_columns = 16;
static constexpr uint8_t led_count = 64;
static constexpr int8_t led_count = 64;
void syncLeds(void);
void setCrgbAt(byte row, byte col, cRGB color);
void setCrgbAt(uint8_t i, cRGB crgb);
cRGB getCrgbAt(uint8_t i);
uint8_t getLedIndex(byte row, byte col);
void setCrgbAt(int8_t i, cRGB crgb);
cRGB getCrgbAt(int8_t i);
int8_t getLedIndex(byte row, byte col);
void scanMatrix(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) {
for (uint8_t i = 0; i < LED_COUNT; i++) {
for (int8_t i = 0; i < LED_COUNT; i++) {
setCrgbAt(i, color);
}
}
void LEDControl::setCrgbAt(uint8_t i, cRGB crgb) {
void LEDControl::setCrgbAt(int8_t i, cRGB crgb) {
KeyboardHardware.setCrgbAt(i, crgb);
}
@ -125,7 +125,7 @@ void LEDControl::setCrgbAt(byte row, byte col, cRGB color) {
KeyboardHardware.setCrgbAt(row, col, color);
}
cRGB LEDControl::getCrgbAt(uint8_t i) {
cRGB LEDControl::getCrgbAt(int8_t i) {
return KeyboardHardware.getCrgbAt(i);
}
@ -255,7 +255,7 @@ EventHandlerResult FocusLEDCommand::onFocusEvent(const char *command) {
}
case THEME: {
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);
::Focus.printColor(c.r, c.g, c.b);
@ -265,7 +265,7 @@ EventHandlerResult FocusLEDCommand::onFocusEvent(const char *command) {
break;
}
uint8_t idx = 0;
int8_t idx = 0;
while (idx < LED_COUNT && Serial.peek() != '\n') {
cRGB color;

@ -139,9 +139,9 @@ class LEDControl : public kaleidoscope::Plugin {
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 cRGB getCrgbAt(uint8_t i);
static cRGB getCrgbAt(int8_t i);
static void syncLeds(void);
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
// -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
// 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;
private:
uint8_t pos = 0;
int8_t pos = 0;
int8_t chase_sign = 1; //negative values when it's going backwar
uint8_t chase_pixels = 5;
uint8_t current_chase_counter = 0;

@ -61,7 +61,7 @@ void LEDRainbowWaveEffect::update(void) {
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);
if (key_hue >= 255) {
key_hue -= 255;

Loading…
Cancel
Save