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.

358 lines
15 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. /* Copyright 2021 Potential Vehicle Owner
  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. #include "muse.h"
  18. enum planck_layers {
  19. _QWERTY,
  20. _COLEMAK,
  21. _DVORAK,
  22. _LOWER,
  23. _RAISE,
  24. _PLOVER,
  25. _ADJUST
  26. };
  27. enum planck_keycodes {
  28. QWERTY = SAFE_RANGE,
  29. COLEMAK,
  30. DVORAK,
  31. PLOVER,
  32. BACKLIT,
  33. EXT_PLV,
  34. DR_VO
  35. };
  36. #define LOWER MO(_LOWER)
  37. #define RAISE MO(_RAISE)
  38. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  39. /* Qwerty
  40. * ,-----------------------------------------------------------------------------------.
  41. * | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp |
  42. * |------+------+------+------+------+------+------+------+------+------+------+------|
  43. * | Esc | A | S | D | F | G | H | J | K | L | ; | " |
  44. * |------+------+------+------+------+------+------+------+------+------+------+------|
  45. * | Shift| Z | X | C | V | B | N | M | , | . | / |Enter |
  46. * |------+------+------+------+------+------+------+------+------+------+------+------|
  47. * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
  48. * `-----------------------------------------------------------------------------------'
  49. */
  50. [_QWERTY] = LAYOUT_planck_grid(
  51. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  52. KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  53. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT ,
  54. BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  55. ),
  56. /* Colemak
  57. * ,-----------------------------------------------------------------------------------.
  58. * | Tab | Q | W | F | P | G | J | L | U | Y | ; | Bksp |
  59. * |------+------+------+------+------+------+------+------+------+------+------+------|
  60. * | Esc | A | R | S | T | D | H | N | E | I | O | " |
  61. * |------+------+------+------+------+------+------+------+------+------+------+------|
  62. * | Shift| Z | X | C | V | B | K | M | , | . | / |Enter |
  63. * |------+------+------+------+------+------+------+------+------+------+------+------|
  64. * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
  65. * `-----------------------------------------------------------------------------------'
  66. */
  67. [_COLEMAK] = LAYOUT_planck_grid(
  68. KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC,
  69. KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT,
  70. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT ,
  71. BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  72. ),
  73. /* Dvorak
  74. * ,-----------------------------------------------------------------------------------.
  75. * | Tab | " | , | . | P | Y | F | G | C | R | L | Bksp |
  76. * |------+------+------+------+------+------+------+------+------+------+------+------|
  77. * | Esc | A | O | E | U | I | D | H | T | N | S | / |
  78. * |------+------+------+------+------+------+------+------+------+------+------+------|
  79. * | Shift| ; | Q | J | K | X | B | M | W | V | Z |Enter |
  80. * |------+------+------+------+------+------+------+------+------+------+------+------|
  81. * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
  82. * `-----------------------------------------------------------------------------------'
  83. */
  84. [_DVORAK] = LAYOUT_planck_grid(
  85. KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC,
  86. KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH,
  87. KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT ,
  88. BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  89. ),
  90. /* Lower
  91. * ,-----------------------------------------------------------------------------------.
  92. * | DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO|
  93. * |------+------+------+------+------+------+------+------+------+------+------+------|
  94. * | DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO|
  95. * |------+------+------+------+------+------+------+------+------+------+------+------|
  96. * | DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO|
  97. * |------+------+------+------+------+------+------+------+------+------+------+------|
  98. * | DR_VO| DR_VO| DR_VO| DR_VO| | | | DR_VO| DR_VO| DR_VO| DR_VO|
  99. * `-----------------------------------------------------------------------------------'
  100. */
  101. [_LOWER] = LAYOUT_planck_grid(
  102. DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO,
  103. DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO,
  104. DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO,
  105. DR_VO, DR_VO, DR_VO, DR_VO, _______, _______, _______, _______, DR_VO, DR_VO, DR_VO, DR_VO
  106. ),
  107. /* Raise
  108. * ,-----------------------------------------------------------------------------------.
  109. * | DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO|
  110. * |------+------+------+------+------+------+------+------+------+------+------+------|
  111. * | DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO|
  112. * |------+------+------+------+------+------+------+------+------+------+------+------|
  113. * | DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO| DR_VO|
  114. * |------+------+------+------+------+------+------+------+------+------+------+------|
  115. * | DR_VO| DR_VO| DR_VO| DR_VO| | | | DR_VO| DR_VO| DR_VO| DR_VO|
  116. * `-----------------------------------------------------------------------------------'
  117. */
  118. [_RAISE] = LAYOUT_planck_grid(
  119. DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO,
  120. DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO,
  121. DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO, DR_VO,
  122. DR_VO, DR_VO, DR_VO, DR_VO, _______, _______, _______, _______, DR_VO, DR_VO, DR_VO, DR_VO
  123. ),
  124. /* Plover layer (http://opensteno.org)
  125. * ,-----------------------------------------------------------------------------------.
  126. * | # | # | # | # | # | # | # | # | # | # | # | # |
  127. * |------+------+------+------+------+------+------+------+------+------+------+------|
  128. * | | S | T | P | H | * | * | F | P | L | T | D |
  129. * |------+------+------+------+------+------+------+------+------+------+------+------|
  130. * | | S | K | W | R | * | * | R | B | G | S | Z |
  131. * |------+------+------+------+------+------+------+------+------+------+------+------|
  132. * | Exit | | | A | O | | E | U | | | |
  133. * `-----------------------------------------------------------------------------------'
  134. */
  135. [_PLOVER] = LAYOUT_planck_grid(
  136. KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1 ,
  137. XXXXXXX, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC,
  138. XXXXXXX, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  139. EXT_PLV, XXXXXXX, XXXXXXX, KC_C, KC_V, XXXXXXX, XXXXXXX, KC_N, KC_M, XXXXXXX, XXXXXXX, XXXXXXX
  140. ),
  141. /* Adjust (Lower + Raise)
  142. * v------------------------RGB CONTROL--------------------v
  143. * ,-----------------------------------------------------------------------------------.
  144. * | | Reset|Debug | RGB |RGBMOD| HUE+ | HUE- | SAT+ | SAT- |BRGTH+|BRGTH-| Del |
  145. * |------+------+------+------+------+------+------+------+------+------+------+------|
  146. * | | |MUSmod|Aud on|Audoff|AGnorm|AGswap|Qwerty|Colemk|Dvorak|Plover| |
  147. * |------+------+------+------+------+------+------+------+------+------+------+------|
  148. * | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof|TermOn|TermOf| | | |
  149. * |------+------+------+------+------+------+------+------+------+------+------+------|
  150. * | | | | | | | | | | | |
  151. * `-----------------------------------------------------------------------------------'
  152. */
  153. [_ADJUST] = LAYOUT_planck_grid(
  154. _______, RESET, DEBUG, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, KC_DEL ,
  155. _______, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, PLOVER, _______,
  156. _______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, TERM_ON, TERM_OFF, _______, _______, _______,
  157. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  158. )
  159. };
  160. #ifdef AUDIO_ENABLE
  161. float plover_song[][2] = SONG(PLOVER_SOUND);
  162. float plover_gb_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
  163. #endif
  164. layer_state_t layer_state_set_user(layer_state_t state) {
  165. return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  166. }
  167. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  168. switch (keycode) {
  169. case QWERTY:
  170. if (record->event.pressed) {
  171. print("mode just switched to qwerty and this is a huge string\n");
  172. set_single_persistent_default_layer(_QWERTY);
  173. }
  174. return false;
  175. break;
  176. case COLEMAK:
  177. if (record->event.pressed) {
  178. set_single_persistent_default_layer(_COLEMAK);
  179. }
  180. return false;
  181. break;
  182. case DVORAK:
  183. if (record->event.pressed) {
  184. set_single_persistent_default_layer(_DVORAK);
  185. }
  186. return false;
  187. break;
  188. case BACKLIT:
  189. if (record->event.pressed) {
  190. register_code(KC_RSFT);
  191. #ifdef BACKLIGHT_ENABLE
  192. backlight_step();
  193. #endif
  194. #ifdef KEYBOARD_planck_rev5
  195. writePinLow(E6);
  196. #endif
  197. } else {
  198. unregister_code(KC_RSFT);
  199. #ifdef KEYBOARD_planck_rev5
  200. writePinHigh(E6);
  201. #endif
  202. }
  203. return false;
  204. break;
  205. case PLOVER:
  206. if (record->event.pressed) {
  207. #ifdef AUDIO_ENABLE
  208. stop_all_notes();
  209. PLAY_SONG(plover_song);
  210. #endif
  211. layer_off(_RAISE);
  212. layer_off(_LOWER);
  213. layer_off(_ADJUST);
  214. layer_on(_PLOVER);
  215. if (!eeconfig_is_enabled()) {
  216. eeconfig_init();
  217. }
  218. keymap_config.raw = eeconfig_read_keymap();
  219. keymap_config.nkro = 1;
  220. eeconfig_update_keymap(keymap_config.raw);
  221. }
  222. return false;
  223. break;
  224. case EXT_PLV:
  225. if (record->event.pressed) {
  226. #ifdef AUDIO_ENABLE
  227. PLAY_SONG(plover_gb_song);
  228. #endif
  229. layer_off(_PLOVER);
  230. }
  231. return false;
  232. break;
  233. case DR_VO:
  234. if (record->event.pressed) {
  235. SEND_STRING("We've been trying to reach you concerning your vehicle's extended warranty. You should've received a notice in the mail about your car's extended warranty eligibility. Since we've not gotten a response, we're giving you a final courtesy call before we close out your file. Press 2 to be removed and placed on our do-not-call list. To speak to someone about possibly extending or reinstating your vehicle's warranty, press 1 to speak with a warranty specialist.\n");
  236. }
  237. return false;
  238. break;
  239. }
  240. return true;
  241. }
  242. bool muse_mode = false;
  243. uint8_t last_muse_note = 0;
  244. uint16_t muse_counter = 0;
  245. uint8_t muse_offset = 70;
  246. uint16_t muse_tempo = 50;
  247. void encoder_update(bool clockwise) {
  248. if (muse_mode) {
  249. if (IS_LAYER_ON(_RAISE)) {
  250. if (clockwise) {
  251. muse_offset++;
  252. } else {
  253. muse_offset--;
  254. }
  255. } else {
  256. if (clockwise) {
  257. muse_tempo+=1;
  258. } else {
  259. muse_tempo-=1;
  260. }
  261. }
  262. } else {
  263. if (clockwise) {
  264. #ifdef MOUSEKEY_ENABLE
  265. tap_code(KC_MS_WH_DOWN);
  266. #else
  267. tap_code(KC_PGDN);
  268. #endif
  269. } else {
  270. #ifdef MOUSEKEY_ENABLE
  271. tap_code(KC_MS_WH_UP);
  272. #else
  273. tap_code(KC_PGUP);
  274. #endif
  275. }
  276. }
  277. }
  278. void dip_switch_update_user(uint8_t index, bool active) {
  279. switch (index) {
  280. case 0: {
  281. #ifdef AUDIO_ENABLE
  282. static bool play_sound = false;
  283. #endif
  284. if (active) {
  285. #ifdef AUDIO_ENABLE
  286. if (play_sound) { PLAY_SONG(plover_song); }
  287. #endif
  288. layer_on(_ADJUST);
  289. } else {
  290. #ifdef AUDIO_ENABLE
  291. if (play_sound) { PLAY_SONG(plover_gb_song); }
  292. #endif
  293. layer_off(_ADJUST);
  294. }
  295. #ifdef AUDIO_ENABLE
  296. play_sound = true;
  297. #endif
  298. break;
  299. }
  300. case 1:
  301. if (active) {
  302. muse_mode = true;
  303. } else {
  304. muse_mode = false;
  305. }
  306. }
  307. }
  308. void matrix_scan_user(void) {
  309. #ifdef AUDIO_ENABLE
  310. if (muse_mode) {
  311. if (muse_counter == 0) {
  312. uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
  313. if (muse_note != last_muse_note) {
  314. stop_note(compute_freq_for_midi_note(last_muse_note));
  315. play_note(compute_freq_for_midi_note(muse_note), 0xF);
  316. last_muse_note = muse_note;
  317. }
  318. }
  319. muse_counter = (muse_counter + 1) % muse_tempo;
  320. } else {
  321. if (muse_counter) {
  322. stop_all_notes();
  323. muse_counter = 0;
  324. }
  325. }
  326. #endif
  327. }
  328. bool music_mask_user(uint16_t keycode) {
  329. switch (keycode) {
  330. case RAISE:
  331. case LOWER:
  332. return false;
  333. default:
  334. return true;
  335. }
  336. }