keymap.c 11 KB

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