diff options
| author | Patrick Stadler <patrick.stadler@gmail.com> | 2021-07-22 08:46:12 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-21 23:46:12 -0700 |
| commit | fb9a254a432e307e82c9dce45e1aba2cf21fa339 (patch) | |
| tree | e4fc4e5464764d421d89ad0e6189a77e03d68851 | |
| parent | 85128302c83b7d8b2525f371c96b46ae79aac801 (diff) | |
| download | qmk_firmware-fb9a254a432e307e82c9dce45e1aba2cf21fa339.tar.gz qmk_firmware-fb9a254a432e307e82c9dce45e1aba2cf21fa339.zip | |
Retain brightness with lighting layers (#13025)
Add guard `RGBLIGHT_LAYERS_RETAIN_VAL` to retain the currently used val
when applying lighting layers.
| -rw-r--r-- | docs/feature_rgblight.md | 4 | ||||
| -rw-r--r-- | quantum/rgblight/rgblight.c | 7 |
2 files changed, 11 insertions, 0 deletions
diff --git a/docs/feature_rgblight.md b/docs/feature_rgblight.md index d323dee4f..8484586c0 100644 --- a/docs/feature_rgblight.md +++ b/docs/feature_rgblight.md | |||
| @@ -326,6 +326,10 @@ would turn the layer 0 (or 1) on and off again three times when `DEBUG` is press | |||
| 326 | 326 | ||
| 327 | Normally lighting layers are not shown when RGB Lighting is disabled (e.g. with `RGB_TOG` keycode). If you would like lighting layers to work even when the RGB Lighting is otherwise off, add `#define RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF` to your `config.h`. | 327 | Normally lighting layers are not shown when RGB Lighting is disabled (e.g. with `RGB_TOG` keycode). If you would like lighting layers to work even when the RGB Lighting is otherwise off, add `#define RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF` to your `config.h`. |
| 328 | 328 | ||
| 329 | ### Retain brightness | ||
| 330 | |||
| 331 | Usually lighting layers apply their configured brightness once activated. If you would like lighting layers to retain the currently used brightness (as returned by `rgblight_get_val()`), add `#define RGBLIGHT_LAYERS_RETAIN_VAL` to your `config.h`. | ||
| 332 | |||
| 329 | ## Functions | 333 | ## Functions |
| 330 | 334 | ||
| 331 | If you need to change your RGB lighting in code, for example in a macro to change the color whenever you switch layers, QMK provides a set of functions to assist you. See [`rgblight.h`](https://github.com/qmk/qmk_firmware/blob/master/quantum/rgblight/rgblight.h) for the full list, but the most commonly used functions include: | 335 | If you need to change your RGB lighting in code, for example in a macro to change the color whenever you switch layers, QMK provides a set of functions to assist you. See [`rgblight.h`](https://github.com/qmk/qmk_firmware/blob/master/quantum/rgblight/rgblight.h) for the full list, but the most commonly used functions include: |
diff --git a/quantum/rgblight/rgblight.c b/quantum/rgblight/rgblight.c index 54face173..373dc08d3 100644 --- a/quantum/rgblight/rgblight.c +++ b/quantum/rgblight/rgblight.c | |||
| @@ -694,6 +694,9 @@ bool rgblight_get_layer_state(uint8_t layer) { | |||
| 694 | 694 | ||
| 695 | // Write any enabled LED layers into the buffer | 695 | // Write any enabled LED layers into the buffer |
| 696 | static void rgblight_layers_write(void) { | 696 | static void rgblight_layers_write(void) { |
| 697 | # ifdef RGBLIGHT_LAYERS_RETAIN_VAL | ||
| 698 | uint8_t current_val = rgblight_get_val(); | ||
| 699 | # endif | ||
| 697 | uint8_t i = 0; | 700 | uint8_t i = 0; |
| 698 | // For each layer | 701 | // For each layer |
| 699 | for (const rgblight_segment_t *const *layer_ptr = rgblight_layers; i < RGBLIGHT_MAX_LAYERS; layer_ptr++, i++) { | 702 | for (const rgblight_segment_t *const *layer_ptr = rgblight_layers; i < RGBLIGHT_MAX_LAYERS; layer_ptr++, i++) { |
| @@ -714,7 +717,11 @@ static void rgblight_layers_write(void) { | |||
| 714 | // Write segment.count LEDs | 717 | // Write segment.count LEDs |
| 715 | LED_TYPE *const limit = &led[MIN(segment.index + segment.count, RGBLED_NUM)]; | 718 | LED_TYPE *const limit = &led[MIN(segment.index + segment.count, RGBLED_NUM)]; |
| 716 | for (LED_TYPE *led_ptr = &led[segment.index]; led_ptr < limit; led_ptr++) { | 719 | for (LED_TYPE *led_ptr = &led[segment.index]; led_ptr < limit; led_ptr++) { |
| 720 | # ifdef RGBLIGHT_LAYERS_RETAIN_VAL | ||
| 721 | sethsv(segment.hue, segment.sat, current_val, led_ptr); | ||
| 722 | # else | ||
| 717 | sethsv(segment.hue, segment.sat, segment.val, led_ptr); | 723 | sethsv(segment.hue, segment.sat, segment.val, led_ptr); |
| 724 | # endif | ||
| 718 | } | 725 | } |
| 719 | segment_ptr++; | 726 | segment_ptr++; |
| 720 | } | 727 | } |
