|
|
@ -1,83 +1,77 @@
|
|
|
|
#include "Kaleidoscope-LEDControl.h"
|
|
|
|
#include "Kaleidoscope-LEDControl.h"
|
|
|
|
#include "Kaleidoscope-Focus.h"
|
|
|
|
#include "Kaleidoscope-Focus.h"
|
|
|
|
|
|
|
|
|
|
|
|
LEDMode *LEDControl_::modes[LED_MAX_MODES];
|
|
|
|
namespace kaleidoscope {
|
|
|
|
uint8_t LEDControl_::previousMode, LEDControl_::mode;
|
|
|
|
|
|
|
|
uint16_t LEDControl_::syncDelay = 16;
|
|
|
|
|
|
|
|
uint32_t LEDControl_::syncTimer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
LEDMode *LEDControl::modes[LED_MAX_MODES];
|
|
|
|
LEDMode::activate(void) {
|
|
|
|
uint8_t LEDControl::mode;
|
|
|
|
LEDControl.activate(this);
|
|
|
|
uint16_t LEDControl::syncDelay = 16;
|
|
|
|
|
|
|
|
uint32_t LEDControl::syncTimer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LEDMode::activate(void) {
|
|
|
|
|
|
|
|
::LEDControl.activate(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void LEDMode::begin(void) {
|
|
|
|
LEDMode::begin(void) {
|
|
|
|
Kaleidoscope.use(&::LEDControl);
|
|
|
|
Kaleidoscope.use(&LEDControl, NULL);
|
|
|
|
::LEDControl.mode_add(this);
|
|
|
|
LEDControl.mode_add(this);
|
|
|
|
setup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LEDControl_::LEDControl_(void) {
|
|
|
|
LEDControl::LEDControl(void) {
|
|
|
|
mode = previousMode = 0;
|
|
|
|
mode = 0;
|
|
|
|
memset(modes, 0, LED_MAX_MODES * sizeof(modes[0]));
|
|
|
|
memset(modes, 0, LED_MAX_MODES * sizeof(modes[0]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void LEDControl::next_mode(void) {
|
|
|
|
LEDControl_::next_mode(void) {
|
|
|
|
|
|
|
|
mode++;
|
|
|
|
mode++;
|
|
|
|
|
|
|
|
|
|
|
|
if (mode >= LED_MAX_MODES) {
|
|
|
|
if (mode >= LED_MAX_MODES || !modes[mode]) {
|
|
|
|
mode = 0;
|
|
|
|
return set_mode(0);
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (modes[mode])
|
|
|
|
return set_mode(mode);
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mode = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
#if 0
|
|
|
|
LEDControl_::update(void) {
|
|
|
|
void LEDControl::update(void) {
|
|
|
|
if (previousMode != mode) {
|
|
|
|
|
|
|
|
set_all_leds_to({0, 0, 0});
|
|
|
|
|
|
|
|
if (modes[mode])
|
|
|
|
|
|
|
|
(modes[mode]->init)();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (modes[mode])
|
|
|
|
if (modes[mode])
|
|
|
|
(modes[mode]->update)();
|
|
|
|
(modes[mode]->update)();
|
|
|
|
|
|
|
|
|
|
|
|
previousMode = mode;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void LEDControl::refreshAt(byte row, byte col) {
|
|
|
|
LEDControl_::init_mode(void) {
|
|
|
|
|
|
|
|
if (modes[mode])
|
|
|
|
if (modes[mode])
|
|
|
|
(modes[mode]->init)();
|
|
|
|
modes[mode]->refreshAt(row, col);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
LEDControl_::set_mode(uint8_t mode_) {
|
|
|
|
LEDControl::set_mode(uint8_t mode_) {
|
|
|
|
if (mode_ < LED_MAX_MODES)
|
|
|
|
if (mode_ >= LED_MAX_MODES)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set_all_leds_to({0, 0, 0});
|
|
|
|
mode = mode_;
|
|
|
|
mode = mode_;
|
|
|
|
|
|
|
|
if (modes[mode])
|
|
|
|
|
|
|
|
modes[mode]->onActivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t
|
|
|
|
uint8_t LEDControl::get_mode_index(void) {
|
|
|
|
LEDControl_::get_mode(void) {
|
|
|
|
|
|
|
|
return mode;
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
LEDMode *LEDControl::get_mode(void) {
|
|
|
|
LEDControl_::activate(LEDMode *mode) {
|
|
|
|
return modes[mode];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LEDControl::activate(LEDMode *mode) {
|
|
|
|
for (uint8_t i = 0; i < LED_MAX_MODES; i++) {
|
|
|
|
for (uint8_t i = 0; i < LED_MAX_MODES; i++) {
|
|
|
|
if (modes[i] == mode)
|
|
|
|
if (modes[i] == mode)
|
|
|
|
return set_mode(i);
|
|
|
|
return set_mode(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int8_t
|
|
|
|
int8_t LEDControl::mode_add(LEDMode *mode) {
|
|
|
|
LEDControl_::mode_add(LEDMode *mode) {
|
|
|
|
|
|
|
|
for (int i = 0; i < LED_MAX_MODES; i++) {
|
|
|
|
for (int i = 0; i < LED_MAX_MODES; i++) {
|
|
|
|
if (modes[i])
|
|
|
|
if (modes[i])
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
@ -88,8 +82,7 @@ LEDControl_::mode_add(LEDMode *mode) {
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void LEDControl::set_all_leds_to(uint8_t r, uint8_t g, uint8_t b) {
|
|
|
|
LEDControl_::set_all_leds_to(uint8_t r, uint8_t g, uint8_t b) {
|
|
|
|
|
|
|
|
cRGB color;
|
|
|
|
cRGB color;
|
|
|
|
color.r = r;
|
|
|
|
color.r = r;
|
|
|
|
color.g = g;
|
|
|
|
color.g = g;
|
|
|
@ -97,35 +90,29 @@ LEDControl_::set_all_leds_to(uint8_t r, uint8_t g, uint8_t b) {
|
|
|
|
set_all_leds_to(color);
|
|
|
|
set_all_leds_to(color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void LEDControl::set_all_leds_to(cRGB color) {
|
|
|
|
LEDControl_::set_all_leds_to(cRGB color) {
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
|
|
|
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
|
|
|
setCrgbAt(i, color);
|
|
|
|
setCrgbAt(i, color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void LEDControl::setCrgbAt(uint8_t i, cRGB crgb) {
|
|
|
|
LEDControl_::setCrgbAt(uint8_t i, cRGB crgb) {
|
|
|
|
|
|
|
|
KeyboardHardware.setCrgbAt(i, crgb);
|
|
|
|
KeyboardHardware.setCrgbAt(i, crgb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void LEDControl::setCrgbAt(byte row, byte col, cRGB color) {
|
|
|
|
LEDControl_::setCrgbAt(byte row, byte col, cRGB color) {
|
|
|
|
|
|
|
|
KeyboardHardware.setCrgbAt(row, col, color);
|
|
|
|
KeyboardHardware.setCrgbAt(row, col, color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cRGB
|
|
|
|
cRGB LEDControl::getCrgbAt(uint8_t i) {
|
|
|
|
LEDControl_::getCrgbAt(uint8_t i) {
|
|
|
|
|
|
|
|
return KeyboardHardware.getCrgbAt(i);
|
|
|
|
return KeyboardHardware.getCrgbAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void LEDControl::syncLeds(void) {
|
|
|
|
LEDControl_::syncLeds(void) {
|
|
|
|
|
|
|
|
KeyboardHardware.syncLeds();
|
|
|
|
KeyboardHardware.syncLeds();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void LEDControl::begin(void) {
|
|
|
|
LEDControl_::begin(void) {
|
|
|
|
|
|
|
|
set_all_leds_to({0, 0, 0});
|
|
|
|
set_all_leds_to({0, 0, 0});
|
|
|
|
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < LED_MAX_MODES; i++) {
|
|
|
|
for (uint8_t i = 0; i < LED_MAX_MODES; i++) {
|
|
|
@ -133,25 +120,23 @@ LEDControl_::begin(void) {
|
|
|
|
(modes[i]->setup)();
|
|
|
|
(modes[i]->setup)();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
event_handler_hook_use(eventHandler);
|
|
|
|
Kaleidoscope.useEventHandlerHook(eventHandler);
|
|
|
|
loop_hook_use(loopHook);
|
|
|
|
Kaleidoscope.useLoopHook(loopHook);
|
|
|
|
|
|
|
|
|
|
|
|
syncTimer = millis() + syncDelay;
|
|
|
|
syncTimer = millis() + syncDelay;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Key
|
|
|
|
Key LEDControl::eventHandler(Key mappedKey, byte row, byte col, uint8_t keyState) {
|
|
|
|
LEDControl_::eventHandler(Key mappedKey, byte row, byte col, uint8_t keyState) {
|
|
|
|
|
|
|
|
if (mappedKey.flags != (SYNTHETIC | IS_INTERNAL | LED_TOGGLE))
|
|
|
|
if (mappedKey.flags != (SYNTHETIC | IS_INTERNAL | LED_TOGGLE))
|
|
|
|
return mappedKey;
|
|
|
|
return mappedKey;
|
|
|
|
|
|
|
|
|
|
|
|
if (keyToggledOn(keyState))
|
|
|
|
if (keyToggledOn(keyState))
|
|
|
|
LEDControl.next_mode();
|
|
|
|
next_mode();
|
|
|
|
|
|
|
|
|
|
|
|
return Key_NoKey;
|
|
|
|
return Key_NoKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void LEDControl::loopHook(bool postClear) {
|
|
|
|
LEDControl_::loopHook(bool postClear) {
|
|
|
|
|
|
|
|
if (postClear)
|
|
|
|
if (postClear)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
@ -162,8 +147,7 @@ LEDControl_::loopHook(bool postClear) {
|
|
|
|
update();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
bool LEDControl::focusHook(const char *command) {
|
|
|
|
LEDControl_::focusHook(const char *command) {
|
|
|
|
|
|
|
|
enum {
|
|
|
|
enum {
|
|
|
|
SETALL,
|
|
|
|
SETALL,
|
|
|
|
MODE,
|
|
|
|
MODE,
|
|
|
@ -189,9 +173,9 @@ LEDControl_::focusHook(const char *command) {
|
|
|
|
uint8_t idx = Serial.parseInt();
|
|
|
|
uint8_t idx = Serial.parseInt();
|
|
|
|
|
|
|
|
|
|
|
|
if (Serial.peek() == '\n') {
|
|
|
|
if (Serial.peek() == '\n') {
|
|
|
|
cRGB c = LEDControl.getCrgbAt(idx);
|
|
|
|
cRGB c = getCrgbAt(idx);
|
|
|
|
|
|
|
|
|
|
|
|
Focus.printColor(c.r, c.g, c.b);
|
|
|
|
::Focus.printColor(c.r, c.g, c.b);
|
|
|
|
Serial.println();
|
|
|
|
Serial.println();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
cRGB c;
|
|
|
|
cRGB c;
|
|
|
@ -200,7 +184,7 @@ LEDControl_::focusHook(const char *command) {
|
|
|
|
c.g = Serial.parseInt();
|
|
|
|
c.g = Serial.parseInt();
|
|
|
|
c.b = Serial.parseInt();
|
|
|
|
c.b = Serial.parseInt();
|
|
|
|
|
|
|
|
|
|
|
|
LEDControl.setCrgbAt(idx, c);
|
|
|
|
setCrgbAt(idx, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -211,16 +195,16 @@ LEDControl_::focusHook(const char *command) {
|
|
|
|
c.g = Serial.parseInt();
|
|
|
|
c.g = Serial.parseInt();
|
|
|
|
c.b = Serial.parseInt();
|
|
|
|
c.b = Serial.parseInt();
|
|
|
|
|
|
|
|
|
|
|
|
LEDControl.set_all_leds_to(c);
|
|
|
|
set_all_leds_to(c);
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case MODE: {
|
|
|
|
case MODE: {
|
|
|
|
char peek = Serial.peek();
|
|
|
|
char peek = Serial.peek();
|
|
|
|
if (peek == '\n') {
|
|
|
|
if (peek == '\n') {
|
|
|
|
Serial.println(LEDControl.get_mode());
|
|
|
|
Serial.println(get_mode_index());
|
|
|
|
} else if (peek == 'n') {
|
|
|
|
} else if (peek == 'n') {
|
|
|
|
LEDControl.next_mode();
|
|
|
|
next_mode();
|
|
|
|
Serial.read();
|
|
|
|
Serial.read();
|
|
|
|
} else if (peek == 'p') {
|
|
|
|
} else if (peek == 'p') {
|
|
|
|
// TODO(algernon)
|
|
|
|
// TODO(algernon)
|
|
|
@ -228,17 +212,17 @@ LEDControl_::focusHook(const char *command) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
uint8_t mode = Serial.parseInt();
|
|
|
|
uint8_t mode = Serial.parseInt();
|
|
|
|
|
|
|
|
|
|
|
|
LEDControl.set_mode(mode);
|
|
|
|
set_mode(mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case THEME: {
|
|
|
|
case THEME: {
|
|
|
|
if (Serial.peek() == '\n') {
|
|
|
|
if (Serial.peek() == '\n') {
|
|
|
|
for (uint8_t idx = 0; idx < LED_COUNT; idx++) {
|
|
|
|
for (uint8_t idx = 0; idx < LED_COUNT; idx++) {
|
|
|
|
cRGB c = LEDControl.getCrgbAt(idx);
|
|
|
|
cRGB c = getCrgbAt(idx);
|
|
|
|
|
|
|
|
|
|
|
|
Focus.printColor(c.r, c.g, c.b);
|
|
|
|
::Focus.printColor(c.r, c.g, c.b);
|
|
|
|
Focus.printSpace();
|
|
|
|
::Focus.printSpace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Serial.println();
|
|
|
|
Serial.println();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -252,7 +236,7 @@ LEDControl_::focusHook(const char *command) {
|
|
|
|
color.g = Serial.parseInt();
|
|
|
|
color.g = Serial.parseInt();
|
|
|
|
color.b = Serial.parseInt();
|
|
|
|
color.b = Serial.parseInt();
|
|
|
|
|
|
|
|
|
|
|
|
LEDControl.setCrgbAt(idx, color);
|
|
|
|
setCrgbAt(idx, color);
|
|
|
|
idx++;
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -262,4 +246,6 @@ LEDControl_::focusHook(const char *command) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LEDControl_ LEDControl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kaleidoscope::LEDControl LEDControl;
|
|
|
|