2
0

keymap.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* Copyright 2019 Cole Markham
  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. #ifdef RGBLIGHT_ENABLE
  18. //Following line allows macro to read current RGB settings
  19. extern rgblight_config_t rgblight_config;
  20. #endif
  21. #define _QWERTY 0
  22. #define _COLEMAK 1
  23. #define _DVORAK 2
  24. #define _LOWER 3
  25. #define _RAISE 4
  26. #define _ADJUST 16
  27. enum custom_keycodes {
  28. QWERTY = SAFE_RANGE,
  29. COLEMAK,
  30. DVORAK,
  31. LOWER,
  32. RAISE,
  33. ADJUST,
  34. };
  35. // define variables for reactive RGB
  36. bool TOG_STATUS = false;
  37. int RGB_current_mode;
  38. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  39. [_QWERTY] = LAYOUT_all(
  40. KC_F1, KC_F2, 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_DEL, KC_PGUP,\
  41. KC_F3, KC_F4, 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_PGDN,\
  42. KC_F5, KC_F6, 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_HOME,\
  43. KC_F7, KC_F8, KC_LSFT,KC_Z,KC_X,KC_C,KC_V,KC_B,KC_N,KC_M,KC_COMM,KC_DOT,KC_SLASH,KC_RSFT,KC_UP,KC_END,\
  44. KC_F9, KC_F10, KC_LCTL,KC_LGUI,KC_LALT, RAISE, KC_SPACE, LOWER, KC_RALT,KC_APP,KC_RCTRL,KC_LEFT,KC_DOWN,KC_RIGHT),
  45. [_RAISE] = LAYOUT_all(
  46. RGB_MOD, _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, _______,\
  47. _______, _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______,\
  48. _______, _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______,\
  49. _______, _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,\
  50. _______, _______, _______,_______,_______, _______, _______, _______, _______,_______,_______,_______,_______,_______),
  51. [_LOWER] = LAYOUT_all(
  52. RGB_MOD, _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, _______,\
  53. _______, _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______,\
  54. _______, _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______,\
  55. _______, _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,\
  56. _______, _______, _______,_______,_______, _______, _______, _______, _______,_______,_______,_______,_______,_______),
  57. [_ADJUST] = LAYOUT_all(
  58. RESET, _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, _______,\
  59. _______, _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______,\
  60. _______, _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______,\
  61. _______, _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,\
  62. _______, _______, _______,_______,_______, _______, _______, _______, _______,_______,_______,_______,_______,_______)
  63. };
  64. // Setting ADJUST layer RGB back to default
  65. void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  66. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
  67. #ifdef RGBLIGHT_ENABLE
  68. rgblight_mode(RGB_current_mode);
  69. #endif
  70. layer_on(layer3);
  71. } else {
  72. layer_off(layer3);
  73. }
  74. }
  75. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  76. {
  77. // MACRODOWN only works in this function
  78. switch(id) {
  79. case 0:
  80. if (record->event.pressed) {
  81. register_code(KC_RSFT);
  82. } else {
  83. unregister_code(KC_RSFT);
  84. }
  85. break;
  86. }
  87. return MACRO_NONE;
  88. };
  89. #ifdef AUDIO_ENABLE
  90. float tone_qwerty[][2] = SONG(QWERTY_SOUND);
  91. #endif
  92. void matrix_init_user(void) {
  93. }
  94. void matrix_scan_user(void) {
  95. }
  96. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  97. switch (keycode) {
  98. case LOWER:
  99. if (record->event.pressed) {
  100. //not sure how to have keyboard check mode and set it to a variable, so my work around
  101. //uses another variable that would be set to true after the first time a reactive key is pressed.
  102. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  103. } else {
  104. TOG_STATUS = !TOG_STATUS;
  105. #ifdef RGBLIGHT_ENABLE
  106. rgblight_mode(16);
  107. #endif
  108. }
  109. layer_on(_LOWER);
  110. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  111. } else {
  112. #ifdef RGBLIGHT_ENABLE
  113. rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  114. #endif
  115. TOG_STATUS = false;
  116. layer_off(_LOWER);
  117. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  118. }
  119. return false;
  120. break;
  121. case RAISE:
  122. if (record->event.pressed) {
  123. //not sure how to have keyboard check mode and set it to a variable, so my work around
  124. //uses another variable that would be set to true after the first time a reactive key is pressed.
  125. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  126. } else {
  127. TOG_STATUS = !TOG_STATUS;
  128. #ifdef RGBLIGHT_ENABLE
  129. rgblight_mode(15);
  130. #endif
  131. }
  132. layer_on(_RAISE);
  133. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  134. } else {
  135. #ifdef RGBLIGHT_ENABLE
  136. rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  137. #endif
  138. layer_off(_RAISE);
  139. TOG_STATUS = false;
  140. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  141. }
  142. return false;
  143. break;
  144. case ADJUST:
  145. // FIXME add RGB feedback
  146. if (record->event.pressed) {
  147. layer_on(_ADJUST);
  148. } else {
  149. layer_off(_ADJUST);
  150. }
  151. return false;
  152. break;
  153. break;
  154. //led operations - RGB mode change now updates the RGB_current_mode to allow the right RGB mode to be set after reactive keys are released
  155. #ifdef RGBLIGHT_ENABLE
  156. case RGB_MOD:
  157. if (record->event.pressed) {
  158. rgblight_mode(RGB_current_mode);
  159. rgblight_step();
  160. RGB_current_mode = rgblight_config.mode;
  161. }
  162. return false;
  163. break;
  164. #endif
  165. }
  166. return true;
  167. }
  168. void led_set_user(uint8_t usb_led) {
  169. }