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() {} FocusTestCommand() {}
EventHandlerResult onFocusEvent(const char *command) { 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!")); Serial.println(F("ok!"));
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }
if (strcmp_P(command, PSTR("help")) == 0) {
Serial.println(F("test"));
return EventHandlerResult::OK;
}
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
@ -63,10 +64,7 @@ class FocusHelpCommand : public Plugin {
FocusHelpCommand() {} FocusHelpCommand() {}
EventHandlerResult onFocusEvent(const char *command) { EventHandlerResult onFocusEvent(const char *command) {
if (strcmp_P(command, PSTR("help")) == 0) { ::Focus.handleHelp(command, PSTR("help"));
Serial.println(F("help"));
return EventHandlerResult::OK;
}
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }

@ -59,6 +59,15 @@ EventHandlerResult FocusSerial::beforeReportingState() {
return EventHandlerResult::OK; 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) { void FocusSerial::printSpace(void) {
Serial.print(F(" ")); Serial.print(F(" "));
} }

@ -24,6 +24,9 @@ class FocusSerial : public kaleidoscope::Plugin {
public: public:
FocusSerial(void) {} FocusSerial(void) {}
bool handleHelp(const char *command,
const char *help_message);
/* Helpers */ /* Helpers */
static void printNumber(uint16_t number); static void printNumber(uint16_t number);
static void printSpace(void); static void printSpace(void);

Loading…
Cancel
Save