New event handler: onLEDModeChange

We'd like to be able to run custom code whenever the led mode changes, reliably,
without having to resort to checking the mode every cycle. For this purpose, we
introduce the `onLEDModeChange()` handler plugins can hook into. It will be
called every time `LEDControl.set_mode()` is called, even if that just sets the
mode to the currently active one.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/733/head
Gergely Nagy 5 years ago
parent 4c2e0a7635
commit fddbd75ff8
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -161,6 +161,14 @@
_CURRENT_IMPLEMENTATION, __NL__ \ _CURRENT_IMPLEMENTATION, __NL__ \
_NOT_ABORTABLE, __NL__ \ _NOT_ABORTABLE, __NL__ \
(), (), ##__VA_ARGS__) __NL__ \ (), (), ##__VA_ARGS__) __NL__ \
/* Called when the LED mode changes. If one needs to know what */ __NL__ \
/* from and what to the mode changed, they should track that */ __NL__ \
/* themselves. */ __NL__ \
OPERATION(onLEDModeChange, __NL__ \
1, __NL__ \
_CURRENT_IMPLEMENTATION, __NL__ \
_NOT_ABORTABLE, __NL__ \
(), (), ##__VA_ARGS__) __NL__ \
/* Called before reporting our state to the host. This is the */ __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__ \ /* last point in a cycle where a plugin can alter what gets */ __NL__ \
/* reported to the host. */ __NL__ \ /* reported to the host. */ __NL__ \
@ -219,6 +227,10 @@
OP(onLayerChange, 1) __NL__ \ OP(onLayerChange, 1) __NL__ \
END(onLayerChange, 1) __NL__ \ END(onLayerChange, 1) __NL__ \
__NL__ \ __NL__ \
START(onLEDModeChange, 1) __NL__ \
OP(onLEDModeChange, 1) __NL__ \
END(onLEDModeChange, 1) __NL__ \
__NL__ \
START(beforeReportingState, 1) __NL__ \ START(beforeReportingState, 1) __NL__ \
OP(beforeReportingState, 1) __NL__ \ OP(beforeReportingState, 1) __NL__ \
END(beforeReportingState, 1) __NL__ \ END(beforeReportingState, 1) __NL__ \

@ -33,6 +33,10 @@ extern void handleKeyswitchEvent(kaleidoscope::Key mappedKey, KeyAddr key_addr,
DEPRECATED(ROW_COL_FUNC) extern void handleKeyswitchEvent(kaleidoscope::Key mappedKey, byte row, byte col, uint8_t keyState); DEPRECATED(ROW_COL_FUNC) extern void handleKeyswitchEvent(kaleidoscope::Key mappedKey, byte row, byte col, uint8_t keyState);
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin {
// Forward declaration to enable friend declarations.
class LEDControl;
}
// Forward declaration to enable friend declarations. // Forward declaration to enable friend declarations.
class Layer_; class Layer_;
@ -55,6 +59,7 @@ class Hooks {
// and Hooks::afterEachCycle. // and Hooks::afterEachCycle.
friend class Kaleidoscope_; friend class Kaleidoscope_;
friend class ::kaleidoscope::Layer_; friend class ::kaleidoscope::Layer_;
friend class ::kaleidoscope::plugin::LEDControl;
// ::handleKeyswitchEvent(...) calls Hooks::onKeyswitchEvent. // ::handleKeyswitchEvent(...) calls Hooks::onKeyswitchEvent.
friend void ::handleKeyswitchEvent(kaleidoscope::Key mappedKey, friend void ::handleKeyswitchEvent(kaleidoscope::Key mappedKey,

@ -68,6 +68,8 @@ LEDControl::set_mode(uint8_t mode_) {
cur_led_mode_ = LEDModeManager::getLEDMode(mode_id); cur_led_mode_ = LEDModeManager::getLEDMode(mode_id);
refreshAll(); refreshAll();
kaleidoscope::Hooks::onLEDModeChange();
} }
void LEDControl::activate(LEDModeInterface *plugin) { void LEDControl::activate(LEDModeInterface *plugin) {

Loading…
Cancel
Save