Instead of returning a bool, to signal whether further processing should be
done, return a Key. Reason being, if we want to replace a key with another, for
subsequent handlers, it is a lot easier if we can modify what gets passed along,
than it is to inject a key, and try to avoid loops and infinite recursion.
Nevertheless, injecting keys is still possible.
This is not immediately useful for the core firmware, but makes it trivially
easy to upgrade keys from their normal behaviour to something special: for
example, a one-shot handler can auto-promote modifiers to one-shot, simply by
scheduling a promoter handler before the real one.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Introduces the RESERVED bit, a bit reserved for plugins. If it is set, the core
handlers will not handle the event.
Also rearranges the SYNTHETIC bits, to make slightly more sense. In practice,
this means that LED_TOGGLE was promoted to a flag bit, under IS_INTERNAL.
The handler that deals with synthetic events was updated to look at the flag
bits in an order that does not cause confusion, and preparations were also made
to turn it into an independent handler on its own (but that step has not been
taken yet).
This is just groundwork to clean things up, and make the event flow easier to
follow.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
The macro handler should only catch things that were meant to be its stuff, and
should only act on keypress, not all kinds of key events.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
We can't register hooks from constructors, because there is no guaranteed order
in which the objects will be created. So it may well happen that the Keyboardio
object gets created later, and zeroes out everything. Or it gets created first,
and registers the default handler as the first one, making all the others
pointless.
Instead, we create a KeyboardioPlugin class, that has a `begin` method. This is
responsible for setting up the hooks and whatnot. To make things simpler (for
some values of simple), a `Keyboardio.use` method is introduced, which, when
given a NULL-terminated list of plugin object pointers, will call the begin
method of each.
All LED effects and other plugins that used to register a static object now use
an extern, and had their initialization moved to the `begin` method.
The end result is not the nicest thing, but it works. We can try figuring out
something nicer later.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Add a `MACRODOWN` convenience macro, that will only run the given macro
when the key toggled on. It assumes that it is called from a function
with a `keyState` argument. If the key is not pressed, the macro will
evaluate to `MACRO_NONE`.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
`Dr`, `Ur`, and `Tr` are similar to the already existing `D`, `U`, and
`T` helpers, but they do not prefix their argument with `Key_`. This
makes it a lot easier to create macros that use custom key codes.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Keys that have the IS_INTERNAL flag set can also have the same bit set as the
IS_MACRO bit, yet, we do not want to handle those as if they were macros. So
teach `handleMacroEvent` to skip keys with that bit set.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Use dot_a_linkage for the Keyboardio-Macros library, and as a
consequence, declare the Macros variable static instead of extern, so
that it gets compiled and linked in even when not referenced directly.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Instead of trying to include an uint16_t in an array of uint8_ts, add the flags
and the rawKey separately. Without this, macro playback would not work, because
the sequence would be corrupt.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
The main thing here is `Macros_::play`, which takes a list of bytes from
PROGMEM, and plays a macro. The array is always a command, followed by
arguments, and the size of the argument depends on the command: key presses and
releases take a 16-bit argument, and the event is injected into the event
handler flow. Waiting and interval change take a 8-bit time. Helpers are
provided to make it a little bit easier to construct a macro.
Of course, the `macroAction` method may do any other side effects, and is not
restricted to returning a sequence of commands.
Fixes#5.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>