logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

keymap.c (14071B)


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