keymap.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /* Copyright 2020 Jordan Egstad
  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. /* ==========================================================================
  18. LAYERS
  19. ========================================================================== */
  20. // qwerty
  21. #define _QW 0
  22. // functions
  23. #define _FN 1
  24. /* ==========================================================================
  25. CUSTOM KEYS
  26. ========================================================================== */
  27. // Tap dances
  28. #define TD_ESCP TD(TD_GV_ESC) // Tap for grave, twice for escape
  29. #define TD_MINS TD(TD_MIN) // Tap for minus, twice for equal
  30. #define TD_BRAC TD(TD_BRC) // Tap for open brace, twice for close
  31. // Layers
  32. #define FN_SPC LT(_FN, KC_SPC) // Tap for space, hold for _FN
  33. // Modifiers
  34. #define LG_ZMIN LGUI(KC_EQUAL) // Command + plus (zoom in)
  35. #define LG_ZMOT LGUI(KC_MINUS) // Command + minus (zoom out)
  36. #define MT_SHFT MT(MOD_RSFT, KC_ENT) // Tap for enter, hold for shift
  37. // Tap Dances
  38. enum {
  39. TD_BRC = 0,
  40. TD_MIN,
  41. TD_GV_ESC,
  42. TD_BS
  43. };
  44. // Tap Dance Definitions
  45. qk_tap_dance_action_t tap_dance_actions[] = {
  46. // Tap once for Left Brace, twice for Right Brace
  47. [TD_BRC] = ACTION_TAP_DANCE_DOUBLE(KC_LBRC, KC_RBRC),
  48. //Tap once for Minus, twice for Equal
  49. [TD_MIN] = ACTION_TAP_DANCE_DOUBLE(KC_MINUS, KC_EQUAL),
  50. // Tap once for Grave, tap twice for Escape
  51. [TD_GV_ESC] = ACTION_TAP_DANCE_DOUBLE(KC_GRAVE, KC_ESCAPE)
  52. };
  53. /* ==========================================================================
  54. KEYMAPS
  55. ========================================================================== */
  56. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  57. /* QWERTY (_QW)
  58. * .--------------------------------------------------------------------------------------------------------------------------------------.
  59. * | ESC | 1 | 2 | 3 | 4 | 5 | - | ` | \| | 6 | 7 | 8 | 9 | 0 | - + |
  60. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+-----------------|
  61. * | TAB | Q | W | E | R | T | [ | \ | ] | Y | U | I | O | P | [ ] |
  62. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+-----------------+--------|
  63. * | CAP LK | A | S | D | F | G | | | | H | J | K | L | ; | ' |
  64. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------------------------+--------|
  65. * | LSHIFT | Z | X | C | V | B | | | | N | M | , | . | / | RSHIFT |
  66. * |--------+--------+--------+--------+--------+-----------------+--------+--------+--------+--------+-----------------+--------+--------|
  67. * | ZOOM- | ZOOM+ | LALT | FN | CMD | BSPC | | | FN | SPACE | ENTER | LEFT | UP | DOWN | RIGHT |
  68. * '--------------------------------------------------------------------------------------------------------------------------------------'
  69. */
  70. [_QW] = LAYOUT_ortho_5x15( /* QWERTY */
  71. TD_ESCP, KC_1, KC_2, KC_3, KC_4, KC_5, KC_MINS, KC_GRV, KC_PIPE, KC_6, KC_7, KC_8, KC_9, KC_0, TD_MINS, \
  72. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_LBRC, KC_BSLS, KC_RBRC, KC_Y, KC_U, KC_I, KC_O, KC_P, TD_BRAC, \
  73. _______, KC_A, KC_S, KC_D, KC_F, KC_G, _______, _______, _______, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, \
  74. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, _______, _______, _______, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, MT_SHFT, \
  75. LG_ZMOT, LG_ZMIN, KC_LCTL, KC_LALT, KC_LGUI, KC_BSPC, _______, RESET, _______, FN_SPC, KC_ENT, KC_LEFT, KC_UP, KC_DOWN, KC_RGHT \
  76. ),
  77. /* FUNCTION (_FN)
  78. * .--------------------------------------------------------------------------------------------------------------------------------------.
  79. * | F1 | F2 | F3 | F4 | F5 | F6 | | P | | F7 | F8 | F9 | F10 | F11 | F12 |
  80. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  81. * | | | | | | | RGB HD | RGB HI | | | | | | | |
  82. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  83. * | A-SFT | | | | | | RGB SD | RGB SI | | | LEFT | UP | DOWN | RIGHT | |
  84. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  85. * | RGB | | | | | | RGB VD | RGB VI | | | | | | | |
  86. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------|
  87. * | RESET | | | | | | RGB RMD| RGB MD | | | PLAY | PREV | VOL UP | VOL DN | NEXT |
  88. * '--------------------------------------------------------------------------------------------------------------------------------------'
  89. */
  90. [_FN] = LAYOUT_ortho_5x15( /* FUNCTION */
  91. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, _______, _______, _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, \
  92. _______, _______, _______, _______, _______, _______, RGB_HUD, RGB_HUI, _______, _______, _______, _______, _______, _______, _______, \
  93. KC_ASTG, _______, _______, _______, _______, _______, RGB_SAD, RGB_SAI, _______, _______, KC_LEFT, KC_UP, KC_DOWN, KC_RGHT, _______, \
  94. RGB_TOG, _______, _______, _______, _______, _______, RGB_VAD, RGB_VAI, _______, _______, _______, _______, _______, _______, _______, \
  95. RESET, _______, _______, _______, _______, _______, RGB_RMOD,RGB_MOD, _______, _______, KC_MPLY, KC_MRWD, KC_VOLU, KC_VOLD, KC_MFFD \
  96. ),
  97. };
  98. /* ==========================================================================
  99. LEDs
  100. ========================================================================== */
  101. // RGB MODES
  102. // 1 = Static
  103. // 2-5 = Breathing
  104. // 6-8 = Rainbow
  105. // 9-14 = Swirl
  106. // 15-20 = Snake
  107. // 21-24 = Nightrider
  108. // 25 = Christmas
  109. // 26-30 = Static Gradient
  110. // Default LED colors
  111. uint8_t h = 170;
  112. uint8_t s = 255;
  113. uint8_t v;
  114. // default animation
  115. uint8_t rgbMode = RGBLIGHT_MODE_STATIC_LIGHT;
  116. // boot animation
  117. uint8_t rgbBootMode = RGBLIGHT_MODE_SNAKE;
  118. // boot timeout vars
  119. uint8_t bootComplete = 0;
  120. int bootTimeoutDuration = 2000;
  121. int bootTimeout;
  122. void init_hsv(void) {
  123. // fetch what the brightness was last sesion
  124. v = rgblight_get_val();
  125. rgblight_sethsv(h,s,v);
  126. }
  127. // fetch current HSV vals
  128. void get_hsv(void) {
  129. h = rgblight_get_hue();
  130. s = rgblight_get_sat();
  131. v = rgblight_get_val();
  132. }
  133. // reset HSV vals
  134. void reset_hsv(void) {
  135. int currentV = rgblight_get_val();
  136. rgblight_sethsv(h,s,currentV);
  137. }
  138. // deterimes when to stop bootup animation
  139. void bootupAnimation(void) {
  140. bootComplete = (timer_elapsed(bootTimeout) > bootTimeoutDuration) ? 1 : 0;
  141. if (bootComplete) {
  142. rgblight_mode(rgbMode);
  143. }
  144. }
  145. /* ==========================================================================
  146. INITIALIZATION FUNCTION
  147. ========================================================================== */
  148. void keyboard_post_init_user(void) {
  149. // start a timeout
  150. bootTimeout = timer_read();
  151. // set rgb color
  152. init_hsv();
  153. // init rgb
  154. rgblight_enable();
  155. // animate in snake ledGreende
  156. rgblight_mode(rgbBootMode);
  157. };
  158. /* ==========================================================================
  159. ALWAYS RUNNING
  160. ========================================================================== */
  161. void matrix_scan_user(void) {
  162. // keep an eye on these layers
  163. uint8_t layer = get_highest_layer(layer_state);
  164. // handle boot-up sequence
  165. bootupAnimation();
  166. // watch the brightness for changes
  167. v = rgblight_get_val();
  168. switch (layer) {
  169. case _FN:
  170. // set leds to white
  171. rgblight_sethsv_noeeprom(h,0,v);
  172. break;
  173. default:
  174. break;
  175. }
  176. };
  177. /* ==========================================================================
  178. KEYPRESS CALLBACKS
  179. ========================================================================== */
  180. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  181. // keep an eye on these layers
  182. uint8_t layer = get_highest_layer(layer_state);
  183. switch (keycode) {
  184. case FN_SPC:
  185. // stash and pop color on key down and key up
  186. (record->event.pressed) ? get_hsv() : reset_hsv();
  187. return true;
  188. default:
  189. switch (layer) {
  190. case _QW:
  191. // tick the hue up with each keypress
  192. rgblight_increase_hue();
  193. break;
  194. default:
  195. break;
  196. }
  197. return true; // Process all other keycodes normally
  198. }
  199. }