keymap.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  118. {
  119. // MACRODOWN only works in this function
  120. switch(id) {
  121. case 0:
  122. if (record->event.pressed) {
  123. register_code(KC_RSFT);
  124. } else {
  125. unregister_code(KC_RSFT);
  126. }
  127. break;
  128. }
  129. return MACRO_NONE;
  130. };
  131. void matrix_init_user(void) {
  132. }
  133. void matrix_scan_user(void) {
  134. }
  135. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  136. switch (keycode) {
  137. case QWERTY:
  138. if (record->event.pressed) {
  139. #ifdef AUDIO_ENABLE
  140. PLAY_NOTE_ARRAY(tone_qwerty, false, 0);
  141. #endif
  142. // persistent_default_layer_set(1UL<<_QWERTY);
  143. }
  144. return false;
  145. break;
  146. case LOWER:
  147. if (record->event.pressed) {
  148. //not sure how to have keyboard check mode and set it to a variable, so my work around
  149. //uses another variable that would be set to true after the first time a reactive key is pressed.
  150. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  151. } else {
  152. TOG_STATUS = !TOG_STATUS;
  153. #ifdef RGBLIGHT_ENABLE
  154. rgblight_mode(16);
  155. #endif
  156. }
  157. layer_on(_LOWER);
  158. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  159. } else {
  160. #ifdef RGBLIGHT_ENABLE
  161. rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  162. #endif
  163. TOG_STATUS = false;
  164. layer_off(_LOWER);
  165. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  166. }
  167. return false;
  168. break;
  169. case RAISE:
  170. if (record->event.pressed) {
  171. //not sure how to have keyboard check mode and set it to a variable, so my work around
  172. //uses another variable that would be set to true after the first time a reactive key is pressed.
  173. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  174. } else {
  175. TOG_STATUS = !TOG_STATUS;
  176. #ifdef RGBLIGHT_ENABLE
  177. rgblight_mode(15);
  178. #endif
  179. }
  180. layer_on(_RAISE);
  181. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  182. } else {
  183. #ifdef RGBLIGHT_ENABLE
  184. rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  185. #endif
  186. layer_off(_RAISE);
  187. TOG_STATUS = false;
  188. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  189. }
  190. return false;
  191. break;
  192. case ADJUST:
  193. // FIXME add RGB feedback
  194. if (record->event.pressed) {
  195. layer_on(_ADJUST);
  196. } else {
  197. layer_off(_ADJUST);
  198. }
  199. return false;
  200. break;
  201. case BL_TOGG:
  202. #ifdef ISSI_ENABLE
  203. if (record->event.pressed) {
  204. print("Enabling backlight\n");
  205. issi_init();
  206. }
  207. #endif
  208. return false;
  209. break;
  210. case BL_STEP:
  211. if (record->event.pressed) {
  212. print("Stepping backlight\n");
  213. #ifdef BACKLIGHT_ENABLE
  214. print("Really stepping backlight\n");
  215. backlight_step();
  216. #endif
  217. }
  218. return false;
  219. break;
  220. //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
  221. #ifdef RGBLIGHT_ENABLE
  222. case RGB_MOD:
  223. if (record->event.pressed) {
  224. rgblight_mode(RGB_current_mode);
  225. rgblight_step();
  226. RGB_current_mode = rgblight_config.mode;
  227. }
  228. return false;
  229. break;
  230. #endif
  231. // case BL_INC:
  232. // meira_inc_backlight_level();
  233. // return false;
  234. // break;
  235. }
  236. return true;
  237. }
  238. void led_set_user(uint8_t usb_led) {
  239. }