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 <algernon@keyboard.io>
pull/791/head
Gergely Nagy 5 years ago
parent 947851150d
commit 1e1e796bb2
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -26,6 +26,7 @@ namespace plugin {
uint32_t IdleLEDs::idle_time_limit = 600000; // 10 minutes uint32_t IdleLEDs::idle_time_limit = 600000; // 10 minutes
uint32_t IdleLEDs::start_time_ = 0; uint32_t IdleLEDs::start_time_ = 0;
bool IdleLEDs::idle_;
uint32_t IdleLEDs::idleTimeoutSeconds() { uint32_t IdleLEDs::idleTimeoutSeconds() {
return idle_time_limit / 1000; return idle_time_limit / 1000;
@ -39,6 +40,7 @@ EventHandlerResult IdleLEDs::beforeEachCycle() {
if (::LEDControl.isEnabled() && if (::LEDControl.isEnabled() &&
Runtime.hasTimeExpired(start_time_, idle_time_limit)) { Runtime.hasTimeExpired(start_time_, idle_time_limit)) {
::LEDControl.disable(); ::LEDControl.disable();
idle_ = true;
} }
return EventHandlerResult::OK; return EventHandlerResult::OK;
@ -46,8 +48,9 @@ EventHandlerResult IdleLEDs::beforeEachCycle() {
EventHandlerResult IdleLEDs::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) { EventHandlerResult IdleLEDs::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) {
if (!::LEDControl.isEnabled()) { if (idle_) {
::LEDControl.enable(); ::LEDControl.enable();
idle_ = false;
} }
start_time_ = Runtime.millisAtCycleStart(); start_time_ = Runtime.millisAtCycleStart();

@ -36,6 +36,7 @@ class IdleLEDs: public kaleidoscope::Plugin {
EventHandlerResult onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state); EventHandlerResult onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state);
private: private:
static bool idle_;
static uint32_t start_time_; static uint32_t start_time_;
}; };

Loading…
Cancel
Save