keyboardio/Kaleidoscope-Focus

Name: Kaleidoscope-Focus

Owner: Keyboardio

Description: Bidirectional communications plugin for Kaleidoscope

Created: 2017-02-25 16:22:03.0

Updated: 2018-05-15 05:09:14.0

Pushed: 2018-05-15 05:09:16.0

Homepage: null

Size: 46

Language: C++

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Kaleidoscope-Focus

status Build Status

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.

Using the plugin

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:

lude <Kaleidoscope.h>
lude <Kaleidoscope-Focus.h>

IDOSCOPE_INIT_PLUGINS(Focus);

 setup () {
rial.begin (9600);

leidoscope.setup ();

cus.addHook (FOCUS_HOOK_HELP);
cus.addHook (FOCUS_HOOK_VERSION);

Plugin methods

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 return true, otherwise false. 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 the help command, and can be left empty, if no documentation is desired for the function.

Focus commands

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.

Wire protocol

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:

These are merely guidelines, and there can be - and are - exceptions. Use your discretion when writing Focus hooks.

Example

In the examples below, < denotes what the host sends to the keyboard, > what the keyboard responds.

rsion
leidoscope/locally-built Keyboardio/Model 01 | Jun 14 2017 11:22:19


lp
lp
rsion


lette
0 0 128 128 128 255 255 255

lette 0 0 0 128 128 128 255 255 255

Further reading

Starting from the example is the recommended way of getting started with the plugin.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.