keymap.c 11 KB

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