Calculate idle time when set instead of every cycle

Signed-off-by: tiltowait <tiltowaitt+github@icloud.com>
pull/666/head
tiltowait 6 years ago
parent f6d2e62649
commit e81f13fac7

@ -34,18 +34,23 @@ Because the plugin needs to know about key events, it is best to make it one of
the first plugins, so it can catch all of them, before any other plugin would
have a chance to consume key events.
## Plugin properties
## Plugin Methods
The plugin provides a single object, `IdleLEDs`, with the following
properties. All times are in seconds.
methods. All times are in seconds.
### `idle_time_limit`
### `.idle_time_limit()`
> The amount of time that can pass without a single key being pressed, before
> the plugin considers the keyboard idle, and turns the LEDs off.
> The amount of time that can pass without a single key being pressed before
> the plugin considers the keyboard idle and turns off the LEDs.
>
> Defaults to 600 seconds (10 minutes).
### `.set_idle_time_limit(uint16_t new_limit)`
> Sets the amount of time that can pass without a single key being pressed
> before the plugin considers the keyboard idle and turns off the LEDs.
## Dependencies
* [Kaleidoscope-LEDControl](LEDControl.md)

@ -50,7 +50,7 @@ KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
void setup() {
Kaleidoscope.setup();
IdleLEDs.idle_time_limit = 300; // 5 minutes
IdleLEDs.set_idle_time_limit(300); // 5 minutes
LEDRainbowWaveEffect.activate();
}

@ -21,12 +21,20 @@
namespace kaleidoscope {
namespace plugin {
uint16_t IdleLEDs::idle_time_limit = 600; // 10 minutes
uint32_t IdleLEDs::idle_time_limit_ = 600000; // 10 minutes
uint32_t IdleLEDs::start_time_ = 0;
uint16_t IdleLEDs::idle_time_limit() {
return uint16_t(idle_time_limit_ / 1000);
}
void IdleLEDs::set_idle_time_limit(uint16_t new_limit) {
idle_time_limit_ = (uint32_t)new_limit * 1000;
}
EventHandlerResult IdleLEDs::beforeEachCycle() {
if (!::LEDControl.paused &&
Kaleidoscope.hasTimeExpired(start_time_, uint32_t(idle_time_limit * 1000))) {
Kaleidoscope.hasTimeExpired(start_time_, idle_time_limit_)) {
::LEDControl.set_all_leds_to(CRGB(0, 0, 0));
::LEDControl.syncLeds();

@ -26,12 +26,14 @@ class IdleLEDs: public kaleidoscope::Plugin {
public:
IdleLEDs(void) {}
static uint16_t idle_time_limit;
static uint16_t idle_time_limit();
static void set_idle_time_limit(uint16_t new_limit);
EventHandlerResult beforeEachCycle();
EventHandlerResult onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state);
private:
static uint32_t idle_time_limit_;
static uint32_t start_time_;
};
}

Loading…
Cancel
Save