IdleLEDs: Use an `end_time` instead of calculating it each cycle

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/445/head
Gergely Nagy 6 years ago
parent 6ac89dfc7e
commit 300e1afacb
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -22,13 +22,11 @@ namespace kaleidoscope {
namespace plugin { namespace plugin {
uint16_t IdleLEDs::idle_time_limit = 600; // 10 minutes uint16_t IdleLEDs::idle_time_limit = 600; // 10 minutes
uint32_t IdleLEDs::last_keypress_time_; uint32_t IdleLEDs::end_time_;
EventHandlerResult IdleLEDs::beforeEachCycle() { EventHandlerResult IdleLEDs::beforeEachCycle() {
uint32_t idle_limit = idle_time_limit * 1000;
if (!::LEDControl.paused && if (!::LEDControl.paused &&
Kaleidoscope.millisAtCycleStart() - last_keypress_time_ >= idle_limit) { (Kaleidoscope.millisAtCycleStart() >= end_time_)) {
::LEDControl.set_all_leds_to(CRGB(0, 0, 0)); ::LEDControl.set_all_leds_to(CRGB(0, 0, 0));
::LEDControl.syncLeds(); ::LEDControl.syncLeds();
@ -45,7 +43,7 @@ EventHandlerResult IdleLEDs::onKeyswitchEvent(Key &mapped_key, byte row, byte co
::LEDControl.refreshAll(); ::LEDControl.refreshAll();
} }
last_keypress_time_ = Kaleidoscope.millisAtCycleStart(); end_time_ = Kaleidoscope.millisAtCycleStart() + idle_time_limit * 1000;
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }

@ -29,14 +29,14 @@ class IdleLEDs: public kaleidoscope::Plugin {
static uint16_t idle_time_limit; static uint16_t idle_time_limit;
EventHandlerResult onSetup() { EventHandlerResult onSetup() {
last_keypress_time_ = millis(); end_time_ = millis() + idle_time_limit * 1000;
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
EventHandlerResult beforeEachCycle(); EventHandlerResult beforeEachCycle();
EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state); EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state);
private: private:
static uint32_t last_keypress_time_; static uint32_t end_time_;
}; };
} }
} }

Loading…
Cancel
Save