logo

qmk_firmware

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

keymap.c (6741B)


  1. /*
  2. Copyright 2021-2022 Alin M Elena <alinm.elena@gmail.com>
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include QMK_KEYBOARD_H
  15. enum layer_names {
  16. _QW = 0,
  17. _LWR,
  18. _RSE,
  19. _ADJ
  20. };
  21. #ifdef RGBLIGHT_ENABLE
  22. const rgblight_segment_t PROGMEM my_qwerty_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLIGHT_LED_COUNT, HSV_PURPLE});
  23. const rgblight_segment_t PROGMEM my_lwr_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLIGHT_LED_COUNT, HSV_CYAN});
  24. const rgblight_segment_t PROGMEM my_rse_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLIGHT_LED_COUNT, HSV_RED});
  25. const rgblight_segment_t PROGMEM my_adj_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLIGHT_LED_COUNT, HSV_GREEN});
  26. const rgblight_segment_t* const PROGMEM my_rgb_layers[] = RGBLIGHT_LAYERS_LIST(my_qwerty_layer, my_lwr_layer, my_rse_layer, my_adj_layer);
  27. #endif
  28. #define LOWER TT(_LWR)
  29. #define RAISE TT(_RSE)
  30. // clang-format off
  31. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  32. [_QW] = LAYOUT_ortho_5x12(
  33. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC,
  34. KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL,
  35. KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  36. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT ,
  37. KC_LCTL, KC_LGUI, KC_LALT, KC_APP, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  38. ),
  39. [_LWR] = LAYOUT_ortho_5x12(
  40. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL,
  41. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE,
  42. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,S(KC_NUHS),S(KC_NUBS),_______, _______, _______,
  43. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY,
  44. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  45. ),
  46. [_RSE] = LAYOUT_ortho_5x12(
  47. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL,
  48. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS,
  49. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, _______, _______, _______,
  50. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY,
  51. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  52. ),
  53. [_ADJ] = LAYOUT_ortho_5x12(
  54. _______, QK_BOOT, _______, _______, _______, _______, UG_TOGG, UG_NEXT, UG_PREV, RGB_M_G, QK_BOOT, _______,
  55. _______, _______, _______, _______, _______, _______, UG_HUEU, UG_SATU, UG_VALU, _______, _______, _______,
  56. _______, _______, _______, _______, _______, _______, UG_HUED, UG_SATD, UG_VALD, _______, _______, _______,
  57. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  58. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  59. )
  60. };
  61. // clang-format on
  62. // let us assume we start with both layers off
  63. bool toggle_lwr = false;
  64. bool toggle_rse = false;
  65. bool led_update_user(led_t led_state) {
  66. // Disable the default LED update code, so that lock LEDs could be reused to show layer status.
  67. return false;
  68. }
  69. void matrix_scan_user(void) {
  70. led_lwr(toggle_lwr);
  71. led_rse(toggle_rse);
  72. led_t led_state = host_keyboard_led_state();
  73. led_caps(led_state.caps_lock);
  74. if (layer_state_is(_ADJ)) {
  75. led_lwr(true);
  76. led_rse(true);
  77. }
  78. }
  79. bool process_record_user(uint16_t keycode, keyrecord_t* record) {
  80. switch (keycode) {
  81. case (TT(_LWR)):
  82. if (!record->event.pressed && record->tap.count == TAPPING_TOGGLE) {
  83. // This runs before the TT() handler toggles the layer state, so the current layer state is the opposite of the final one after toggle.
  84. toggle_lwr = !layer_state_is(_LWR);
  85. }
  86. return true;
  87. break;
  88. case (TT(_RSE)):
  89. if (record->event.pressed && record->tap.count == TAPPING_TOGGLE) {
  90. toggle_rse = !layer_state_is(_RSE);
  91. }
  92. return true;
  93. break;
  94. default:
  95. return true;
  96. }
  97. }
  98. layer_state_t layer_state_set_user(layer_state_t state) {
  99. #ifdef RGBLIGHT_ENABLE
  100. rgblight_set_layer_state(0, layer_state_cmp(state, _QW));
  101. rgblight_set_layer_state(1, layer_state_cmp(state, _LWR));
  102. rgblight_set_layer_state(2, layer_state_cmp(state, _RSE));
  103. rgblight_set_layer_state(3, layer_state_cmp(state, _ADJ));
  104. #endif
  105. return update_tri_layer_state(state, _LWR, _RSE, _ADJ);
  106. }
  107. #ifdef RGBLIGHT_ENABLE
  108. layer_state_t default_layer_state_set_user(layer_state_t state) {
  109. rgblight_set_layer_state(0, layer_state_cmp(state, _QW));
  110. return state;
  111. }
  112. void keyboard_post_init_user(void) {
  113. // Enable the LED layers
  114. rgblight_layers = my_rgb_layers;
  115. }
  116. #endif
  117. #ifdef ENCODER_ENABLE
  118. # define MEDIA_KEY_DELAY 10
  119. static inline void my_encoders(const uint8_t index, const bool clockwise) {
  120. if (index == 0) { /* First encoder */
  121. if (IS_LAYER_ON(_LWR)) {
  122. if (clockwise) {
  123. rgblight_decrease_val_noeeprom();
  124. } else {
  125. rgblight_increase_val_noeeprom();
  126. }
  127. } else if (IS_LAYER_ON(_RSE)) {
  128. if (clockwise) {
  129. rgblight_decrease_hue_noeeprom();
  130. } else {
  131. rgblight_increase_hue_noeeprom();
  132. }
  133. } else {
  134. if (clockwise) {
  135. tap_code_delay(KC_VOLD, MEDIA_KEY_DELAY);
  136. } else {
  137. tap_code_delay(KC_VOLU, MEDIA_KEY_DELAY);
  138. }
  139. }
  140. }
  141. }
  142. bool encoder_update_user(uint8_t index, bool clockwise) {
  143. my_encoders(index, clockwise);
  144. return true;
  145. }
  146. #endif