logo

qmk_firmware

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

keymap.c (2725B)


  1. /* Copyright 2020-2021 SergioPoverony
  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 layers num */
  18. enum layer_number {
  19. _HOME = 0,
  20. _RED,
  21. _BLUE,
  22. _GREEN
  23. };
  24. /* Encoder function with layers function */
  25. bool encoder_update_user(uint8_t index, bool clockwise) {
  26. if (index == 0) {
  27. switch (get_highest_layer(layer_state)) {
  28. case _HOME:
  29. if (clockwise) {
  30. tap_code(KC_VOLU);
  31. } else {
  32. tap_code(KC_VOLD);
  33. }
  34. break;
  35. case _RED:
  36. if (clockwise) {
  37. tap_code(KC_MS_WH_UP);
  38. } else {
  39. tap_code(KC_MS_WH_DOWN);
  40. }
  41. break;
  42. case _BLUE:
  43. if (clockwise) {
  44. tap_code(KC_PGUP);
  45. } else {
  46. tap_code(KC_PGDN);
  47. }
  48. break;
  49. case _GREEN:
  50. default:
  51. if (clockwise) {
  52. tap_code16(KC_LEFT);
  53. } else {
  54. tap_code16(KC_RIGHT);
  55. }
  56. break;
  57. }
  58. }
  59. return true;
  60. }
  61. /* Layout */
  62. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  63. [_HOME] = LAYOUT(
  64. KC_1, KC_2, KC_3, KC_4,
  65. TO(_RED),
  66. KC_5, KC_6, KC_7, KC_8
  67. ),
  68. [_RED] = LAYOUT(
  69. KC_Q, KC_W, KC_E, KC_R,
  70. TO(_BLUE),
  71. KC_A, KC_S, KC_D, KC_F
  72. ),
  73. [_BLUE] = LAYOUT(
  74. KC_1, KC_2, KC_3, KC_4,
  75. TO(_GREEN),
  76. KC_5, KC_6, KC_7, KC_8
  77. ),
  78. [_GREEN] = LAYOUT(
  79. KC_1, KC_2, KC_3, KC_4,
  80. TO(_HOME),
  81. KC_5, KC_6, KC_7, KC_8
  82. ),
  83. };
  84. /* Select led layout */
  85. layer_state_t layer_state_set_user(layer_state_t state)
  86. {
  87. turn_off_leds();
  88. switch (get_highest_layer(state))
  89. {
  90. case _HOME:
  91. turn_on_led(RED_LED);
  92. turn_on_led(BLUE_LED);
  93. break;
  94. case _RED:
  95. turn_on_led(RED_LED);
  96. break;
  97. case _BLUE:
  98. turn_on_led(BLUE_LED);
  99. break;
  100. case _GREEN:
  101. turn_on_led(GREEN_LED);
  102. break;
  103. }
  104. return state;
  105. };