Keep property public and rename methods to conform to style guide.

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

@ -34,22 +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 the first plugins, so it can catch all of them, before any other plugin would
have a chance to consume key events. have a chance to consume key events.
## Plugin Methods ## Plugin Properties
The plugin provides a single object, `IdleLEDs`, with the following The plugin provides a single object, `IdleLEDs`, with the following properties
methods. All times are in seconds. and methods.
### `.idle_time_limit()` ### `.idle_time_limit`
> The amount of time that can pass without a single key being pressed before > Property storing the amount of time that can pass without a single key being
> the plugin considers the keyboard idle and turns off the LEDs. > pressed before the plugin considers the keyboard idle and turns off the LEDs.
> > Value is expressed in milliseconds.
> Defaults to 600 seconds (10 minutes).
### `.set_idle_time_limit(uint16_t new_limit)` > Defaults to 600000 milliseconds (10 minutes).
> Sets the amount of time that can pass without a single key being pressed > Provided for compatibility reasons. It is recommended to use one of the
> before the plugin considers the keyboard idle and turns off the LEDs. > 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 ## Dependencies

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

@ -21,20 +21,20 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { 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;
uint16_t IdleLEDs::idle_time_limit() { uint32_t IdleLEDs::idleTimeoutSeconds() {
return uint16_t(idle_time_limit_ / 1000); return idle_time_limit / 1000;
} }
void IdleLEDs::set_idle_time_limit(uint16_t new_limit) { void IdleLEDs::setIdleTimeoutSeconds(uint32_t new_limit) {
idle_time_limit_ = (uint32_t)new_limit * 1000; idle_time_limit = new_limit * 1000;
} }
EventHandlerResult IdleLEDs::beforeEachCycle() { EventHandlerResult IdleLEDs::beforeEachCycle() {
if (!::LEDControl.paused && if (!::LEDControl.paused &&
Kaleidoscope.hasTimeExpired(start_time_, idle_time_limit_)) { Kaleidoscope.hasTimeExpired(start_time_, idle_time_limit)) {
::LEDControl.set_all_leds_to(CRGB(0, 0, 0)); ::LEDControl.set_all_leds_to(CRGB(0, 0, 0));
::LEDControl.syncLeds(); ::LEDControl.syncLeds();

@ -26,14 +26,15 @@ class IdleLEDs: public kaleidoscope::Plugin {
public: public:
IdleLEDs(void) {} IdleLEDs(void) {}
static uint16_t idle_time_limit(); static uint32_t idle_time_limit;
static void set_idle_time_limit(uint16_t new_limit);
static uint32_t idleTimeoutSeconds();
static void setIdleTimeoutSeconds(uint32_t new_limit);
EventHandlerResult beforeEachCycle(); EventHandlerResult beforeEachCycle();
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 uint32_t idle_time_limit_;
static uint32_t start_time_; static uint32_t start_time_;
}; };
} }

Loading…
Cancel
Save