keymap.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /* Copyright 2017 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 "meira.h"
  17. #include "issi.h"
  18. #include "lighting.h"
  19. #ifdef RGBLIGHT_ENABLE
  20. //Following line allows macro to read current RGB settings
  21. extern rgblight_config_t rgblight_config;
  22. #endif
  23. #define _QWERTY 0
  24. #define _LOWER 1
  25. #define _RAISE 2
  26. #define _ADJUST 16
  27. enum custom_keycodes {
  28. QWERTY = SAFE_RANGE,
  29. LOWER,
  30. RAISE,
  31. ADJUST,
  32. };
  33. // define variables for reactive RGB
  34. bool TOG_STATUS = false;
  35. int RGB_current_mode;
  36. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  37. /* Qwerty
  38. * ,-----------------------------------------------------------------------------------.
  39. * | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp |
  40. * |------+------+------+------+------+-------------+------+------+------+------+------|
  41. * | Esc | A | S | D | F | G | H | J | K | L | ; | ' |
  42. * |------+------+------+------+------+------|------+------+------+------+------+------|
  43. * | Shift| Z | X | C | V | B | N | M | , | . |//GUI |Enter |
  44. * |------+------+------+------+------+------+------+------+------+------+------+------|
  45. * | Ctrl | GUI | Alt | GUI |Lower |Space |Enter |Raise | Left | Down | Up |Right |
  46. * `-----------------------------------------------------------------------------------'
  47. */
  48. [_QWERTY] = KEYMAP( \
  49. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, \
  50. KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, \
  51. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, GUI_T(KC_SLSH), KC_ENT, \
  52. KC_LCTL, KC_LGUI, KC_LALT, KC_RGUI, LOWER, KC_SPC, KC_ENT, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \
  53. ),
  54. /* Lower
  55. * ,-----------------------------------------------------------------------------------.
  56. * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | DEL |
  57. * |------+------+------+------+------+-------------+------+------+------+------+------|
  58. * | | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | |
  59. * |------+------+------+------+------+------|------+------+------+------+------+------|
  60. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | | | |
  61. * |------+------+------+------+------+------+------+------+------+------+------+------|
  62. * | | | | | | | | | Home | PgUp | PgDn | End |
  63. * `-----------------------------------------------------------------------------------'
  64. */
  65. [_LOWER] = KEYMAP( \
  66. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL, \
  67. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, \
  68. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, S(KC_NUHS), S(KC_NUBS), _______, _______, _______, \
  69. _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END \
  70. ),
  71. /* Raise
  72. * ,-----------------------------------------------------------------------------------.
  73. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | DEL |
  74. * |------+------+------+------+------+-------------+------+------+------+------+------|
  75. * | | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ |
  76. * |------+------+------+------+------+------|------+------+------+------+------+------|
  77. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / | | | |
  78. * |------+------+------+------+------+------+------+------+------+------+------+------|
  79. * | | | | | | | | | Home | PgUp | PgDn | End |
  80. * `-----------------------------------------------------------------------------------'
  81. */
  82. [_RAISE] = KEYMAP( \
  83. KC_GRV , KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL, \
  84. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, \
  85. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, _______, _______, _______, \
  86. _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END \
  87. ),
  88. /* Adjust (Lower + Raise)
  89. * ,-----------------------------------------------------------------------------------.
  90. * | | Reset| | | | | | | | | | Del |
  91. * |------+------+------+------+------+-------------+------+------+------+------+------|
  92. * | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty| | | | |
  93. * |------+------+------+------+------+------|------+------+------+------+------+------|
  94. * | | | | | | | | | | | | |
  95. * |------+------+------+------+------+------+------+------+------+------+------+------|
  96. * | | | | | | | | | | | |
  97. * `-----------------------------------------------------------------------------------'
  98. */
  99. [_ADJUST] = KEYMAP( \
  100. BL_TOGG, RESET, _______, KC_MRWD, KC_MPLY, KC_MFFD, KC_PSCR, _______, KC_MUTE, KC_VOLD, KC_VOLU, KC_DEL, \
  101. BL_STEP, RGB_MOD, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, _______, _______, _______, _______, \
  102. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  103. _______, KC_PSCR, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
  104. )
  105. };
  106. // Setting ADJUST layer RGB back to default
  107. void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  108. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
  109. #ifdef RGBLIGHT_ENABLE
  110. rgblight_mode(RGB_current_mode);
  111. #endif
  112. layer_on(layer3);
  113. } else {
  114. layer_off(layer3);
  115. }
  116. }
  117. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  118. switch (keycode) {
  119. case QWERTY:
  120. if (record->event.pressed) {
  121. #ifdef AUDIO_ENABLE
  122. PLAY_SONG(tone_qwerty);
  123. #endif
  124. // persistent_default_layer_set(1UL<<_QWERTY);
  125. }
  126. return false;
  127. break;
  128. case LOWER:
  129. if (record->event.pressed) {
  130. //not sure how to have keyboard check mode and set it to a variable, so my work around
  131. //uses another variable that would be set to true after the first time a reactive key is pressed.
  132. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  133. } else {
  134. TOG_STATUS = !TOG_STATUS;
  135. #ifdef RGBLIGHT_ENABLE
  136. rgblight_mode(16);
  137. #endif
  138. }
  139. layer_on(_LOWER);
  140. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  141. } else {
  142. #ifdef RGBLIGHT_ENABLE
  143. rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  144. #endif
  145. TOG_STATUS = false;
  146. layer_off(_LOWER);
  147. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  148. }
  149. return false;
  150. break;
  151. case RAISE:
  152. if (record->event.pressed) {
  153. //not sure how to have keyboard check mode and set it to a variable, so my work around
  154. //uses another variable that would be set to true after the first time a reactive key is pressed.
  155. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  156. } else {
  157. TOG_STATUS = !TOG_STATUS;
  158. #ifdef RGBLIGHT_ENABLE
  159. rgblight_mode(15);
  160. #endif
  161. }
  162. layer_on(_RAISE);
  163. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  164. } else {
  165. #ifdef RGBLIGHT_ENABLE
  166. rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  167. #endif
  168. layer_off(_RAISE);
  169. TOG_STATUS = false;
  170. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  171. }
  172. return false;
  173. break;
  174. case ADJUST:
  175. // FIXME add RGB feedback
  176. if (record->event.pressed) {
  177. layer_on(_ADJUST);
  178. } else {
  179. layer_off(_ADJUST);
  180. }
  181. return false;
  182. break;
  183. case BL_TOGG:
  184. #ifdef ISSI_ENABLE
  185. if (record->event.pressed) {
  186. print("Enabling backlight\n");
  187. issi_init();
  188. }
  189. #endif
  190. return false;
  191. break;
  192. case BL_STEP:
  193. if (record->event.pressed) {
  194. print("Stepping backlight\n");
  195. #ifdef BACKLIGHT_ENABLE
  196. print("Really stepping backlight\n");
  197. backlight_step();
  198. #endif
  199. }
  200. return false;
  201. break;
  202. //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
  203. #ifdef RGBLIGHT_ENABLE
  204. case RGB_MOD:
  205. if (record->event.pressed) {
  206. rgblight_mode(RGB_current_mode);
  207. rgblight_step();
  208. RGB_current_mode = rgblight_config.mode;
  209. }
  210. return false;
  211. break;
  212. #endif
  213. // case BL_INC:
  214. // meira_inc_backlight_level();
  215. // return false;
  216. // break;
  217. }
  218. return true;
  219. }
  220. void led_set_user(uint8_t usb_led) {
  221. }