You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
5.7 KiB

  1. /* Copyright 2021 TW59420 <https://github.com/TW59420>
  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. typedef union {
  18. uint32_t raw;
  19. struct {
  20. bool top_rgb_change :1;
  21. bool bottom_rgb_change :1;
  22. };
  23. } user_config_t;
  24. user_config_t user_config;
  25. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  26. [0] = LAYOUT(
  27. KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_VOLD, KC_DEL, KC_VOLU,
  28. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGUP,
  29. KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGDN,
  30. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, RGB_TOG,
  31. KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1), KC_LEFT, KC_DOWN, KC_RGHT
  32. ),
  33. [1] = LAYOUT(
  34. KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, RGB_HUI, _______,
  35. RGB_TOG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_HUD,
  36. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, USER00, RGB_SAI,
  37. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, USER01, RGB_VAI, RGB_SAD,
  38. _______, _______, _______, _______, RGB_MOD, _______, RGB_SPD, RGB_VAD, RGB_SPI
  39. ),
  40. [2] = LAYOUT(
  41. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  42. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  43. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  44. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  45. _______, _______, _______, _______, _______, _______, _______, _______, _______
  46. ),
  47. [3] = LAYOUT(
  48. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  49. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  50. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  51. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  52. _______, _______, _______, _______, _______, _______, _______, _______, _______
  53. ),
  54. };
  55. void keyboard_post_init_user(void) {
  56. // Read the user config from EEPROM
  57. user_config.raw = eeconfig_read_user();
  58. }
  59. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  60. switch (keycode) {
  61. case USER00:
  62. if (record->event.pressed) {
  63. // Do something when pressed
  64. user_config.top_rgb_change ^= 1; // Toggles the status
  65. eeconfig_update_user(user_config.raw); // Writes the new status to EEPROM
  66. } else {
  67. // Do something else when release
  68. }
  69. return false; // Skip all further processing of this key
  70. case USER01:
  71. if (record->event.pressed) {
  72. // Do something when pressed
  73. user_config.bottom_rgb_change ^= 1; // Toggles the status
  74. eeconfig_update_user(user_config.raw); // Writes the new status to EEPROM
  75. } else {
  76. // Do something else when release
  77. }
  78. return false; // Skip all further processing of this key
  79. default:
  80. return true; // Process all other keycodes normally
  81. }
  82. }
  83. #ifdef ENCODER_ENABLE
  84. bool encoder_update_user(uint8_t index, bool clockwise) {
  85. if (index == 0) {
  86. if (clockwise) {
  87. tap_code(dynamic_keymap_get_keycode(biton32(layer_state), 4, 3));
  88. } else {
  89. tap_code(dynamic_keymap_get_keycode(biton32(layer_state), 4, 4));
  90. }
  91. }
  92. return true;
  93. }
  94. #endif
  95. void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
  96. if (user_config.top_rgb_change)
  97. {
  98. for (size_t i = 16; i < 83; i++)
  99. {
  100. RGB_MATRIX_INDICATOR_SET_COLOR(i, 0, 0, 0);
  101. }
  102. }
  103. if (host_keyboard_led_state().caps_lock) {
  104. RGB_MATRIX_INDICATOR_SET_COLOR(52, 0, 255, 255); // assuming caps lock is at led #5
  105. }
  106. if (user_config.bottom_rgb_change)
  107. {
  108. for (size_t i = 0; i < 16; i++)
  109. {
  110. RGB_MATRIX_INDICATOR_SET_COLOR(i, 0, 0, 0);
  111. }
  112. }
  113. }