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