From 7756be1a6d7e65fc7b13f0663873a9db79df813e Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Tue, 6 Apr 2021 14:17:10 -0500 Subject: [PATCH] Add `beforeSyncingLeds()` event handler hook function This allows plugins to override the current LED mode just before the LED sync is done (i.e. after the mode sets the LED colors, but before those changes are pushed to the hardware.) Signed-off-by: Michael Richters --- src/kaleidoscope/event_handlers.h | 13 +++++++++++++ src/kaleidoscope/plugin/LEDControl.cpp | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/src/kaleidoscope/event_handlers.h b/src/kaleidoscope/event_handlers.h index ae24ab01..b3765601 100644 --- a/src/kaleidoscope/event_handlers.h +++ b/src/kaleidoscope/event_handlers.h @@ -234,6 +234,15 @@ class SignatureCheckDummy {}; _NOT_ABORTABLE, __NL__ \ (),(),(), /* non template */ __NL__ \ (), (), ##__VA_ARGS__) __NL__ \ + /* Called immediately before the LEDs get updated. This is for */ __NL__ \ + /* plugins that override the current LED mode. */ __NL__ \ + OPERATION(beforeSyncingLeds, __NL__ \ + 1, __NL__ \ + _CURRENT_IMPLEMENTATION, __NL__ \ + _NOT_ABORTABLE, __NL__ \ + (),(),(), /* non template */ __NL__ \ + (), (), ##__VA_ARGS__) __NL__ \ + /* DEPRECATED */ __NL__ \ /* Called before reporting our state to the host. This is the */ __NL__ \ /* last point in a cycle where a plugin can alter what gets */ __NL__ \ /* reported to the host. */ __NL__ \ @@ -333,6 +342,10 @@ class SignatureCheckDummy {}; OP(onLEDModeChange, 1) __NL__ \ END(onLEDModeChange, 1) __NL__ \ __NL__ \ + START(beforeSyncingLeds, 1) __NL__ \ + OP(beforeSyncingLeds, 1) __NL__ \ + END(beforeSyncingLeds, 1) __NL__ \ + __NL__ \ START(beforeReportingState, 1, 2) __NL__ \ OP(beforeReportingState, 1) __NL__ \ OP(beforeReportingState, 2) __NL__ \ diff --git a/src/kaleidoscope/plugin/LEDControl.cpp b/src/kaleidoscope/plugin/LEDControl.cpp index ecebc803..c2d87bad 100644 --- a/src/kaleidoscope/plugin/LEDControl.cpp +++ b/src/kaleidoscope/plugin/LEDControl.cpp @@ -124,6 +124,11 @@ void LEDControl::syncLeds(void) { if (!enabled_) return; + // This would be a good spot to introduce a new hook function so that a plugin + // that needs to override the color of an LED used by an LED mode can do so + // efficiently. + Hooks::beforeSyncingLeds(); + Runtime.device().syncLeds(); }