Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rgblight idle timeout feature #6450

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/feature_rgblight.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 many minutes of inactivity.|

## Effects and Animations

Expand Down
3 changes: 3 additions & 0 deletions quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
35 changes: 34 additions & 1 deletion quantum/rgblight.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

}
Expand Down Expand Up @@ -797,6 +805,16 @@ void rgblight_task(void) {
// static light mode, do nothing here
if ( 1 == 0 ) { //dummy
}
#ifdef RGBLIGHT_IDLE_ENABLE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for multiple defines for this feature as you can just used #if RGBLIGHT_IDLE_TIMEOUT > 0

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Should I just use the rgb matrix variable or still use a separate one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep the RGB Light define for this feature separate as there has been interest in running both RGB Light & Matrix at the same time.

// exit early if we are timedout
else if (rgblight_idle_timedout) {
return;
} else if (timer_elapsed32(rgblight_idle_timer) >= (RGBLIGHT_IDLE_TIMEOUT * 60000)) {
drashna marked this conversation as resolved.
Show resolved Hide resolved
rgblight_idle_timedout = true;
rgblight_disable_noeeprom();
rgblight_idle_timer = timer_read32();
yanfali marked this conversation as resolved.
Show resolved Hide resolved
}
#endif
#ifdef RGBLIGHT_EFFECT_BREATHING
else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING) {
// breathing mode
Expand Down Expand Up @@ -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();
Copy link
Contributor

@XScorpion2 XScorpion2 Aug 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't change the enable/disable state, as a user could have previously disabled the rgblight, and this would turn it back on against the users wishes. Use a similar pattern to what rgb matrix uses to turn off the LEDs without changing user state.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I will look at the rgb matrix code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rgb_matrix code uses a g_suspend_state boolean locally to determine if it's suspended or not, and renders based on that.

}
rgblight_idle_timer = timer_read32();
}
#endif
return true;
}
#endif

// Effects
#ifdef RGBLIGHT_EFFECT_BREATHING

Expand Down
8 changes: 8 additions & 0 deletions quantum/rgblight.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion quantum/rgblight_reconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) || \
Expand All @@ -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
Expand Down