You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

256 lines
11 KiB

  1. #include QMK_KEYBOARD_H
  2. extern keymap_config_t keymap_config;
  3. #ifdef RGBLIGHT_ENABLE
  4. //Following line allows macro to read current RGB settings
  5. extern rgblight_config_t rgblight_config;
  6. rgblight_config_t RGB_current_config;
  7. #endif
  8. extern uint8_t is_master;
  9. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  10. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  11. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  12. // entirely and just use numbers.
  13. enum layer_number {
  14. _QWERTY = 0,
  15. _LOWER,
  16. _RAISE,
  17. _ADJUST
  18. };
  19. enum custom_keycodes {
  20. QWERTY = SAFE_RANGE,
  21. COLEMAK,
  22. DVORAK,
  23. LOWER,
  24. RAISE,
  25. ADJUST,
  26. BACKLIT,
  27. KANA,
  28. EISU,
  29. RGBRST
  30. };
  31. enum macro_keycodes {
  32. KC_SAMPLEMACRO,
  33. };
  34. //Macros
  35. #define M_SAMPLE M(KC_SAMPLEMACRO)
  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. * | Ctrl | A | S | D | F | G | | H | J | K | L | ; | ' |
  42. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  43. * | Shift| Z | X | C | V | B | | N | M | , | . | / |Enter |
  44. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  45. * | Esc |ADJUST| Alt | GUI |LOWER |Space | | Space| RAISE| KANA | Left | Down | Right|
  46. * `-----------------------------------------' `-----------------------------------------'
  47. */
  48. [_QWERTY] = LAYOUT_ortho_4x12(
  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_LCTL, 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, KC_SLSH, KC_ENT , \
  52. KC_ESC, ADJUST, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KANA, KC_LEFT, KC_DOWN, KC_RGHT \
  53. ),
  54. /* Lower
  55. * ,-----------------------------------------. ,-----------------------------------------.
  56. * | ~ | ! | @ | # | $ | % | | ^ | & | * | ( | ) | |
  57. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  58. * | | | | | | | | - | _ | + | { | } | | |
  59. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  60. * | | | | | | | | | | | | UP | |
  61. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  62. * | | | | | | | | | | | | | |
  63. * `-----------------------------------------' `-----------------------------------------'
  64. */
  65. [_LOWER] = LAYOUT_ortho_4x12( \
  66. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, _______, \
  67. _______, _______, _______, _______, _______, _______, KC_MINS, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, \
  68. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_UP, _______, \
  69. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
  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 | | | | ? | |
  78. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  79. * | | | | | | | | | | Next | Vol- | Vol+ | Play |
  80. * `-----------------------------------------' `-----------------------------------------'
  81. */
  82. [_RAISE] = LAYOUT_ortho_4x12( \
  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, _______, _______, _______, S(KC_SLSH), _______, \
  86. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
  87. ),
  88. /* Adjust (Lower + Raise)
  89. * ,-----------------------------------------. ,-----------------------------------------.
  90. * | | Reset|RGBRST| | | | | | | | | | Ins |
  91. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  92. * | |RGB ON| HUE+ | SAT+ | VAL+ | Mac | | Win | - | = |Print |ScLock|Pause |
  93. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  94. * | | MODE | HUE- | SAT- | VAL- | | | | | | |PageUp| |
  95. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  96. * | | | | EISU | EISU | EISU | | KANA | KANA | KANA | Home |PageDn| End |
  97. * `-----------------------------------------' `-----------------------------------------'
  98. */
  99. [_ADJUST] = LAYOUT_ortho_4x12( \
  100. _______, QK_BOOT, RGBRST, _______, _______, _______, _______, _______, _______, _______, _______, KC_INS, \
  101. _______, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, AG_NORM, AG_SWAP, KC_MINS, KC_EQL, KC_PSCR, KC_SCRL, KC_PAUS,\
  102. _______, RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD, _______, _______, _______, _______, _______, KC_PGUP, _______,\
  103. _______, _______, _______, EISU, EISU, EISU, KANA, KANA, KANA, KC_HOME, KC_PGDN, KC_END\
  104. )
  105. };
  106. // define variables for reactive RGB
  107. bool TOG_STATUS = false;
  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_noeeprom(RGB_current_config.mode);
  113. #endif
  114. layer_on(layer3);
  115. } else {
  116. layer_off(layer3);
  117. }
  118. }
  119. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  120. switch (keycode) {
  121. case QWERTY:
  122. if (record->event.pressed) {
  123. set_single_persistent_default_layer(_QWERTY);
  124. }
  125. return false;
  126. break;
  127. case LOWER:
  128. if (record->event.pressed) {
  129. //not sure how to have keyboard check mode and set it to a variable, so my work around
  130. //uses another variable that would be set to true after the first time a reactive key is pressed.
  131. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  132. } else {
  133. TOG_STATUS = !TOG_STATUS;
  134. #ifdef RGBLIGHT_ENABLE
  135. rgblight_mode_noeeprom(16);
  136. #endif
  137. }
  138. layer_on(_LOWER);
  139. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  140. } else {
  141. #ifdef RGBLIGHT_ENABLE
  142. rgblight_mode_noeeprom(RGB_current_config.mode); // revert RGB to initial mode prior to RGB mode change
  143. #endif
  144. TOG_STATUS = false;
  145. layer_off(_LOWER);
  146. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  147. }
  148. return false;
  149. break;
  150. case RAISE:
  151. if (record->event.pressed) {
  152. //not sure how to have keyboard check mode and set it to a variable, so my work around
  153. //uses another variable that would be set to true after the first time a reactive key is pressed.
  154. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  155. } else {
  156. TOG_STATUS = !TOG_STATUS;
  157. #ifdef RGBLIGHT_ENABLE
  158. rgblight_mode_noeeprom(15);
  159. #endif
  160. }
  161. layer_on(_RAISE);
  162. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  163. } else {
  164. #ifdef RGBLIGHT_ENABLE
  165. rgblight_mode_noeeprom(RGB_current_config.mode); // revert RGB to initial mode prior to RGB mode change
  166. #endif
  167. layer_off(_RAISE);
  168. TOG_STATUS = false;
  169. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  170. }
  171. return false;
  172. break;
  173. case ADJUST:
  174. if (record->event.pressed) {
  175. layer_on(_ADJUST);
  176. } else {
  177. layer_off(_ADJUST);
  178. }
  179. return false;
  180. break;
  181. //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
  182. case RGB_MOD:
  183. #ifdef RGBLIGHT_ENABLE
  184. if (record->event.pressed) {
  185. rgblight_mode_noeeprom(RGB_current_config.mode);
  186. rgblight_step();
  187. RGB_current_config.mode = rgblight_config.mode;
  188. }
  189. #endif
  190. return false;
  191. break;
  192. case EISU:
  193. if (record->event.pressed) {
  194. if(keymap_config.swap_lalt_lgui==false){
  195. register_code(KC_LNG2);
  196. }else{
  197. SEND_STRING(SS_LALT("`"));
  198. }
  199. } else {
  200. unregister_code(KC_LNG2);
  201. }
  202. return false;
  203. break;
  204. case KANA:
  205. if (record->event.pressed) {
  206. if(keymap_config.swap_lalt_lgui==false){
  207. register_code(KC_LNG1);
  208. }else{
  209. SEND_STRING(SS_LALT("`"));
  210. }
  211. } else {
  212. unregister_code(KC_LNG1);
  213. }
  214. return false;
  215. break;
  216. case RGBRST:
  217. #ifdef RGBLIGHT_ENABLE
  218. if (record->event.pressed) {
  219. eeconfig_update_rgblight_default();
  220. rgblight_enable();
  221. RGB_current_config = rgblight_config;
  222. }
  223. #endif
  224. break;
  225. }
  226. return true;
  227. }
  228. void matrix_init_user(void) {
  229. #ifdef RGBLIGHT_ENABLE
  230. rgblight_init();
  231. RGB_current_config = rgblight_config;
  232. #endif
  233. }