~ruther/qmk_firmware

e2e287ec5f720839efd8f7cecf447763433cda27 — Joshua Diamond 5 years ago dfcd4f0
Option to allow lighting layers when RGB Lighting is off (#9051)

3 files changed, 24 insertions(+), 6 deletions(-)

M docs/config_options.md
M docs/feature_rgblight.md
M quantum/rgblight.c
M docs/config_options.md => docs/config_options.md +2 -0
@@ 197,6 197,8 @@ If you define these options you will enable the associated feature, which may in
  * Note: Increasing the maximum will increase the firmware size and slow sync on split keyboards.
* `#define RGBLIGHT_LAYER_BLINK` 
  * Adds ability to [blink](feature_rgblight.md?id=lighting-layer-blink) a lighting layer for a specified number of milliseconds (e.g. to acknowledge an action).
* `#define RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF`
  * If defined, then [lighting layers](feature_rgblight?id=overriding-rgb-lighting-onoff-status) will be shown even if RGB Light is off.
* `#define RGBLED_NUM 12`
  * number of LEDs
* `#define RGBLIGHT_SPLIT`

M docs/feature_rgblight.md => docs/feature_rgblight.md +4 -0
@@ 278,6 278,10 @@ void post_process_record_user(uint16_t keycode, keyrecord_t *record) {
}
```

### Overriding RGB Lighting on/off status

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`.

## Functions

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.h) for the full list, but the most commonly used functions include:

M quantum/rgblight.c => quantum/rgblight.c +18 -6
@@ 628,6 628,13 @@ void rgblight_set_layer_state(uint8_t layer, bool enabled) {
    if (rgblight_status.timer_enabled == false) {
        rgblight_mode_noeeprom(rgblight_config.mode);
    }

#    ifdef RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF
    // If not enabled, then nothing else will actually set the LEDs...
    if (!rgblight_config.enable) {
        rgblight_set();
    }
#    endif
}

bool rgblight_get_layer_state(uint8_t layer) {


@@ 693,16 700,11 @@ void rgblight_unblink_layers(void) {
__attribute__((weak)) void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { ws2812_setleds(start_led, num_leds); }

#ifndef RGBLIGHT_CUSTOM_DRIVER

void rgblight_set(void) {
    LED_TYPE *start_led;
    uint8_t   num_leds = rgblight_ranges.clipping_num_leds;

#    ifdef RGBLIGHT_LAYERS
    if (rgblight_layers != NULL) {
        rgblight_layers_write();
    }
#    endif

    if (!rgblight_config.enable) {
        for (uint8_t i = rgblight_ranges.effect_start_pos; i < rgblight_ranges.effect_end_pos; i++) {
            led[i].r = 0;


@@ 714,6 716,16 @@ void rgblight_set(void) {
        }
    }

#    ifdef RGBLIGHT_LAYERS
    if (rgblight_layers != NULL
#        ifndef RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF
        && rgblight_config.enable
#        endif
    ) {
        rgblight_layers_write();
    }
#    endif

#    ifdef RGBLIGHT_LED_MAP
    LED_TYPE led0[RGBLED_NUM];
    for (uint8_t i = 0; i < RGBLED_NUM; i++) {