add simple firmware with hardcoded firmware
haldean
4 years ago
0 | #include <usb_keyboard.h> | |
1 | ||
2 | void setup() { | |
3 | pinMode(6, INPUT); | |
4 | pinMode(7, INPUT); | |
5 | pinMode(8, INPUT); | |
6 | pinMode(9, INPUT); | |
7 | pinMode(10, INPUT); | |
8 | pinMode(11, INPUT); | |
9 | } | |
10 | ||
11 | /* The two possible states for the stomp. We use these instead | |
12 | * of simple 0 or 1 to detect HW failures; if there's a short, | |
13 | * it will cause either both or neither input to be set, which | |
14 | * would be a 3 or a 0. */ | |
15 | constexpr int A = 2; | |
16 | constexpr int B = 1; | |
17 | ||
18 | void loop() { | |
19 | int switch_mode = digitalRead(6) << 1 | digitalRead(7); | |
20 | int left_state = digitalRead(8) << 1 | digitalRead(9); | |
21 | int right_state = digitalRead(10) << 1 | digitalRead(11); | |
22 | ||
23 | int old_modifiers = keyboard_modifier_keys; | |
24 | keyboard_modifier_keys = 0; | |
25 | keyboard_keys[0] = 0; | |
26 | keyboard_keys[1] = 0; | |
27 | ||
28 | if (switch_mode == A) { | |
29 | if (left_state == A) { | |
30 | keyboard_modifier_keys = KEY_LEFT_SHIFT; | |
31 | } | |
32 | /* If the modifier is released, you have to release both | |
33 | * the modifiers and the key itself, so we send an | |
34 | * intermediate state with the modifier changed and the key | |
35 | * released */ | |
36 | if (keyboard_modifier_keys != 0 && old_modifiers == 0) { | |
37 | usb_keyboard_send(); | |
38 | } | |
39 | if (right_state == A) | |
40 | keyboard_keys[0] = KEY_W; | |
41 | } | |
42 | else if (switch_mode == B) { | |
43 | int i = 0; | |
44 | if (left_state == A) { | |
45 | keyboard_keys[i++] = KEY_LEFT; | |
46 | } | |
47 | if (right_state == A) { | |
48 | keyboard_keys[i++] = KEY_UP; | |
49 | } | |
50 | } | |
51 | ||
52 | usb_keyboard_send(); | |
53 | } |