keymap.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* Copyright 2019-2020 DMQ Design
  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. #include "midi.h"
  18. #include "qmk_midi.h"
  19. enum layers
  20. {
  21. _BL,
  22. _FL,
  23. _TL
  24. };
  25. uint8_t currentLayer;
  26. //The below layers are intentionally empty in order to give a good starting point for how to configure multiple layers.
  27. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  28. [_BL] = LAYOUT(/* Base */
  29. KC_KP_7, KC_KP_8, KC_KP_9, TO(_BL),
  30. KC_KP_4, KC_KP_5, KC_KP_6, TO(_FL),
  31. KC_KP_1, KC_KP_2, KC_KP_3, TO(_TL),
  32. KC_KP_0, RGB_TOG, RGB_MOD
  33. ),
  34. [_FL] = LAYOUT(/* Base */
  35. KC_NO, KC_NO, KC_NO, KC_TRNS,
  36. KC_NO, KC_NO, KC_NO, KC_TRNS,
  37. KC_NO, KC_NO, KC_NO, KC_TRNS,
  38. KC_MS_BTN1, KC_NO, KC_MS_BTN2
  39. ),
  40. [_TL] = LAYOUT(/* Base */
  41. KC_NO, KC_NO, KC_NO, KC_TRNS,
  42. KC_NO, KC_NO, KC_NO, KC_TRNS,
  43. KC_NO, KC_NO, KC_NO, KC_TRNS,
  44. KC_NO, KC_NO, KC_NO
  45. )
  46. };
  47. bool encoder_update_user(uint8_t index, bool clockwise) {
  48. if (index == 0) { /* First encoder */
  49. switch (currentLayer) { //break each encoder update into a switch statement for the current layer
  50. case _BL:
  51. if (clockwise) {
  52. rgblight_increase_hue();
  53. } else {
  54. rgblight_decrease_hue();
  55. }
  56. break;
  57. case _FL:
  58. if (clockwise) {
  59. midi_send_cc(&midi_device, 0, 0x14, 1);
  60. } else {
  61. midi_send_cc(&midi_device, 0, 0x15, 1);
  62. }
  63. break;
  64. case _TL:
  65. if (clockwise) {
  66. midi_send_cc(&midi_device, 0, 0x1A, 1);
  67. } else {
  68. midi_send_cc(&midi_device, 0, 0x1B, 1);
  69. }
  70. break;
  71. }
  72. } else if (index == 1) { /* Second encoder */
  73. switch (currentLayer) {
  74. case _BL:
  75. if (clockwise) {
  76. tap_code(KC_VOLU);
  77. } else {
  78. tap_code(KC_VOLD);
  79. }
  80. break;
  81. case _FL:
  82. if (clockwise) {
  83. midi_send_cc(&midi_device, 0, 0x16, 1);
  84. } else {
  85. midi_send_cc(&midi_device, 0, 0x17, 1);
  86. }
  87. break;
  88. case _TL:
  89. if (clockwise) {
  90. midi_send_cc(&midi_device, 0, 0x1C, 1);
  91. } else {
  92. midi_send_cc(&midi_device, 0, 0x1D, 1);
  93. }
  94. break;
  95. }
  96. } else if (index == 2) { /* Third encoder */
  97. switch (currentLayer) {
  98. case _BL:
  99. if (clockwise) {
  100. rgblight_increase_val();
  101. } else {
  102. rgblight_decrease_val();
  103. }
  104. break;
  105. case _FL:
  106. if (clockwise) {
  107. midi_send_cc(&midi_device, 0, 0x18, 1);
  108. } else {
  109. midi_send_cc(&midi_device, 0, 0x19, 1);
  110. }
  111. break;
  112. case _TL:
  113. if (clockwise) {
  114. midi_send_cc(&midi_device, 0, 0x1E, 1);
  115. } else {
  116. midi_send_cc(&midi_device, 0, 0x1F, 1);
  117. }
  118. break;
  119. }
  120. }
  121. return true;
  122. }
  123. layer_state_t layer_state_set_user(layer_state_t state) { //This will run every time the layer is updated
  124. currentLayer = get_highest_layer(state);
  125. switch (currentLayer) {
  126. case _BL:
  127. setrgb(RGB_WHITE, &led[0]); //Set the top LED to white for the bottom layer
  128. setrgb(0, 0, 0, &led[1]);
  129. setrgb(0, 0, 0, &led[2]);
  130. break;
  131. case _FL:
  132. setrgb(0, 0, 0, &led[0]); //Set the middle LED to white for the middle layer
  133. setrgb(RGB_WHITE, &led[1]);
  134. setrgb(0, 0, 0, &led[2]);
  135. break;
  136. case _TL:
  137. setrgb(0, 0, 0, &led[0]);
  138. setrgb(0, 0, 0, &led[1]);
  139. setrgb(RGB_WHITE, &led[2]); //Set the bottom LED to white for the top layer
  140. break;
  141. }
  142. rgblight_set();
  143. return state;
  144. }