Skip to content

Instantly share code, notes, and snippets.

@loadedsith
Last active Nov 10, 2020
Embed
What would you like to do?
Backlight responds to layers
bool has_layer_changed = true;
void matrix_scan_user(void) {
uint8_t layer = biton32(layer_state);
static uint8_t old_layer = 0;
if (old_layer != layer) {
has_layer_changed = true;
old_layer = layer;
}
if (has_layer_changed) {
has_layer_changed = false;
switch (layer) {
case _LOWER:
backlight_set(1);
break;
case _QWERTY:
backlight_set(2);
break;
case _RAISE:
backlight_set(3);
break;
case _ADJUST:
backlight_set(4);
break;
}
}
};
@mgor

This comment has been minimized.

Copy link

@mgor mgor commented Nov 10, 2020

where does one specify what corresponds to the backlight_set 1..4?
i've got working it working for underglow with rgb layers, where the number is a array index to the specified layer color configuration. but can't seem to find any information for the backlight scenario.

Example:

const rgblight_segment_t PROGMEM mg_func_layer[] = RGBLIGHT_LAYER_SEGMENTS(
    {MG_LAYER_LEDS_RIGHT - 2, MG_LAYER_LEDS, HSV_GREEN}
);
...
const rgblight_segment_t* const PROGMEM mg_rgb_layers[] = RGBLIGHT_LAYERS_LIST(
    mg_capslock_active_layer,
    mg_func_layer,
    mg_caps_layer,
    mg_menu_layer
);

...
layer_state_t layer_state_set_user(layer_state_t state) {
    rgblight_set_layer_state(1, layer_state_cmp(state, _FUNC));
    return state;
}

so the 1 parameter to rgblight_set_layer_statecorresponds to themg_func_layer rgblight_segment_t`.
trying to understand the same relationship here :)

@loadedsith

This comment has been minimized.

Copy link
Owner Author

@loadedsith loadedsith commented Nov 10, 2020

I believe this is ancient code. QMK's lighting support has gotten a lot better.

@loadedsith

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment