diff --git a/examples/FocusSerial/FocusSerial.ino b/examples/FocusSerial/FocusSerial.ino index fcb8b280..c83910ca 100644 --- a/examples/FocusSerial/FocusSerial.ino +++ b/examples/FocusSerial/FocusSerial.ino @@ -45,14 +45,15 @@ class FocusTestCommand : public Plugin { FocusTestCommand() {} EventHandlerResult onFocusEvent(const char *command) { - if (strcmp_P(command, PSTR("test")) == 0) { + const char *cmd = PSTR("test"); + + if (::Focus.handleHelp(command, cmd)) + return EventHandlerResult::OK; + + if (strcmp_P(command, cmd) == 0) { Serial.println(F("ok!")); return EventHandlerResult::EVENT_CONSUMED; } - if (strcmp_P(command, PSTR("help")) == 0) { - Serial.println(F("test")); - return EventHandlerResult::OK; - } return EventHandlerResult::OK; } @@ -63,10 +64,7 @@ class FocusHelpCommand : public Plugin { FocusHelpCommand() {} EventHandlerResult onFocusEvent(const char *command) { - if (strcmp_P(command, PSTR("help")) == 0) { - Serial.println(F("help")); - return EventHandlerResult::OK; - } + ::Focus.handleHelp(command, PSTR("help")); return EventHandlerResult::OK; } diff --git a/src/kaleidoscope/FocusSerial.cpp b/src/kaleidoscope/FocusSerial.cpp index 3864df4f..7fb37525 100644 --- a/src/kaleidoscope/FocusSerial.cpp +++ b/src/kaleidoscope/FocusSerial.cpp @@ -59,6 +59,15 @@ EventHandlerResult FocusSerial::beforeReportingState() { return EventHandlerResult::OK; } +bool FocusSerial::handleHelp(const char *command, + const char *help_message) { + if (strcmp_P(command, PSTR("help")) != 0) + return false; + + Serial.println((const __FlashStringHelper *)help_message); + return true; +} + void FocusSerial::printSpace(void) { Serial.print(F(" ")); } diff --git a/src/kaleidoscope/FocusSerial.h b/src/kaleidoscope/FocusSerial.h index 8eeaec98..4e5613ea 100644 --- a/src/kaleidoscope/FocusSerial.h +++ b/src/kaleidoscope/FocusSerial.h @@ -24,6 +24,9 @@ class FocusSerial : public kaleidoscope::Plugin { public: FocusSerial(void) {} + bool handleHelp(const char *command, + const char *help_message); + /* Helpers */ static void printNumber(uint16_t number); static void printSpace(void);