Merge pull request #445 from keyboardio/idleleds/overflow-fix

IdleLEDs: Make timeout calculation more efficient, and avoid an overflow
pull/446/head
Jesse Vincent 6 years ago committed by GitHub
commit 5c9284636b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

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

Loading…
Cancel
Save