From 2cd1e6947cf7015aa78d474b2f01b13773d444d3 Mon Sep 17 00:00:00 2001 From: Nicolas Vitaterna Date: Tue, 30 Jul 2019 21:44:45 -0400 Subject: [PATCH 1/3] rgblight idle timeout feature --- docs/feature_rgblight.md | 1 + quantum/quantum.c | 3 +++ quantum/rgblight.c | 35 ++++++++++++++++++++++++++++++++++- quantum/rgblight.h | 8 ++++++++ quantum/rgblight_reconfig.h | 7 ++++++- 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/docs/feature_rgblight.md b/docs/feature_rgblight.md index be4ddfa72956..cc164756d1b4 100644 --- a/docs/feature_rgblight.md +++ b/docs/feature_rgblight.md @@ -76,6 +76,7 @@ Your RGB lighting can be configured by placing these `#define`s in your `config. |`RGBLIGHT_LIMIT_VAL` |`255` |The maximum brightness level | |`RGBLIGHT_SLEEP` |*Not defined*|If defined, the RGB lighting will be switched off when the host goes to sleep| |`RGBLIGHT_SPLIT` |*Not defined*|If defined, synchronization functionality for split keyboards is added| +|`RGBLIGHT_IDLE_TIMEOUT`|*Not defined*|If defined, turn the backlight off after this number in minutes of inactivity.| ## Effects and Animations diff --git a/quantum/quantum.c b/quantum/quantum.c index d98c601d991a..a3e5cc4d0ae0 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -297,6 +297,9 @@ bool process_record_quantum(keyrecord_t *record) { #endif #ifdef SPACE_CADET_ENABLE process_space_cadet(keycode, record) && + #endif + #ifdef RGBLIGHT_USE_PROCESS + process_rgblight(keycode, record) && #endif true)) { return false; diff --git a/quantum/rgblight.c b/quantum/rgblight.c index f569d6b9e3f4..72e71c34b28f 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -93,12 +93,16 @@ bool is_rgblight_initialized = false; animation_status_t animation_status = {}; #endif +#ifdef RGBLIGHT_IDLE_ENABLE +bool rgblight_idle_timedout = false; +uint32_t rgblight_idle_timer; +#endif + #ifndef LED_ARRAY LED_TYPE led[RGBLED_NUM]; #define LED_ARRAY led #endif - static uint8_t clipping_start_pos = 0; static uint8_t clipping_num_leds = RGBLED_NUM; static uint8_t effect_start_pos = 0; @@ -220,6 +224,10 @@ void rgblight_init(void) { rgblight_mode_noeeprom(rgblight_config.mode); } + #ifdef RGBLIGHT_IDLE_ENABLE + rgblight_idle_timer = timer_read32(); + #endif + is_rgblight_initialized = true; } @@ -797,6 +805,16 @@ void rgblight_task(void) { // static light mode, do nothing here if ( 1 == 0 ) { //dummy } +#ifdef RGBLIGHT_IDLE_ENABLE + // exit early if we are timedout + else if (rgblight_idle_timedout) { + return; + } else if (timer_elapsed32(rgblight_idle_timer) >= (RGBLIGHT_IDLE_TIMEOUT * 60000)) { + rgblight_idle_timedout = true; + rgblight_disable_noeeprom(); + rgblight_idle_timer = timer_read32(); + } +#endif #ifdef RGBLIGHT_EFFECT_BREATHING else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING) { // breathing mode @@ -885,6 +903,21 @@ void rgblight_task(void) { #endif /* RGBLIGHT_USE_TIMER */ +#ifdef RGBLIGHT_USE_PROCESS +bool process_rgblight(uint16_t keycode, keyrecord_t *record) { + #ifdef RGBLIGHT_IDLE_ENABLE + if (record->event.pressed) { + if (rgblight_idle_timedout) { + rgblight_idle_timedout = false; + rgblight_enable_noeeprom(); + } + rgblight_idle_timer = timer_read32(); + } + #endif + return true; +} +#endif + // Effects #ifdef RGBLIGHT_EFFECT_BREATHING diff --git a/quantum/rgblight.h b/quantum/rgblight.h index cba18ae72912..8ada879480e3 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -264,6 +264,14 @@ void rgblight_timer_enable(void); void rgblight_timer_disable(void); void rgblight_timer_toggle(void); +// if timeout is set, enable the rgblight idle feature +#ifdef RGBLIGHT_IDLE_TIMEOUT + #define RGBLIGHT_IDLE_ENABLE +#endif + +#include "quantum.h" +bool process_rgblight(uint16_t keycode, keyrecord_t *record); + #ifdef RGBLIGHT_SPLIT #define RGBLIGHT_STATUS_CHANGE_MODE (1<<0) #define RGBLIGHT_STATUS_CHANGE_HSVS (1<<1) diff --git a/quantum/rgblight_reconfig.h b/quantum/rgblight_reconfig.h index 11bd4fd11820..10e7eb1f2eb6 100644 --- a/quantum/rgblight_reconfig.h +++ b/quantum/rgblight_reconfig.h @@ -18,6 +18,10 @@ #define RGBLIGHT_EFFECT_STATIC_GRADIENT #endif +#if defined(RGBLIGHT_IDLE_TIMEOUT) + #define RGBLIGHT_USE_PROCESS +#endif + // check dynamic animation effects chose ? #if defined(RGBLIGHT_EFFECT_BREATHING) || \ defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || \ @@ -26,7 +30,8 @@ defined(RGBLIGHT_EFFECT_KNIGHT) || \ defined(RGBLIGHT_EFFECT_CHRISTMAS) || \ defined(RGBLIGHT_EFFECT_RGB_TEST) || \ - defined(RGBLIGHT_EFFECT_ALTERNATING) + defined(RGBLIGHT_EFFECT_ALTERNATING) || \ + defined(RGBLIGHT_IDLE_ENABLE) #define RGBLIGHT_USE_TIMER #ifndef RGBLIGHT_ANIMATIONS #define RGBLIGHT_ANIMATIONS // for backward compatibility From 5a2aa15d98ad637109619f584ff1bf0a776c79e4 Mon Sep 17 00:00:00 2001 From: Nicolas Vitaterna Date: Wed, 31 Jul 2019 08:56:24 -0400 Subject: [PATCH 2/3] Update feature_rgblight.md --- docs/feature_rgblight.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/feature_rgblight.md b/docs/feature_rgblight.md index cc164756d1b4..f1d196579fbc 100644 --- a/docs/feature_rgblight.md +++ b/docs/feature_rgblight.md @@ -76,7 +76,7 @@ Your RGB lighting can be configured by placing these `#define`s in your `config. |`RGBLIGHT_LIMIT_VAL` |`255` |The maximum brightness level | |`RGBLIGHT_SLEEP` |*Not defined*|If defined, the RGB lighting will be switched off when the host goes to sleep| |`RGBLIGHT_SPLIT` |*Not defined*|If defined, synchronization functionality for split keyboards is added| -|`RGBLIGHT_IDLE_TIMEOUT`|*Not defined*|If defined, turn the backlight off after this number in minutes of inactivity.| +|`RGBLIGHT_IDLE_TIMEOUT`|*Not defined*|If defined, turn the backlight off after this many minutes of inactivity.| ## Effects and Animations From 2595132305f472b04566610d972a5ad6dc70fce2 Mon Sep 17 00:00:00 2001 From: Nicolas Vitaterna Date: Wed, 31 Jul 2019 19:47:52 -0400 Subject: [PATCH 3/3] changes for comments --- quantum/rgblight.c | 3 +-- quantum/rgblight.h | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 72e71c34b28f..aa36328d677d 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -809,10 +809,9 @@ void rgblight_task(void) { // exit early if we are timedout else if (rgblight_idle_timedout) { return; - } else if (timer_elapsed32(rgblight_idle_timer) >= (RGBLIGHT_IDLE_TIMEOUT * 60000)) { + } else if (timer_elapsed32(rgblight_idle_timer) >= (RGBLIGHT_IDLE_TIMEOUT * RGBLIGHT_IDLE_MULTIPLIER)) { rgblight_idle_timedout = true; rgblight_disable_noeeprom(); - rgblight_idle_timer = timer_read32(); } #endif #ifdef RGBLIGHT_EFFECT_BREATHING diff --git a/quantum/rgblight.h b/quantum/rgblight.h index 8ada879480e3..39ee062bce25 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -267,6 +267,7 @@ void rgblight_timer_toggle(void); // if timeout is set, enable the rgblight idle feature #ifdef RGBLIGHT_IDLE_TIMEOUT #define RGBLIGHT_IDLE_ENABLE + #define RGBLIGHT_IDLE_MULTIPLIER 60000 #endif #include "quantum.h"