Add an optional Focus hook

Implements the `layer.on`, `layer.off`, and `layer.getState` commands, which can
be used to control the active layers from the host.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/122/head
Gergely Nagy 8 years ago
parent 1c468752c8
commit b66c17c77d

@ -97,4 +97,47 @@ Kaleidoscope_::useLoopHook(loopHook hook) {
appendLoopHook (hook); appendLoopHook (hook);
} }
bool
Kaleidoscope_::focusHook(const char *command) {
enum {
ON,
OFF,
GETSTATE,
} subCommand;
if (strncmp_P(command, PSTR("layer."), 6) != 0)
return false;
if (strcmp_P (command + 6, PSTR("on")) == 0)
subCommand = ON;
else if (strcmp_P(command + 6, PSTR("off")) == 0)
subCommand = OFF;
else if (strcmp_P(command + 6, PSTR("getState")) == 0)
subCommand = GETSTATE;
else
return false;
switch (subCommand) {
case ON:
{
uint8_t layer = Serial.parseInt();
Layer.on(layer);
break;
}
case OFF:
{
uint8_t layer = Serial.parseInt();
Layer.off(layer);
break;
}
case GETSTATE:
Serial.println(Layer.getLayerState(), BIN);
break;
}
return true;
}
Kaleidoscope_ Kaleidoscope; Kaleidoscope_ Kaleidoscope;

@ -94,10 +94,17 @@ class Kaleidoscope_ {
static void replaceLoopHook(loopHook oldHook, loopHook newHook); static void replaceLoopHook(loopHook oldHook, loopHook newHook);
static void appendLoopHook(loopHook hook); static void appendLoopHook(loopHook hook);
static void useLoopHook(loopHook hook); static void useLoopHook(loopHook hook);
static bool focusHook(const char *command);
}; };
extern Kaleidoscope_ Kaleidoscope; extern Kaleidoscope_ Kaleidoscope;
#define FOCUS_HOOK_KALEIDOSCOPE FOCUS_HOOK(Kaleidoscope.focusHook, \
"layer.on\n" \
"layer.off\n" \
"layer.getState")
/* -- DEPRECATED aliases; remove them when there are no more users. -- */ /* -- DEPRECATED aliases; remove them when there are no more users. -- */
#define event_handler_hook_use(hook) Kaleidoscope.useEventHandlerHook(hook); #define event_handler_hook_use(hook) Kaleidoscope.useEventHandlerHook(hook);

Loading…
Cancel
Save