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.

222 lines
7.3 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. // this is the style you want to emulate.
  2. // This is the canonical layout file for the Quantum project. If you want to add another keyboard,
  3. #include QMK_KEYBOARD_H
  4. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  5. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  6. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  7. // entirely and just use numbers.
  8. enum mitosis_layers
  9. {
  10. _MALT,
  11. _SHIFTED,
  12. _FUNCTION,
  13. _FUNCSHIFT
  14. };
  15. enum mitosis_keycodes
  16. {
  17. FNKEY = SAFE_RANGE,
  18. SHIFT
  19. };
  20. // Macro definitions for readability
  21. enum mitosis_macros
  22. {
  23. VOLU,
  24. VOLD,
  25. ESCM
  26. };
  27. #define LONGPRESS_DELAY 150
  28. #define LAYER_TOGGLE_DELAY 300
  29. // Fillers to make layering more clear
  30. #define _______ KC_TRNS
  31. #define XXXXXXX KC_NO
  32. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  33. [_MALT] = LAYOUT( /* Malt Layout, customised for reduced columns (ex: quote and shift locations) */
  34. KC_Q, KC_P, KC_Y, KC_C, KC_B, KC_V, KC_M, KC_U, KC_Z, KC_L,
  35. KC_A, KC_N, KC_I, KC_S, KC_F, KC_D, KC_T, KC_H, KC_O, KC_R,
  36. KC_COMM, KC_DOT, KC_J, KC_G, KC_SLSH, KC_SCLN, KC_W, KC_K, KC_QUOT, KC_X,
  37. M(VOLU), M(ESCM), KC_TAB, KC_LCTL, KC_LALT, KC_ENT, KC_DEL, KC_PGUP,
  38. M(VOLD), KC_LGUI, KC_E, FNKEY, SHIFT, KC_SPC, KC_BSPC, KC_PGDN
  39. ),
  40. [_SHIFTED] = LAYOUT( /* Shifted Layer, layered so that tri_layer can be used, or selectively
  41. able to modify individual key's shifted behaviour */
  42. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  43. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  44. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  45. _______, _______, _______, _______, _______, _______, _______, _______,
  46. _______, _______, _______, _______, _______, _______, _______, _______
  47. ),
  48. [_FUNCTION] = LAYOUT( /* Function Layer, primary alternative layer featuring numpad on right hand,
  49. cursor keys on left hand, and all symbols*/
  50. KC_AMPR, KC_PERC, KC_UP, KC_CIRC, KC_PIPE, KC_LBRC, KC_7, KC_8, KC_9, KC_MINS,
  51. KC_AT, KC_LEFT, KC_DOWN, KC_RGHT, KC_HASH, KC_LPRN, KC_4, KC_5, KC_6, KC_PLUS,
  52. KC_ASTR, KC_UNDS, KC_EXLM, KC_DLR, KC_BSLS, KC_LCBR, KC_1, KC_2, KC_3, KC_ENT,
  53. KC_HOME, KC_GRV, KC_PWR, _______, _______, KC_EQL, KC_TILD, KC_DOT,
  54. KC_END, _______, _______, _______, _______, KC_0, _______, KC_PSCR
  55. ),
  56. [_FUNCSHIFT] = LAYOUT( /* Function Shifted Layer, secondary alternative layer with closing brackets,
  57. and F-keys under their numpad equivalents*/
  58. _______, _______, _______, _______, _______, KC_RBRC, KC_F7, KC_F8, KC_F9, KC_F10,
  59. _______, _______, _______, _______, _______, KC_RPRN, KC_F4, KC_F5, KC_F6, KC_F11,
  60. _______, _______, _______, _______, _______, KC_RCBR, KC_F1, KC_F2, KC_F3, KC_F12,
  61. _______, _______, _______, _______, _______, _______, _______, _______,
  62. _______, _______, _______, _______, _______, _______, _______, _______
  63. )
  64. };
  65. const uint16_t PROGMEM fn_actions[] = {
  66. };
  67. static uint16_t key_timer;
  68. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  69. {
  70. // MACRODOWN only works in this function
  71. switch(id) {
  72. //switch multiplexing for media, short tap for volume up, long press for play/pause
  73. case VOLU:
  74. if (record->event.pressed) {
  75. key_timer = timer_read(); // if the key is being pressed, we start the timer.
  76. } else { // this means the key was just released, so we can figure out how long it was pressed for (tap or "held down").
  77. if (timer_elapsed(key_timer) > LONGPRESS_DELAY) { // LONGPRESS_DELAY being 150ms, the threshhold we pick for counting something as a tap.
  78. return MACRO(T(MPLY), END);
  79. } else {
  80. return MACRO(T(VOLU), END);
  81. }
  82. }
  83. break;
  84. //switch multiplexing for media, short tap for volume down, long press for next track
  85. case VOLD:
  86. if (record->event.pressed) {
  87. key_timer = timer_read();
  88. } else {
  89. if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
  90. return MACRO(T(MNXT), END);
  91. } else {
  92. return MACRO(T(VOLD), END);
  93. }
  94. }
  95. break;
  96. //switch multiplexing for escape, short tap for escape, long press for context menu
  97. case ESCM:
  98. if (record->event.pressed) {
  99. key_timer = timer_read();
  100. } else {
  101. if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
  102. return MACRO(T(APP), END);
  103. } else {
  104. return MACRO(T(ESC), END);
  105. }
  106. }
  107. break;
  108. break;
  109. }
  110. return MACRO_NONE;
  111. };
  112. static bool singular_key = false;
  113. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  114. uint8_t layer;
  115. layer = biton32(layer_state); // get the current layer
  116. //custom layer handling for tri_layer,
  117. switch (keycode) {
  118. case FNKEY:
  119. if (record->event.pressed) {
  120. key_timer = timer_read();
  121. singular_key = true;
  122. layer_on(_FUNCTION);
  123. } else {
  124. if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
  125. layer_off(_FUNCTION);
  126. }
  127. }
  128. update_tri_layer(_FUNCTION, _SHIFTED, _FUNCSHIFT);
  129. return false;
  130. break;
  131. //SHIFT is handled as LSHIFT in the general case
  132. case SHIFT:
  133. if (record->event.pressed) {
  134. key_timer = timer_read();
  135. singular_key = true;
  136. layer_on(_SHIFTED);
  137. register_code(KC_LSFT);
  138. } else {
  139. if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
  140. layer_off(_SHIFTED);
  141. unregister_code(KC_LSFT);
  142. }
  143. }
  144. update_tri_layer(_FUNCTION, _SHIFTED, _FUNCSHIFT);
  145. return false;
  146. break;
  147. //If any other key was pressed during the layer mod hold period,
  148. //then the layer mod was used momentarily, and should block latching
  149. default:
  150. singular_key = false;
  151. break;
  152. }
  153. //FUNCSHIFT has been shifted by the SHIFT handling, some keys need to be excluded
  154. if (layer == _FUNCSHIFT) {
  155. //F1-F12 should be sent as unshifted keycodes,
  156. //and ] needs to be unshifted or it is sent as }
  157. if ( (keycode >= KC_F1 && keycode <= KC_F12)
  158. || keycode == KC_RBRC ) {
  159. if (record->event.pressed) {
  160. unregister_mods(MOD_LSFT);
  161. } else {
  162. register_mods(MOD_LSFT);
  163. }
  164. }
  165. }
  166. return true;
  167. };
  168. void matrix_scan_user(void) {
  169. uint8_t layer = biton32(layer_state);
  170. switch (layer) {
  171. case _MALT:
  172. set_led_off;
  173. break;
  174. case _FUNCTION:
  175. set_led_blue;
  176. break;
  177. case _SHIFTED:
  178. set_led_red;
  179. break;
  180. case _FUNCSHIFT:
  181. set_led_green;
  182. break;
  183. default:
  184. break;
  185. }
  186. };