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 mousekey handler was way too eager, and captured events that were not meant
to be handled by it, like the `a` key. This has been fixed by removing the
`KEY_MOUSE_CENTER` bit, and replacing it with `KEY_MOUSE_BUTTON`. That way,
everything fits into the `IS_MOUSE_KEY` flag bit.
While there, also fixed the id of the right mouse button.
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>
Instead of including `key_defs.h`, include `KeyboardioFirmware.h` in
`Keyboardio-MouseKeys.h`, so that the dependency is clear. This is
needed for the arduino-builder to arrange the linking order properly
when using KeyboardioFirmware, KeyboardioFirmware-MouseKeys and other
libraries combined. It does not affect the combination of just the two,
but if there's a third, that happens to include `KeyboardioFirmware.h`
too, this dependency is required for correct linking.
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>
When we mark a symbol extern, but do not reference it anywhere else
directly, it will not be compiled in when using dot_a_linkage. For this
reason, make MouseKeys a static variable instead of extern.
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 reason it was removed before no longer applies, and enabling it saves
noticeable amounts of size when using KeyboardioFirmware as a library.
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>
Instead of having a previousState and a currentState, of which at most
two bits are used, use a single byte. This saves us a lot of code space,
and makes a number of things easier, too.
The helpers were redone as macros, since they are just bit checks now.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
The mousekeys are not specific to the Model01, name it after Keyboardio
instead, as suggested by @obra.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
The primary reason for the move is to be able to disable mouse keys
completely, and not even compile them in. For this to work, it needs to
be in a separate library, otherwise it will always be included, even if
not active.
So, this patch turns mouse-keys into a simple plugin, included with the
core firmware! This makes the default event handler a bit simpler, the
code marginally smaller, and the feature completely optional.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>