From a5afaf1eb47470348348de5b4acbb839b9c20a5e Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Wed, 21 Sep 2022 11:53:48 +0200 Subject: [PATCH] FocusSerial: Documentation update Updates for the FocusSerial documentation, showing the new patterns, and documenting the new methods. Signed-off-by: Gergely Nagy --- plugins/Kaleidoscope-FocusSerial/README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/plugins/Kaleidoscope-FocusSerial/README.md b/plugins/Kaleidoscope-FocusSerial/README.md index 1e529887..3a216f20 100644 --- a/plugins/Kaleidoscope-FocusSerial/README.md +++ b/plugins/Kaleidoscope-FocusSerial/README.md @@ -25,7 +25,12 @@ class FocusTestCommand : public Plugin { } EventHandlerResult onFocusEvent(const char *input) { - if (!::Focus.inputMatchesCommand(input, PSTR("test"))) + const char *cmd = PSTR("test"); + + if (::Focus.inputMatchesHelp(input)) + return ::Focus.printHelp(cmd); + + if (!::Focus.inputMatchesCommand(input, cmd)) return EventHandlerResult::OK; ::Focus.send(F("Congratulations, the test command works!")); @@ -47,6 +52,18 @@ void setup () { The plugin provides the `Focus` object, with a couple of helper methods aimed at developers. Terminating the response with a dot on its own line is handled implicitly by `FocusSerial`, one does not need to do that explicitly. +### `.inputMatchesHelp(input)` + +Returns `true` if the given `input` matches the `help` command. To be used at the top of `onFocusEvent()`, followed by `.printHelp(...)`. + +### `.printHelp(...)` + +Given a series of strings (stored in `PROGMEM`, via `PSTR()`), prints them one per line. Assumes it is run as part of handling the `help` command. Returns `EventHandlerResult::OK`. + +### `.inputMatchesCommand(input, command)` + +Returns `true` if the `input` matches the expected `command`, false otherwise. A convenience function over `strcmp_P()`. + ### `.send(...)` ### `.sendRaw(...)`