Migrate to the new onFocusEvent APIs

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/365/head
Gergely Nagy 6 years ago
parent e525aef803
commit 7ae4cae1e1

@ -15,7 +15,7 @@
*/ */
#include "Kaleidoscope-LEDControl.h" #include "Kaleidoscope-LEDControl.h"
#include "Kaleidoscope-Focus.h" #include "Kaleidoscope-FocusSerial.h"
namespace kaleidoscope { namespace kaleidoscope {
@ -175,7 +175,7 @@ kaleidoscope::EventHandlerResult LEDControl::beforeReportingState(void) {
return kaleidoscope::EventHandlerResult::OK; return kaleidoscope::EventHandlerResult::OK;
} }
bool LEDControl::focusHook(const char *command) { EventHandlerResult FocusLEDCommand::onFocusEvent(const char *command) {
enum { enum {
SETALL, SETALL,
MODE, MODE,
@ -183,8 +183,14 @@ bool LEDControl::focusHook(const char *command) {
THEME, THEME,
} subCommand; } subCommand;
if (::Focus.handleHelp(command, PSTR("led.at\n"
"led.setAll\n"
"led.mode\n"
"led.theme")))
return EventHandlerResult::OK;
if (strncmp_P(command, PSTR("led."), 4) != 0) if (strncmp_P(command, PSTR("led."), 4) != 0)
return false; return EventHandlerResult::OK;
if (strcmp_P(command + 4, PSTR("at")) == 0) if (strcmp_P(command + 4, PSTR("at")) == 0)
subCommand = AT; subCommand = AT;
else if (strcmp_P(command + 4, PSTR("setAll")) == 0) else if (strcmp_P(command + 4, PSTR("setAll")) == 0)
@ -194,14 +200,14 @@ bool LEDControl::focusHook(const char *command) {
else if (strcmp_P(command + 4, PSTR("theme")) == 0) else if (strcmp_P(command + 4, PSTR("theme")) == 0)
subCommand = THEME; subCommand = THEME;
else else
return false; return EventHandlerResult::OK;
switch (subCommand) { switch (subCommand) {
case AT: { case AT: {
uint8_t idx = Serial.parseInt(); uint8_t idx = Serial.parseInt();
if (Serial.peek() == '\n') { if (Serial.peek() == '\n') {
cRGB c = getCrgbAt(idx); cRGB c = ::LEDControl.getCrgbAt(idx);
::Focus.printColor(c.r, c.g, c.b); ::Focus.printColor(c.r, c.g, c.b);
Serial.println(); Serial.println();
@ -210,7 +216,7 @@ bool LEDControl::focusHook(const char *command) {
::Focus.readColor(c); ::Focus.readColor(c);
setCrgbAt(idx, c); ::LEDControl.setCrgbAt(idx, c);
} }
break; break;
} }
@ -219,31 +225,31 @@ bool LEDControl::focusHook(const char *command) {
::Focus.readColor(c); ::Focus.readColor(c);
set_all_leds_to(c); ::LEDControl.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(get_mode_index()); Serial.println(::LEDControl.get_mode_index());
} else if (peek == 'n') { } else if (peek == 'n') {
next_mode(); ::LEDControl.next_mode();
Serial.read(); Serial.read();
} else if (peek == 'p') { } else if (peek == 'p') {
prev_mode(); ::LEDControl.prev_mode();
Serial.read(); Serial.read();
} else { } else {
uint8_t mode = Serial.parseInt(); uint8_t mode = Serial.parseInt();
set_mode(mode); ::LEDControl.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 = getCrgbAt(idx); cRGB c = ::LEDControl.getCrgbAt(idx);
::Focus.printColor(c.r, c.g, c.b); ::Focus.printColor(c.r, c.g, c.b);
::Focus.printSpace(); ::Focus.printSpace();
@ -258,16 +264,17 @@ bool LEDControl::focusHook(const char *command) {
::Focus.readColor(color); ::Focus.readColor(color);
setCrgbAt(idx, color); ::LEDControl.setCrgbAt(idx, color);
idx++; idx++;
} }
break; break;
} }
} }
return true; return EventHandlerResult::EVENT_CONSUMED;
} }
} }
kaleidoscope::LEDControl LEDControl; kaleidoscope::LEDControl LEDControl;
kaleidoscope::FocusLEDCommand FocusLEDCommand;

@ -142,8 +142,6 @@ class LEDControl : public kaleidoscope::Plugin {
static uint16_t syncDelay; static uint16_t syncDelay;
static bool paused; static bool paused;
static bool focusHook(const char *command);
kaleidoscope::EventHandlerResult onSetup(); kaleidoscope::EventHandlerResult onSetup();
kaleidoscope::EventHandlerResult onKeyswitchEvent(Key &mappedKey, byte row, byte col, uint8_t keyState); kaleidoscope::EventHandlerResult onKeyswitchEvent(Key &mappedKey, byte row, byte col, uint8_t keyState);
kaleidoscope::EventHandlerResult beforeReportingState(); kaleidoscope::EventHandlerResult beforeReportingState();
@ -154,12 +152,14 @@ class LEDControl : public kaleidoscope::Plugin {
static uint8_t mode; static uint8_t mode;
}; };
class FocusLEDCommand : public Plugin {
public:
FocusLEDCommand() {}
EventHandlerResult onFocusEvent(const char *command);
};
} }
extern kaleidoscope::LEDControl LEDControl; extern kaleidoscope::LEDControl LEDControl;
extern kaleidoscope::FocusLEDCommand FocusLEDCommand;
#define FOCUS_HOOK_LEDCONTROL FOCUS_HOOK (LEDControl.focusHook, \
"led.at\n" \
"led.setAll\n" \
"led.theme\n" \
"led.mode")

Loading…
Cancel
Save