keymap.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. #include "roadkit.h"
  2. #include "action_layer.h"
  3. #include "eeconfig.h"
  4. extern keymap_config_t keymap_config;
  5. #ifdef BACKLIGHT_ENABLE
  6. #include "backlight.h"
  7. #endif
  8. #ifdef AUDIO_ENABLE
  9. #include "audio.h"
  10. #endif
  11. void backlight_toggle(void){
  12. };
  13. enum roadkit_layers {
  14. _NUMPAD,
  15. _NAVIGATION,
  16. _EXCEL,
  17. _ADJUST,
  18. _DYN
  19. };
  20. enum minivan_keycodes {
  21. NUMPAD = SAFE_RANGE,
  22. NAVIGATION,
  23. EXCEL,
  24. NUMPAD_LOCK,
  25. NAVIGATION_LOCK,
  26. EXCEL_LOCK,
  27. PARENS,
  28. BRACKETS,
  29. BRACES,
  30. BACKLIT,
  31. MACSLEEP,
  32. DYNAMIC_MACRO_RANGE,
  33. };
  34. #include "dynamic_macro.h"
  35. // Fillers to make keymaps cleaner looking
  36. #define _______ KC_TRNS
  37. #define XXXXXXX KC_NO
  38. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  39. [_NUMPAD] = /* Numpad */
  40. KEYMAP(KC_KP_7, KC_KP_8, KC_KP_9, KC_KP_PLUS, \
  41. KC_KP_4, KC_KP_5, KC_KP_6, \
  42. KC_KP_1, KC_KP_2, KC_KP_3, NAVIGATION, \
  43. EXCEL, KC_KP_DOT),
  44. [_EXCEL] = /* Excel related */
  45. KEYMAP(KC_KP_SLASH, KC_KP_ASTERISK, KC_MINS, KC_TAB, \
  46. KC_QUOT, KC_KP_EQUAL, PARENS , \
  47. KC_DQT, BRACKETS, BRACES, _______, \
  48. _______, MO(_DYN)),
  49. [_NAVIGATION] = /* Navigation */
  50. KEYMAP(KC_HOME, _______, KC_PGUP, KC_TAB, \
  51. KC_END, KC_UP, KC_PGDN, \
  52. KC_LEFT, KC_DOWN, KC_RIGHT, _______, \
  53. _______, MO(_DYN)),
  54. [_ADJUST] = /* Adjustments */
  55. KEYMAP(KC_NUMLOCK, MACSLEEP, BACKLIT, _______, \
  56. KC_BSPC, _______, KC_DEL, \
  57. EXCEL_LOCK, NUMPAD_LOCK, NAVIGATION_LOCK, _______, \
  58. _______, _______),
  59. [_DYN] = /* DYNAMIC MACRO */
  60. KEYMAP(DYN_REC_START1, DYN_REC_START2, _______, _______, \
  61. _______, _______, _______, \
  62. DYN_MACRO_PLAY1, DYN_MACRO_PLAY2, _______, _______, \
  63. _______, _______),
  64. };
  65. const uint16_t PROGMEM fn_actions[] = {
  66. };
  67. #ifdef AUDIO_ENABLE
  68. float tone_startup[][2] = SONG(STARTUP_SOUND);
  69. float tone_numpad[][2] = SONG(QWERTY_SOUND);
  70. float tone_excel[][2] = SONG(DVORAK_SOUND);
  71. float tone_navigation[][2] = SONG(COLEMAK_SOUND);
  72. float tone_plover[][2] = SONG(PLOVER_SOUND);
  73. float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND);
  74. float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
  75. float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
  76. #endif
  77. void persistant_default_layer_set(uint16_t default_layer) {
  78. eeconfig_update_default_layer(default_layer);
  79. default_layer_set(default_layer);
  80. }
  81. bool fn_tap_used = false; // sets to false when space is pressed,
  82. // sets to true when any other key is pressed,
  83. //when space is lifted, if another key was prssed, don't send space.
  84. uint16_t fn_keycode = 0; // stores which spacebar was used, either raise or lower...
  85. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  86. if (!process_record_dynamic_macro(keycode, record)) {
  87. return false;
  88. }
  89. switch (keycode) {
  90. case NAVIGATION: // This key is enter if tapped, navigation if held
  91. if (record->event.pressed) {
  92. fn_keycode = NAVIGATION; // these two lines figure out if the next action is
  93. fn_tap_used = false;
  94. layer_on(_NAVIGATION);
  95. update_tri_layer(_EXCEL, _NAVIGATION, _ADJUST);
  96. } else {
  97. layer_off(_NAVIGATION);
  98. update_tri_layer(_EXCEL, _NAVIGATION, _ADJUST);
  99. if(!fn_tap_used && fn_keycode == NAVIGATION ){
  100. register_code(KC_KP_ENTER);
  101. unregister_code(KC_KP_ENTER);
  102. fn_keycode = 0;
  103. fn_tap_used = false;
  104. }
  105. }
  106. return false;
  107. break;
  108. case EXCEL:
  109. if (record->event.pressed) {
  110. fn_keycode = EXCEL;
  111. fn_tap_used = false;
  112. layer_on(_EXCEL);
  113. update_tri_layer(_EXCEL, _NAVIGATION, _ADJUST);
  114. } else {
  115. layer_off(_EXCEL);
  116. update_tri_layer(_EXCEL, _NAVIGATION, _ADJUST);
  117. if(!fn_tap_used && fn_keycode == EXCEL ){
  118. register_code(KC_KP_0);
  119. unregister_code(KC_KP_0);
  120. fn_keycode = 0;
  121. fn_tap_used = false;
  122. }
  123. }
  124. return false;
  125. break;
  126. default:
  127. fn_tap_used = true;
  128. break; // don't return because this just handles the spacebars.
  129. }
  130. // this is the normal keycode processing switch from Planck default layout.
  131. switch (keycode) {
  132. case NUMPAD_LOCK:
  133. if (record->event.pressed) {
  134. #ifdef AUDIO_ENABLE
  135. PLAY_NOTE_ARRAY(tone_numpad, false, 0);
  136. #endif
  137. persistant_default_layer_set(1UL<<_NUMPAD);
  138. }
  139. return false;
  140. break;
  141. case NAVIGATION_LOCK:
  142. if (record->event.pressed) {
  143. #ifdef AUDIO_ENABLE
  144. PLAY_NOTE_ARRAY(tone_navigation, false, 0);
  145. #endif
  146. persistant_default_layer_set(1UL<<_NAVIGATION);
  147. }
  148. return false;
  149. break;
  150. case EXCEL_LOCK:
  151. if (record->event.pressed) {
  152. #ifdef AUDIO_ENABLE
  153. PLAY_NOTE_ARRAY(tone_excel, false, 0);
  154. #endif
  155. persistant_default_layer_set(1UL<<_EXCEL);
  156. }
  157. return false;
  158. break;
  159. case PARENS:
  160. if (record->event.pressed) {
  161. register_code(KC_RSFT);
  162. register_code(KC_9);
  163. unregister_code(KC_9);
  164. register_code(KC_0);
  165. unregister_code(KC_0);
  166. register_code(KC_RSFT);
  167. register_code(KC_LEFT);
  168. unregister_code(KC_LEFT);
  169. }
  170. return false;
  171. break;
  172. case BRACKETS:
  173. if (record->event.pressed) {
  174. register_code(KC_LBRC);
  175. unregister_code(KC_LBRC);
  176. register_code(KC_RBRC);
  177. unregister_code(KC_RBRC);
  178. register_code(KC_LEFT);
  179. unregister_code(KC_LEFT);
  180. }
  181. return false;
  182. break;
  183. case BRACES:
  184. if (record->event.pressed) {
  185. register_code(KC_RSFT);
  186. register_code(KC_LBRC);
  187. unregister_code(KC_LBRC);
  188. register_code(KC_RBRC);
  189. unregister_code(KC_RBRC);
  190. unregister_code(KC_RSFT);
  191. register_code(KC_LEFT);
  192. unregister_code(KC_LEFT);
  193. }
  194. return false;
  195. break;
  196. case BACKLIT:
  197. if (record->event.pressed) {
  198. #ifdef BACKLIGHT_ENABLE
  199. backlight_step();
  200. #endif
  201. }
  202. return false;
  203. break;
  204. case MACSLEEP:
  205. if (record->event.pressed) {
  206. register_code(KC_RSFT);
  207. register_code(KC_RCTL);
  208. register_code(KC_POWER);
  209. unregister_code(KC_POWER);
  210. unregister_code(KC_RCTL);
  211. unregister_code(KC_RSFT);
  212. }
  213. return false;
  214. break;
  215. }
  216. return true;
  217. }