logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

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. #include QMK_KEYBOARD_H
  17. enum custom_keycodes {
  18. LAYER_SWITCH = SAFE_RANGE,
  19. };
  20. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  21. /* Default */
  22. [0] = LAYOUT(LAYER_SWITCH, G(KC_C), G(KC_V)),
  23. /* RGB Toggle + Mode Change */
  24. [1] = LAYOUT(LAYER_SWITCH, UG_TOGG, UG_NEXT),
  25. /* RGB Brightness */
  26. [2] = LAYOUT(LAYER_SWITCH, UG_VALD, UG_VALU),
  27. /* RGB Hue */
  28. [3] = LAYOUT(LAYER_SWITCH, UG_HUED, UG_HUEU),
  29. /* RGB Saturation */
  30. [4] = LAYOUT(LAYER_SWITCH, UG_SATD, UG_SATU),
  31. };
  32. /* Lighting layers */
  33. const rgblight_segment_t PROGMEM layer_indicator_0[] = RGBLIGHT_LAYER_SEGMENTS(
  34. {0, 1, HSV_WHITE},
  35. {1, 4, HSV_OFF}
  36. );
  37. const rgblight_segment_t PROGMEM layer_indicator_1[] = RGBLIGHT_LAYER_SEGMENTS(
  38. {0, 1, HSV_OFF},
  39. {1, 1, HSV_WHITE},
  40. {2, 3, HSV_OFF}
  41. );
  42. const rgblight_segment_t PROGMEM layer_indicator_2[] = RGBLIGHT_LAYER_SEGMENTS(
  43. {0, 2, HSV_OFF},
  44. {2, 1, HSV_WHITE},
  45. {3, 2, HSV_OFF}
  46. );
  47. const rgblight_segment_t PROGMEM layer_indicator_3[] = RGBLIGHT_LAYER_SEGMENTS(
  48. {0, 3, HSV_OFF},
  49. {3, 1, HSV_WHITE},
  50. {4, 1, HSV_OFF}
  51. );
  52. const rgblight_segment_t PROGMEM layer_indicator_4[] = RGBLIGHT_LAYER_SEGMENTS(
  53. {0, 4, HSV_OFF},
  54. {4, 1, HSV_WHITE}
  55. );
  56. const rgblight_segment_t* const PROGMEM rgb_layers[] = RGBLIGHT_LAYERS_LIST(
  57. layer_indicator_0,
  58. layer_indicator_1,
  59. layer_indicator_2,
  60. layer_indicator_3,
  61. layer_indicator_4
  62. );
  63. void keyboard_post_init_user(void) {
  64. /* Enable the LED layers */
  65. rgblight_layers = rgb_layers;
  66. }
  67. /* Layer handler */
  68. uint16_t layer = 0;
  69. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  70. switch (keycode) {
  71. case LAYER_SWITCH:
  72. if (record->event.pressed) {
  73. if (layer > 0) {
  74. layer_off(layer);
  75. }
  76. rgblight_unblink_layer(layer);
  77. layer = (layer + 1) % 5;
  78. rgblight_blink_layer_repeat(layer, 1000, 1);
  79. if (layer > 0) {
  80. layer_on(layer);
  81. }
  82. }
  83. return false;
  84. default:
  85. return true;
  86. }
  87. }