hakbraley

QMK Swap Hands lighting

Sep 15th, 2021 (edited)
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. /*  https://www.reddit.com/r/olkb/comments/poc34h/how_can_i_convert_an_led_index_to_the_index_of/
  2.  *  Code to change layer coloring based on if swap_hands is active or not.
  3.  */
  4.  
  5. extern bool swap_hands;  //gives access to the variable where swap_hands is updated
  6.  
  7. void set_layer_color(int layer) {
  8.     keypos_t key_pos;
  9.    
  10.     for (r=0; r<MATRIX_ROWS; r++) {
  11.         for (c=0; c<MATRIX_COLS; c++) {
  12.             if (swap_hands)
  13.                 key_pos = hand_swap_config[r][c];
  14.             else
  15.                 key_pos = (keypos_t){.row = r, .col = c};
  16.            
  17.             uint8_t led_index = g_led_config.matrix_co[key_pos.row][key_pos.col];
  18.             if (led_index == NO_LED)
  19.                 continue;
  20.            
  21.             HSV hsv = {
  22.                 .h = pgm_read_byte(&ledmap[layer][led_index][0]),
  23.                 .s = pgm_read_byte(&ledmap[layer][led_index][1]),
  24.                 .v = pgm_read_byte(&ledmap[layer][led_index][2]),
  25.             };
  26.             if (!hsv.h && !hsv.s && !hsv.v) {
  27.                 rgb_matrix_set_color(led_index, 0, 0, 0);
  28.             } else {
  29.                 RGB   rgb = hsv_to_rgb(hsv);
  30.                 float f   = (float)rgb_matrix_config.hsv.v / UINT8_MAX;
  31.                 rgb_matrix_set_color(led_index, f * rgb.r, f * rgb.g, f * rgb.b);
  32.             }
  33.         }
  34.     }
  35. }
Add Comment
Please, Sign In to add comment