diff options
Diffstat (limited to 'keyboards/dm9records/plaid/keymaps/default/keymap.c')
-rw-r--r-- | keyboards/dm9records/plaid/keymaps/default/keymap.c | 414 |
1 files changed, 414 insertions, 0 deletions
diff --git a/keyboards/dm9records/plaid/keymaps/default/keymap.c b/keyboards/dm9records/plaid/keymaps/default/keymap.c new file mode 100644 index 000000000..c5075b0e0 --- /dev/null +++ b/keyboards/dm9records/plaid/keymaps/default/keymap.c | |||
@@ -0,0 +1,414 @@ | |||
1 | /* Copyright 2019 Takuya Urakawa (dm9records.com) | ||
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 | |||
17 | #include QMK_KEYBOARD_H | ||
18 | |||
19 | |||
20 | enum plaid_layers { | ||
21 | _QWERTY, | ||
22 | _COLEMAK, | ||
23 | _DVORAK, | ||
24 | _LOWER, | ||
25 | _RAISE, | ||
26 | _PLOVER, | ||
27 | _ADJUST | ||
28 | }; | ||
29 | |||
30 | enum plaid_keycodes { | ||
31 | QWERTY = SAFE_RANGE, | ||
32 | COLEMAK, | ||
33 | DVORAK, | ||
34 | PLOVER, | ||
35 | EXT_PLV, | ||
36 | LED_1, | ||
37 | LED_2, | ||
38 | LED_3, | ||
39 | LED_4, | ||
40 | LED_5, | ||
41 | LED_6, | ||
42 | LED_7, | ||
43 | LED_8, | ||
44 | LED_9, | ||
45 | LED_0 | ||
46 | }; | ||
47 | |||
48 | #define LOWER MO(_LOWER) | ||
49 | #define RAISE MO(_RAISE) | ||
50 | |||
51 | // array of keys considered modifiers for led purposes | ||
52 | const uint16_t modifiers[] = { | ||
53 | KC_LCTL, | ||
54 | KC_RCTL, | ||
55 | KC_LALT, | ||
56 | KC_RALT, | ||
57 | KC_LSFT, | ||
58 | KC_RSFT, | ||
59 | KC_LGUI, | ||
60 | KC_RGUI, | ||
61 | LOWER, | ||
62 | RAISE | ||
63 | }; | ||
64 | |||
65 | //Setup consts for LED modes | ||
66 | #define LEDMODE_ON 1 //always on | ||
67 | #define LEDMODE_OFF 0 //always off | ||
68 | #define LEDMODE_MODS 2 //On with modifiers | ||
69 | #define LEDMODE_BLINKIN 3 //blinkinlights - % chance toggle on keypress | ||
70 | #define LEDMODE_KEY 4 //On with any keypress, off with key release | ||
71 | #define LEDMODE_ENTER 5 // On with enter key | ||
72 | |||
73 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
74 | |||
75 | /* Qwerty | ||
76 | * ,-----------------------------------------------------------------------------------. | ||
77 | * | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp | | ||
78 | * |------+------+------+------+------+-------------+------+------+------+------+------| | ||
79 | * | Esc | A | S | D | F | G | H | J | K | L | ; | " | | ||
80 | * |------+------+------+------+------+------|------+------+------+------+------+------| | ||
81 | * | Shift| Z | X | C | V | B | N | M | , | . | / |Enter | | ||
82 | * |------+------+------+------+------+------+------+------+------+------+------+------| | ||
83 | * | Ctrl | RAlt | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | | ||
84 | * `-----------------------------------------------------------------------------------' | ||
85 | */ | ||
86 | [_QWERTY] = LAYOUT_plaid_grid( | ||
87 | KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, | ||
88 | KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, | ||
89 | KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , | ||
90 | KC_LCTL, KC_RALT, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT | ||
91 | ), | ||
92 | |||
93 | /* Colemak | ||
94 | * ,-----------------------------------------------------------------------------------. | ||
95 | * | Tab | Q | W | F | P | G | J | L | U | Y | ; | Bksp | | ||
96 | * |------+------+------+------+------+-------------+------+------+------+------+------| | ||
97 | * | Esc | A | R | S | T | D | H | N | E | I | O | " | | ||
98 | * |------+------+------+------+------+------|------+------+------+------+------+------| | ||
99 | * | Shift| Z | X | C | V | B | K | M | , | . | / |Enter | | ||
100 | * |------+------+------+------+------+------+------+------+------+------+------+------| | ||
101 | * | Ctrl | RAlt | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | | ||
102 | * `-----------------------------------------------------------------------------------' | ||
103 | */ | ||
104 | [_COLEMAK] = LAYOUT_plaid_grid( | ||
105 | KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC, | ||
106 | KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT, | ||
107 | KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , | ||
108 | KC_LCTL, KC_RALT, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT | ||
109 | ), | ||
110 | |||
111 | /* Dvorak | ||
112 | * ,-----------------------------------------------------------------------------------. | ||
113 | * | Tab | " | , | . | P | Y | F | G | C | R | L | Bksp | | ||
114 | * |------+------+------+------+------+-------------+------+------+------+------+------| | ||
115 | * | Esc | A | O | E | U | I | D | H | T | N | S | / | | ||
116 | * |------+------+------+------+------+------|------+------+------+------+------+------| | ||
117 | * | Shift| ; | Q | J | K | X | B | M | W | V | Z |Enter | | ||
118 | * |------+------+------+------+------+------+------+------+------+------+------+------| | ||
119 | * | Ctrl | RAlt | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | | ||
120 | * `-----------------------------------------------------------------------------------' | ||
121 | */ | ||
122 | [_DVORAK] = LAYOUT_plaid_grid( | ||
123 | KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC, | ||
124 | KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH, | ||
125 | KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT , | ||
126 | KC_LCTL, KC_RALT, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT | ||
127 | ), | ||
128 | |||
129 | /* Lower | ||
130 | * ,-----------------------------------------------------------------------------------. | ||
131 | * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp | | ||
132 | * |------+------+------+------+------+-------------+------+------+------+------+------| | ||
133 | * | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | | | ||
134 | * |------+------+------+------+------+------|------+------+------+------+------+------| | ||
135 | * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | Home | End | | | ||
136 | * |------+------+------+------+------+------+------+------+------+------+------+------| | ||
137 | * | | | | | | | | Next | Vol- | Vol+ | Play | | ||
138 | * `-----------------------------------------------------------------------------------' | ||
139 | */ | ||
140 | [_LOWER] = LAYOUT_plaid_grid( | ||
141 | KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC, | ||
142 | KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, | ||
143 | _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, S(KC_NUHS), S(KC_NUBS), KC_HOME, KC_END, _______, | ||
144 | _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY | ||
145 | ), | ||
146 | |||
147 | /* Raise | ||
148 | * ,-----------------------------------------------------------------------------------. | ||
149 | * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp | | ||
150 | * |------+------+------+------+------+-------------+------+------+------+------+------| | ||
151 | * | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ | | ||
152 | * |------+------+------+------+------+------|------+------+------+------+------+------| | ||
153 | * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / |Pg Up |Pg Dn | | | ||
154 | * |------+------+------+------+------+------+------+------+------+------+------+------| | ||
155 | * | | | | | | | | Next | Vol- | Vol+ | Play | | ||
156 | * `-----------------------------------------------------------------------------------' | ||
157 | */ | ||
158 | [_RAISE] = LAYOUT_plaid_grid( | ||
159 | KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, | ||
160 | KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, | ||
161 | _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, KC_PGUP, KC_PGDN, _______, | ||
162 | _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY | ||
163 | ), | ||
164 | |||
165 | /* Plover layer (http://opensteno.org) | ||
166 | * ,-----------------------------------------------------------------------------------. | ||
167 | * | # | # | # | # | # | # | # | # | # | # | # | # | | ||
168 | * |------+------+------+------+------+-------------+------+------+------+------+------| | ||
169 | * | | S | T | P | H | * | * | F | P | L | T | D | | ||
170 | * |------+------+------+------+------+------|------+------+------+------+------+------| | ||
171 | * | | S | K | W | R | * | * | R | B | G | S | Z | | ||
172 | * |------+------+------+------+------+------+------+------+------+------+------+------| | ||
173 | * | Exit | | | A | O | | E | U | | | | | ||
174 | * `-----------------------------------------------------------------------------------' | ||
175 | */ | ||
176 | |||
177 | [_PLOVER] = LAYOUT_plaid_grid( | ||
178 | KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1 , | ||
179 | XXXXXXX, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, | ||
180 | XXXXXXX, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, | ||
181 | EXT_PLV, XXXXXXX, XXXXXXX, KC_C, KC_V, XXXXXXX, XXXXXXX, KC_N, KC_M, XXXXXXX, XXXXXXX, XXXXXXX | ||
182 | ), | ||
183 | |||
184 | /* Adjust (Lower + Raise) | ||
185 | * ,-----------------------------------------------------------------------------------. | ||
186 | * |Reset | | | | | | | | | | | Del | | ||
187 | * |------+------+------+------+------+-------------+------+------+------+------+------| | ||
188 | * | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty|Colemk|Dvorak|Plover| | | ||
189 | * |------+------+------+------+------+------|------+------+------+------+------+------| | ||
190 | * | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | | | | | | ||
191 | * |------+------+------+------+------+------+------+------+------+------+------+------| | ||
192 | * | | | | | | | | | | | | | ||
193 | * `-----------------------------------------------------------------------------------' | ||
194 | */ | ||
195 | [_ADJUST] = LAYOUT_plaid_grid( | ||
196 | RESET,LED_1, LED_2, LED_3, LED_4, LED_5,LED_6, LED_7, LED_8, LED_9, LED_0,KC_DEL , | ||
197 | _______, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, PLOVER, _______, | ||
198 | _______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, TERM_ON, TERM_OFF, _______, _______, _______, | ||
199 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ | ||
200 | ) | ||
201 | |||
202 | |||
203 | }; | ||
204 | |||
205 | //Setup config struct for LED | ||
206 | typedef union { | ||
207 | uint32_t raw; | ||
208 | struct { | ||
209 | uint8_t red_mode :8; | ||
210 | uint8_t green_mode :8; | ||
211 | }; | ||
212 | } led_config_t; | ||
213 | led_config_t led_config; | ||
214 | |||
215 | //Set leds to saved state during powerup | ||
216 | void keyboard_post_init_user(void) { | ||
217 | // set LED pin modes | ||
218 | setPinOutput(LED_RED); | ||
219 | setPinOutput(LED_GREEN); | ||
220 | |||
221 | // Call the post init code. | ||
222 | led_config.raw = eeconfig_read_user(); | ||
223 | |||
224 | if(led_config.red_mode == LEDMODE_ON) { | ||
225 | writePinHigh(LED_RED); | ||
226 | } | ||
227 | |||
228 | if(led_config.green_mode == LEDMODE_ON) { | ||
229 | writePinHigh(LED_GREEN); | ||
230 | } | ||
231 | } | ||
232 | |||
233 | void eeconfig_init_user(void) { // EEPROM is getting reset! | ||
234 | led_config.raw = 0; | ||
235 | led_config.red_mode = LEDMODE_ON; | ||
236 | led_config.green_mode = LEDMODE_MODS; | ||
237 | eeconfig_update_user(led_config.raw); | ||
238 | eeconfig_update_user(led_config.raw); | ||
239 | } | ||
240 | |||
241 | layer_state_t layer_state_set_user(layer_state_t state) { | ||
242 | return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST); | ||
243 | } | ||
244 | |||
245 | void led_keypress_update(uint8_t led, uint8_t led_mode, uint16_t keycode, keyrecord_t *record) { | ||
246 | switch (led_mode) { | ||
247 | case LEDMODE_MODS: | ||
248 | for (int i=0;i<sizeof(modifiers) / sizeof(modifiers[0]);i++) { | ||
249 | if(keycode==modifiers[i]) { | ||
250 | if (record->event.pressed) { | ||
251 | writePinHigh(led); | ||
252 | } | ||
253 | else { | ||
254 | writePinLow(led); | ||
255 | } | ||
256 | } | ||
257 | } | ||
258 | break; | ||
259 | case LEDMODE_BLINKIN: | ||
260 | if (record->event.pressed) { | ||
261 | if(rand() % 2 == 1) { | ||
262 | if(rand() % 2 == 0) { | ||
263 | writePinLow(led); | ||
264 | } | ||
265 | else { | ||
266 | writePinHigh(led); | ||
267 | } | ||
268 | } | ||
269 | } | ||
270 | break; | ||
271 | case LEDMODE_KEY: | ||
272 | if (record->event.pressed) { | ||
273 | writePinHigh(led); | ||
274 | return; | ||
275 | } | ||
276 | else { | ||
277 | writePinLow(led); | ||
278 | return; | ||
279 | } | ||
280 | break; | ||
281 | case LEDMODE_ENTER: | ||
282 | if (keycode==KC_ENT) { | ||
283 | writePinHigh(led); | ||
284 | } | ||
285 | else { | ||
286 | writePinLow(led); | ||
287 | } | ||
288 | break; | ||
289 | |||
290 | } | ||
291 | } | ||
292 | |||
293 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | ||
294 | /* If the either led mode is keypressed based, call the led updater | ||
295 | then let it fall through the keypress handlers. Just to keep | ||
296 | the logic out of this procedure */ | ||
297 | if (led_config.red_mode >= LEDMODE_MODS && led_config.red_mode <= LEDMODE_ENTER) { | ||
298 | led_keypress_update(LED_RED, led_config.red_mode, keycode, record); | ||
299 | } | ||
300 | if (led_config.green_mode >= LEDMODE_MODS && led_config.green_mode <= LEDMODE_ENTER) { | ||
301 | led_keypress_update(LED_GREEN, led_config.green_mode, keycode, record); | ||
302 | } | ||
303 | switch (keycode) { | ||
304 | case QWERTY: | ||
305 | if (record->event.pressed) { | ||
306 | print("mode just switched to qwerty and this is a huge string\n"); | ||
307 | set_single_persistent_default_layer(_QWERTY); | ||
308 | } | ||
309 | return false; | ||
310 | break; | ||
311 | case COLEMAK: | ||
312 | if (record->event.pressed) { | ||
313 | set_single_persistent_default_layer(_COLEMAK); | ||
314 | } | ||
315 | return false; | ||
316 | break; | ||
317 | case DVORAK: | ||
318 | if (record->event.pressed) { | ||
319 | set_single_persistent_default_layer(_DVORAK); | ||
320 | } | ||
321 | return false; | ||
322 | break; | ||
323 | case PLOVER: | ||
324 | if (record->event.pressed) { | ||
325 | layer_off(_RAISE); | ||
326 | layer_off(_LOWER); | ||
327 | layer_off(_ADJUST); | ||
328 | layer_on(_PLOVER); | ||
329 | if (!eeconfig_is_enabled()) { | ||
330 | eeconfig_init(); | ||
331 | } | ||
332 | keymap_config.raw = eeconfig_read_keymap(); | ||
333 | keymap_config.nkro = 1; | ||
334 | eeconfig_update_keymap(keymap_config.raw); | ||
335 | } | ||
336 | return false; | ||
337 | break; | ||
338 | case EXT_PLV: | ||
339 | if (record->event.pressed) { | ||
340 | layer_off(_PLOVER); | ||
341 | } | ||
342 | return false; | ||
343 | break; | ||
344 | case LED_1: | ||
345 | if (record->event.pressed) { | ||
346 | if (led_config.red_mode==LEDMODE_ON) { | ||
347 | led_config.red_mode=LEDMODE_OFF; | ||
348 | writePinLow(LED_RED); | ||
349 | } | ||
350 | else { | ||
351 | led_config.red_mode=LEDMODE_ON; | ||
352 | writePinHigh(LED_RED); | ||
353 | } | ||
354 | } | ||
355 | eeconfig_update_user(led_config.raw); | ||
356 | return false; | ||
357 | break; | ||
358 | case LED_2: | ||
359 | if (record->event.pressed) { | ||
360 | if (led_config.green_mode==LEDMODE_ON) { | ||
361 | led_config.green_mode=LEDMODE_OFF; | ||
362 | writePinLow(LED_GREEN); | ||
363 | } | ||
364 | else { | ||
365 | led_config.green_mode=LEDMODE_ON; | ||
366 | writePinHigh(LED_GREEN); | ||
367 | } | ||
368 | } | ||
369 | eeconfig_update_user(led_config.raw); | ||
370 | return false; | ||
371 | break; | ||
372 | case LED_3: | ||
373 | led_config.red_mode=LEDMODE_MODS; | ||
374 | eeconfig_update_user(led_config.raw); | ||
375 | return false; | ||
376 | break; | ||
377 | case LED_4: | ||
378 | led_config.green_mode=LEDMODE_MODS; | ||
379 | eeconfig_update_user(led_config.raw); | ||
380 | return false; | ||
381 | break; | ||
382 | case LED_5: | ||
383 | led_config.red_mode=LEDMODE_BLINKIN; | ||
384 | eeconfig_update_user(led_config.raw); | ||
385 | return false; | ||
386 | break; | ||
387 | case LED_6: | ||
388 | led_config.green_mode=LEDMODE_BLINKIN; | ||
389 | eeconfig_update_user(led_config.raw); | ||
390 | return false; | ||
391 | break; | ||
392 | case LED_7: | ||
393 | led_config.red_mode=LEDMODE_KEY; | ||
394 | eeconfig_update_user(led_config.raw); | ||
395 | return false; | ||
396 | break; | ||
397 | case LED_8: | ||
398 | led_config.green_mode=LEDMODE_KEY; | ||
399 | eeconfig_update_user(led_config.raw); | ||
400 | return false; | ||
401 | break; | ||
402 | case LED_9: | ||
403 | led_config.red_mode=LEDMODE_ENTER; | ||
404 | eeconfig_update_user(led_config.raw); | ||
405 | return false; | ||
406 | break; | ||
407 | case LED_0: | ||
408 | led_config.green_mode=LEDMODE_ENTER; | ||
409 | eeconfig_update_user(led_config.raw); | ||
410 | return false; | ||
411 | break; | ||
412 | } | ||
413 | return true; | ||
414 | } | ||