Add a method to ease handling the `help` command

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/365/head
Gergely Nagy 6 years ago
parent 4f8c6332f7
commit 80566ca5a1

@ -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;
}

@ -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(" "));
}

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

Loading…
Cancel
Save