From 1e1e796bb2bcab530ea96392e1a381f88a6694a9 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 7 Jan 2020 16:59:58 +0100 Subject: [PATCH] IdleLEDs: Be smarter about re-enabling LEDs This changes the IdleLEDs plugin to only re-enable LEDs if they were disabled due to idleness. If they were turned off any other way, the plugin will not re-enable them. This makes it play better with the `Key_LEDToggle` key. Fixes #790. Signed-off-by: Gergely Nagy --- src/kaleidoscope/plugin/IdleLEDs.cpp | 5 ++++- src/kaleidoscope/plugin/IdleLEDs.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/kaleidoscope/plugin/IdleLEDs.cpp b/src/kaleidoscope/plugin/IdleLEDs.cpp index 6094d6de..a2424861 100644 --- a/src/kaleidoscope/plugin/IdleLEDs.cpp +++ b/src/kaleidoscope/plugin/IdleLEDs.cpp @@ -26,6 +26,7 @@ namespace plugin { uint32_t IdleLEDs::idle_time_limit = 600000; // 10 minutes uint32_t IdleLEDs::start_time_ = 0; +bool IdleLEDs::idle_; uint32_t IdleLEDs::idleTimeoutSeconds() { return idle_time_limit / 1000; @@ -39,6 +40,7 @@ EventHandlerResult IdleLEDs::beforeEachCycle() { if (::LEDControl.isEnabled() && Runtime.hasTimeExpired(start_time_, idle_time_limit)) { ::LEDControl.disable(); + idle_ = true; } return EventHandlerResult::OK; @@ -46,8 +48,9 @@ EventHandlerResult IdleLEDs::beforeEachCycle() { EventHandlerResult IdleLEDs::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) { - if (!::LEDControl.isEnabled()) { + if (idle_) { ::LEDControl.enable(); + idle_ = false; } start_time_ = Runtime.millisAtCycleStart(); diff --git a/src/kaleidoscope/plugin/IdleLEDs.h b/src/kaleidoscope/plugin/IdleLEDs.h index c6da2981..5d43cd18 100644 --- a/src/kaleidoscope/plugin/IdleLEDs.h +++ b/src/kaleidoscope/plugin/IdleLEDs.h @@ -36,6 +36,7 @@ class IdleLEDs: public kaleidoscope::Plugin { EventHandlerResult onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state); private: + static bool idle_; static uint32_t start_time_; };