Kaleidoscope
|
Bidirectional communication for Kaleidoscope. With this plugin, one can expose a set of commands via the Serial port, and allow the host to talk with the keyboard - and vice versa. This plugin implements only the basic building blocks, a framework other plugins can opt-in to.
This plugin is not meant to be used by the end-user (apart from setting it up to use plugin-provided hooks), but by plugin authors instead. As an end user, please see the documentation of the plugins you use, for instructions on how to hook them up with Focus
!
Nevertheless, the basic commands we implement with this plugin alone, are usable like this:
The plugin provides the Focus
object, which has the following method:
.addHook(FOCUS_HOOK (function, documentation))
Adds a new hook to
Focus
. Hooks are called in order of registration, and they get the parsed command name as argument. If they handle the command, they shall returntrue
, otherwisefalse
. Once a command has been handled, it will not be given to other hooks.The hook function is responsible for reading the rest of the command, in whatever way it sees fit.
The
documentation
argument is a string, used by thehelp
command, and can be left empty, if no documentation is desired for thefunction
.
The plugin ships with two (optional) hooks: FOCUS_HOOK_VERSION
, and FOCUS_HOOK_HELP
, implementing the following two commands, respectively:
version
Return the version of the firmware, the keyboard vendor & product, and the compile date.
help
Return the list of commands the keyboard supports.
Focus
uses a simple, textual, request-response-based wire protocol.
Each request has to be on one line, anything before the first space is the command part (if there is no space, just a newline, then the whole line will be considered a command), everything after are arguments. The plugin itself only parses until the end of the command part, argument parsing is left to the various hooks. If there is anything left on the line after hooks are done processing, it will be ignored.
Responses can be multi-line, but most aren't. Their content is also up to the hooks, Focus
does not enforce anything, except a trailing dot and a newline. Responses should end with a dot on its own line.
Apart from these, there are no restrictions on what can go over the wire, but to make the experience consistent, find a few guidelines below:
led.theme
, or led.setAll
.These are merely guidelines, and there can be - and are - exceptions. Use your discretion when writing Focus hooks.
In the examples below, <
denotes what the host sends to the keyboard, >
what the keyboard responds.
Starting from the example is the recommended way of getting started with the plugin.