Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* https://www.reddit.com/r/olkb/comments/poc34h/how_can_i_convert_an_led_index_to_the_index_of/
- * Code to change layer coloring based on if swap_hands is active or not.
- */
- extern bool swap_hands; //gives access to the variable where swap_hands is updated
- void set_layer_color(int layer) {
- keypos_t key_pos;
- for (r=0; r<MATRIX_ROWS; r++) {
- for (c=0; c<MATRIX_COLS; c++) {
- if (swap_hands)
- key_pos = hand_swap_config[r][c];
- else
- key_pos = (keypos_t){.row = r, .col = c};
- uint8_t led_index = g_led_config.matrix_co[key_pos.row][key_pos.col];
- if (led_index == NO_LED)
- continue;
- HSV hsv = {
- .h = pgm_read_byte(&ledmap[layer][led_index][0]),
- .s = pgm_read_byte(&ledmap[layer][led_index][1]),
- .v = pgm_read_byte(&ledmap[layer][led_index][2]),
- };
- if (!hsv.h && !hsv.s && !hsv.v) {
- rgb_matrix_set_color(led_index, 0, 0, 0);
- } else {
- RGB rgb = hsv_to_rgb(hsv);
- float f = (float)rgb_matrix_config.hsv.v / UINT8_MAX;
- rgb_matrix_set_color(led_index, f * rgb.r, f * rgb.g, f * rgb.b);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment