Advertisement
hakbraley

QMK Custom Layer Lighting

Aug 20th, 2021
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.33 KB | None | 0 0
  1.  
  2. enum custom_keycodes {
  3.     TOG_STAT = SAFE_RANGE,  //first macro key always starts at SAFE_RANGE
  4.     //MACRO1,   //other macros
  5.     //MACRO2,
  6.     //...
  7. };
  8.  
  9.  
  10. //configure the colors you want for each layer
  11. void set_layer_color() {
  12.     switch(get_highest_layer(layer_state)) {
  13.         case 0:  //layer 0
  14.             rgb_matrix_sethsv_noeeprom(HSV_ORANGE);
  15.             break;
  16.         case 1:  //layer 1
  17.             rgb_matrix_sethsv_noeeprom(HSV_CORAL);
  18.             break;
  19.         //other layers
  20.         default:  //for any layer not listed in this function
  21.             rgb_matrix_sethsv_noeeprom(HSV_GREEN);
  22.             break;
  23.     }
  24. }
  25.  
  26.  
  27. //configure the animations you want for each layer
  28. void set_layer_anim(void) {
  29.     switch(get_highest_layer(layer_state)) {
  30.         case 0:  //layer 0
  31.             rgb_matrix_mode_noeeprom(RGB_MATRIX_BREATHING);
  32.             break;
  33.         case 1:  //layer 1
  34.             rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_REACTIVE_MULTICROSS);  //needs RGB_MATRIX_KEYPRESSES in config.h
  35.             break;
  36.         //other layers
  37.         default:  //for any layer not listed in this function
  38.             rgb_matrix_mode_noeeprom(RGB_MATRIX_CYCLE_LEFT_RIGHT); //rainbow wave
  39.             break;
  40.     }
  41. }
  42.  
  43. void set_rgb_layers(void) {
  44.     if (!rgb_matrix_is_enabled()) return;  //if LEDs are turned off, exit the function
  45.        
  46.     set_layer_color();  //set color based on current layer
  47.    
  48.     if (static_color_mode) {  //if static color mode is active
  49.         rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_COLOR);  //set LEDs to solid color mode
  50.     } else {
  51.         set_layer_anim();  //set animation based on current layer
  52.     }
  53. }
  54.  
  55. //this function is called automatically every time there's a layer change
  56. layer_state_t layer_state_set_user(layer_state_t state) {
  57.     set_rgb_layers();  
  58.     return state;
  59. }
  60.  
  61.  
  62. //this will set the LEDs to static color mode when true
  63. bool static_color_mode = false;
  64.  
  65. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  66.         case TOG_STAT:
  67.             if (record->event.pressed) {  //when TOG_STAT is pressed
  68.                 static_color_mode = !static_color_mode;  //flip this variable
  69.                 set_rgb_layers();
  70.             }
  71.             break;
  72.         //change this key's functionality a bit to set color/animation when LEDs are toggled on
  73.         case RGB_TOG:
  74.             if (record->event.pressed) {  //when RGB_TOG is pressed
  75.                 rgb_matrix_toggle_noeeprom();  //toggle RGB
  76.                 if (rgb_matrix_is_enabled) {
  77.                     set_rgb_layers();
  78.                 }
  79.             return false;  //do nothing else with this key
  80.     }
  81.     return true;
  82. };
  83.  
  84.  
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement