Loop hooks: Run the loop hooks twice

Some behaviour would benefit from knowing the last report, some would want a
clear report and a way to pre-fill the next one. For this reason, we need two
places to call loop hooks from: one after scanning the matrix and updating LEDs,
and another after sending and clearing the report.

To save space and sanity, we call the same hooks twice, but the second time, we
set the `postClear` flag, which is false the first time.

All users have been updated.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/71/head
Gergely Nagy 8 years ago
parent 9800926446
commit e78b63deae

@ -24,12 +24,18 @@ void
Keyboardio_::loop(void) {
KeyboardHardware.scan_matrix();
LEDControl.update();
for (byte i = 0; loopHooks[i] != NULL && i < HOOK_MAX; i++) {
custom_loop_t hook = loopHooks[i];
(*hook)(false);
}
Keyboard.sendReport();
Keyboard.releaseAll();
for (byte i = 0; loopHooks[i] != NULL && i < HOOK_MAX; i++) {
custom_loop_t hook = loopHooks[i];
(*hook)();
(*hook)(true);
}
}

@ -40,7 +40,10 @@ LEDNumlock::update (void) {
}
void
LEDNumlock::loopHook (void) {
LEDNumlock::loopHook (bool postClear) {
if (!postClear)
return;
if (Layer.isOn (numpadIndex)) {
if (storedLEDMode != us) {
storedLEDMode = LEDControl.get_mode ();

@ -13,7 +13,7 @@ class LEDNumlock : LEDMode {
virtual void setup (void) final;
private:
static void loopHook (void);
static void loopHook (bool postClear);
BreathState breathState;
};

@ -11,7 +11,7 @@ extern custom_handler_t eventHandlers[HOOK_MAX];
void event_handler_hook_add (custom_handler_t hook);
void event_handler_hook_replace (custom_handler_t oldHook, custom_handler_t newHook);
typedef void (*custom_loop_t)(void);
typedef void (*custom_loop_t)(bool postClear);
extern custom_loop_t loopHooks[HOOK_MAX];
void loop_hook_add (custom_loop_t hook);

Loading…
Cancel
Save