From e78b63deae5d25667765987c0ed58a3fa7e24aba Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 25 Dec 2016 09:18:22 +0100 Subject: [PATCH] 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 --- src/KeyboardioFirmware.cpp | 8 +++++++- src/LED-Numlock.cpp | 5 ++++- src/LED-Numlock.h | 2 +- src/hooks.h | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/KeyboardioFirmware.cpp b/src/KeyboardioFirmware.cpp index 94dce80f..82315e37 100644 --- a/src/KeyboardioFirmware.cpp +++ b/src/KeyboardioFirmware.cpp @@ -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); } } diff --git a/src/LED-Numlock.cpp b/src/LED-Numlock.cpp index 0f6df86d..354390b7 100644 --- a/src/LED-Numlock.cpp +++ b/src/LED-Numlock.cpp @@ -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 (); diff --git a/src/LED-Numlock.h b/src/LED-Numlock.h index 0c64aa7d..d104f0be 100644 --- a/src/LED-Numlock.h +++ b/src/LED-Numlock.h @@ -13,7 +13,7 @@ class LEDNumlock : LEDMode { virtual void setup (void) final; private: - static void loopHook (void); + static void loopHook (bool postClear); BreathState breathState; }; diff --git a/src/hooks.h b/src/hooks.h index 2499174b..464b4727 100644 --- a/src/hooks.h +++ b/src/hooks.h @@ -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);