diff --git a/doc/plugin/IdleLEDs.md b/doc/plugin/IdleLEDs.md index 48ebd797..3d71d9da 100644 --- a/doc/plugin/IdleLEDs.md +++ b/doc/plugin/IdleLEDs.md @@ -34,17 +34,32 @@ 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 Properties -The plugin provides a single object, `IdleLEDs`, with the following -properties. All times are in seconds. +The plugin provides a single object, `IdleLEDs`, with the following properties +and methods. -### `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. -> -> Defaults to 600 seconds (10 minutes). +> Property storing 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. +> Value is expressed in milliseconds. + +> Defaults to 600000 milliseconds (10 minutes). + +> Provided for compatibility reasons. It is recommended to use one of the +> methods below instead of setting this property directly. + +### `.idleTimeoutSeconds()` + +> Returns the amount of time (in seconds) that can pass without a single key +> being pressed before the plugin considers the keyboard idle and turns off the +> LEDs. + +### `.setIdleTimeoutSeconds(uint32_t new_limit)` + +> Sets the amount of time (in seconds) that can pass without a single key being +> pressed before the plugin considers the keyboard idle and turns off the LEDs. ## Dependencies diff --git a/examples/LEDs/IdleLEDs/IdleLEDs.ino b/examples/LEDs/IdleLEDs/IdleLEDs.ino index 704f499e..25b9791e 100644 --- a/examples/LEDs/IdleLEDs/IdleLEDs.ino +++ b/examples/LEDs/IdleLEDs/IdleLEDs.ino @@ -50,7 +50,7 @@ KALEIDOSCOPE_INIT_PLUGINS(LEDControl, void setup() { Kaleidoscope.setup(); - IdleLEDs.idle_time_limit = 300; // 5 minutes + IdleLEDs.setIdleTimeoutSeconds(300); // 5 minutes LEDRainbowWaveEffect.activate(); } diff --git a/src/kaleidoscope/plugin/IdleLEDs.cpp b/src/kaleidoscope/plugin/IdleLEDs.cpp index 34f75dff..0489bd30 100644 --- a/src/kaleidoscope/plugin/IdleLEDs.cpp +++ b/src/kaleidoscope/plugin/IdleLEDs.cpp @@ -21,12 +21,20 @@ namespace kaleidoscope { namespace plugin { -uint16_t IdleLEDs::idle_time_limit = 600; // 10 minutes -uint32_t IdleLEDs::start_time_ = 0; +uint32_t IdleLEDs::idle_time_limit = 600000; // 10 minutes +uint32_t IdleLEDs::start_time_ = 0; + +uint32_t IdleLEDs::idleTimeoutSeconds() { + return idle_time_limit / 1000; +} + +void IdleLEDs::setIdleTimeoutSeconds(uint32_t new_limit) { + idle_time_limit = 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(); diff --git a/src/kaleidoscope/plugin/IdleLEDs.h b/src/kaleidoscope/plugin/IdleLEDs.h index 801eafa9..8722cf83 100644 --- a/src/kaleidoscope/plugin/IdleLEDs.h +++ b/src/kaleidoscope/plugin/IdleLEDs.h @@ -26,7 +26,10 @@ class IdleLEDs: public kaleidoscope::Plugin { public: IdleLEDs(void) {} - static uint16_t idle_time_limit; + static uint32_t idle_time_limit; + + static uint32_t idleTimeoutSeconds(); + static void setIdleTimeoutSeconds(uint32_t new_limit); EventHandlerResult beforeEachCycle(); EventHandlerResult onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state);