keymap.c (2853B)
1 /* Copyright 2022 Jason Wihardja 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 2 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16 17 #include QMK_KEYBOARD_H 18 19 enum custom_keycodes { 20 LAYER_SWITCH = SAFE_RANGE, 21 }; 22 23 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 24 25 /* Default */ 26 [0] = LAYOUT(LAYER_SWITCH, C(KC_C), C(KC_V)), 27 28 /* RGB Toggle + Mode Change */ 29 [1] = LAYOUT(LAYER_SWITCH, UG_TOGG, UG_NEXT), 30 31 /* RGB Brightness */ 32 [2] = LAYOUT(LAYER_SWITCH, UG_VALD, UG_VALU), 33 34 /* RGB Hue */ 35 [3] = LAYOUT(LAYER_SWITCH, UG_HUED, UG_HUEU), 36 37 /* RGB Saturation */ 38 [4] = LAYOUT(LAYER_SWITCH, UG_SATD, UG_SATU), 39 40 }; 41 42 /* Lighting layers */ 43 44 const rgblight_segment_t PROGMEM layer_indicator_0[] = RGBLIGHT_LAYER_SEGMENTS( 45 {0, 1, HSV_WHITE}, 46 {1, 4, HSV_OFF} 47 ); 48 49 const rgblight_segment_t PROGMEM layer_indicator_1[] = RGBLIGHT_LAYER_SEGMENTS( 50 {0, 1, HSV_OFF}, 51 {1, 1, HSV_WHITE}, 52 {2, 3, HSV_OFF} 53 ); 54 55 const rgblight_segment_t PROGMEM layer_indicator_2[] = RGBLIGHT_LAYER_SEGMENTS( 56 {0, 2, HSV_OFF}, 57 {2, 1, HSV_WHITE}, 58 {3, 2, HSV_OFF} 59 ); 60 61 const rgblight_segment_t PROGMEM layer_indicator_3[] = RGBLIGHT_LAYER_SEGMENTS( 62 {0, 3, HSV_OFF}, 63 {3, 1, HSV_WHITE}, 64 {4, 1, HSV_OFF} 65 ); 66 67 const rgblight_segment_t PROGMEM layer_indicator_4[] = RGBLIGHT_LAYER_SEGMENTS( 68 {0, 4, HSV_OFF}, 69 {4, 1, HSV_WHITE} 70 ); 71 72 const rgblight_segment_t* const PROGMEM rgb_layers[] = RGBLIGHT_LAYERS_LIST( 73 layer_indicator_0, 74 layer_indicator_1, 75 layer_indicator_2, 76 layer_indicator_3, 77 layer_indicator_4 78 ); 79 80 void keyboard_post_init_user(void) { 81 /* Enable the LED layers */ 82 rgblight_layers = rgb_layers; 83 } 84 85 /* Layer handler */ 86 87 uint16_t layer = 0; 88 89 bool process_record_user(uint16_t keycode, keyrecord_t *record) { 90 switch (keycode) { 91 case LAYER_SWITCH: 92 if (record->event.pressed) { 93 if (layer > 0) { 94 layer_off(layer); 95 } 96 97 rgblight_unblink_layer(layer); 98 layer = (layer + 1) % 5; 99 rgblight_blink_layer_repeat(layer, 1000, 1); 100 101 if (layer > 0) { 102 layer_on(layer); 103 } 104 } 105 return false; 106 default: 107 return true; 108 } 109 }