fork/GramFirmware

git clone https://git.julia.blue/fork/GramFirmware

Skywalker1127Add files via upload007edc4

v0.1.0
10.7 KiB291 linesraw
1/* Ultimate profile by Taker */
2#include "modes/UltimateUSB.hpp"
3
4#define ANALOG_STICK_MIN 28
5#define ANALOG_STICK_NEUTRAL 128
6#define ANALOG_STICK_MAX 228
7
8UltimateUSB::UltimateUSB(socd::SocdType socd_type) {
9    _socd_pair_count = 5;
10    _socd_pairs = new socd::SocdPair[_socd_pair_count]{
11        socd::SocdPair{&InputState::left,    &InputState::right,   socd_type},
12        socd::SocdPair{ &InputState::down,   &InputState::up,      socd_type},
13        socd::SocdPair{ &InputState::down,   &InputState::up2,     socd_type},
14        socd::SocdPair{ &InputState::c_left, &InputState::c_right, socd_type},
15        socd::SocdPair{ &InputState::c_down, &InputState::c_up,    socd_type},
16    };
17}
18
19void UltimateUSB::UpdateDigitalOutputs(InputState &inputs, OutputState &outputs) {
20    outputs.b = inputs.a;
21    outputs.a = inputs.b;
22    outputs.x = inputs.x;
23    outputs.y = inputs.y;
24    outputs.buttonL = inputs.lightshield;
25    outputs.buttonR = inputs.z || inputs.midshield;
26    outputs.triggerLDigital = inputs.l;
27    outputs.triggerRDigital = inputs.r;
28    outputs.start = inputs.start;
29    outputs.select = inputs.select;
30    outputs.home = inputs.home;
31
32    // Turn on D-Pad layer by holding Mod X + Mod Y or Nunchuk C button.
33    if ((inputs.mod_x && inputs.mod_y) || inputs.up2) {
34        outputs.dpadUp = inputs.c_up;
35        outputs.dpadDown = inputs.c_down;
36        outputs.dpadLeft = inputs.c_left;
37        outputs.dpadRight = inputs.c_right;
38    }
39
40    // Activate select/home by holding Mod Y
41    if ((inputs.mod_y)) {
42        outputs.select = inputs.midshield;
43        outputs.home = inputs.start;
44    }
45}
46
47void UltimateUSB::UpdateAnalogOutputs(InputState &inputs, OutputState &outputs) {
48    // Coordinate calculations to make modifier handling simpler.
49    UpdateDirections(
50        inputs.left,
51        inputs.right,
52        inputs.down,
53        inputs.up,
54        inputs.c_left,
55        inputs.c_right,
56        inputs.c_down,
57        inputs.c_up,
58        ANALOG_STICK_MIN,
59        ANALOG_STICK_NEUTRAL,
60        ANALOG_STICK_MAX,
61        outputs
62    );
63
64    bool shield_button_pressed = inputs.l || inputs.r;
65
66    if (inputs.mod_x) {
67        // MX + Horizontal = 6625 = 53
68        if (directions.horizontal) {
69            outputs.leftStickX = 128 + (directions.x * 53);
70            // Horizontal Shield tilt = 51
71            if (shield_button_pressed) {
72                outputs.leftStickX = 128 + (directions.x * 51);
73            }
74            // Horizontal Tilts = 36
75            if (inputs.a) {
76                outputs.leftStickX = 128 + (directions.x * 36);
77            }
78        }
79        // MX + Vertical = 44
80        if (directions.vertical) {
81            outputs.leftStickY = 128 + (directions.y * 44);
82            // Vertical Shield Tilt = 51
83            if (shield_button_pressed) {
84                outputs.leftStickY = 128 + (directions.y * 51);
85            }
86        }
87        if (directions.diagonal) {
88            // MX + q1/2/3/4 = 53 35
89            outputs.leftStickX = 128 + (directions.x * 53);
90            outputs.leftStickY = 128 + (directions.y * 35);
91            if (shield_button_pressed) {
92                // MX + L, R, LS, and MS + q1/2/3/4 = 6375 3750 = 51 30
93                outputs.leftStickX = 128 + (directions.x * 51);
94                outputs.leftStickY = 128 + (directions.y * 30);
95            }
96        }
97
98        // Angled fsmash/ftilt with C-Stick + MX
99        if (directions.cx != 0) {
100            outputs.rightStickX = 128 + (directions.cx * 127);
101            outputs.rightStickY = 128 + (directions.y * 59);
102        }
103
104        /* Up B angles */
105        if (directions.diagonal && !shield_button_pressed) {
106            // (33.44) = 53 35
107            outputs.leftStickX = 128 + (directions.x * 53);
108            outputs.leftStickY = 128 + (directions.y * 35);
109            // (39.05) = 53 43
110            if (inputs.c_down) {
111                outputs.leftStickX = 128 + (directions.x * 53);
112                outputs.leftStickY = 128 + (directions.y * 43);
113            }
114            // (36.35) = 53 39
115            if (inputs.c_left) {
116                outputs.leftStickX = 128 + (directions.x * 53);
117                outputs.leftStickY = 128 + (directions.y * 39);
118            }
119            // (30.32) = 56 41
120            if (inputs.c_up) {
121                outputs.leftStickX = 128 + (directions.x * 53);
122                outputs.leftStickY = 128 + (directions.y * 31);
123            }
124            // (27.85) = 49 42
125            if (inputs.c_right) {
126                outputs.leftStickX = 128 + (directions.x * 53);
127                outputs.leftStickY = 128 + (directions.y * 28);
128            }
129
130            /* Extended Up B Angles */
131            if (inputs.b) {
132                // (33.29) = 67 44
133                outputs.leftStickX = 128 + (directions.x * 67);
134                outputs.leftStickY = 128 + (directions.y * 44);
135                // (39.38) = 67 55
136                if (inputs.c_down) {
137                    outputs.leftStickX = 128 + (directions.x * 67);
138                    outputs.leftStickY = 128 + (directions.y * 55);
139                }
140                // (36.18) = 67 49
141                if (inputs.c_left) {
142                    outputs.leftStickX = 128 + (directions.x * 67);
143                    outputs.leftStickY = 128 + (directions.y * 49);
144                }
145                // (30.2) = 67 39
146                if (inputs.c_up) {
147                    outputs.leftStickX = 128 + (directions.x * 67);
148                    outputs.leftStickY = 128 + (directions.y * 39);
149                }
150                // (27.58) = 67 35
151                if (inputs.c_right) {
152                    outputs.leftStickX = 128 + (directions.x * 67);
153                    outputs.leftStickY = 128 + (directions.y * 35);
154                }
155            }
156
157            // Angled Ftilts
158            if (inputs.a) {
159                outputs.leftStickX = 128 + (directions.x * 36);
160                outputs.leftStickY = 128 + (directions.y * 26);
161            }
162        }
163    }
164
165    if (inputs.mod_y) {
166        // MY + Horizontal (even if shield is held) = 41
167        if (directions.horizontal) {
168            outputs.leftStickX = 128 + (directions.x * 41);
169            // MY Horizontal Tilts
170            if (inputs.a) {
171                outputs.leftStickX = 128 + (directions.x * 36);
172            }
173        }
174        // MY + Vertical (even if shield is held) = 53
175        if (directions.vertical) {
176            outputs.leftStickY = 128 + (directions.y * 53);
177            // MY Vertical Tilts
178            if (inputs.a) {
179                outputs.leftStickY = 128 + (directions.y * 36);
180            }
181        }
182        if (directions.diagonal) {
183            // MY + q1/2/3/4 = 35 59
184            outputs.leftStickX = 128 + (directions.x * 35);
185            outputs.leftStickY = 128 + (directions.y * 53);
186            if (shield_button_pressed) {
187                // MY + L, R, LS, and MS + q1/2 = 38 70
188                outputs.leftStickX = 128 + (directions.x * 38);
189                outputs.leftStickY = 128 + (directions.y * 70);
190                // MY + L, R, LS, and MS + q3/4 = 40 68
191                if (directions.x == -1) {
192                    outputs.leftStickX = 128 + (directions.x * 40);
193                    outputs.leftStickY = 128 + (directions.y * 68);
194                }
195            }
196        }
197
198        /* Up B angles */
199        if (directions.diagonal && !shield_button_pressed) {
200            // (56.56) = 35 53
201            outputs.leftStickX = 128 + (directions.x * 35);
202            outputs.leftStickY = 128 + (directions.y * 53);
203            // (50.95) = 43 53
204            if (inputs.c_down) {
205                outputs.leftStickX = 128 + (directions.x * 43);
206                outputs.leftStickY = 128 + (directions.y * 53);
207            }
208            // (53.65) = 39 53
209            if (inputs.c_left) {
210                outputs.leftStickX = 128 + (directions.x * 49);
211                outputs.leftStickY = 128 + (directions.y * 53);
212            }
213            // (59.68) = 31 53
214            if (inputs.c_up) {
215                outputs.leftStickX = 128 + (directions.x * 31);
216                outputs.leftStickY = 128 + (directions.y * 53);
217            }
218            // (62.15) = 28 53
219            if (inputs.c_right) {
220                outputs.leftStickX = 128 + (directions.x * 28);
221                outputs.leftStickY = 128 + (directions.y * 53);
222            }
223
224            /* Extended Up B Angles */
225            if (inputs.b) {
226                // (56.71) = 44 67
227                outputs.leftStickX = 128 + (directions.x * 44);
228                outputs.leftStickY = 128 + (directions.y * 67);
229                // (50.62) = 55 67
230                if (inputs.c_down) {
231                    outputs.leftStickX = 128 + (directions.x * 55);
232                    outputs.leftStickY = 128 + (directions.y * 67);
233                }
234                // (53.82) = 49 67
235                if (inputs.c_left) {
236                    outputs.leftStickX = 128 + (directions.x * 49);
237                    outputs.leftStickY = 128 + (directions.y * 67);
238                }
239                // (59.8) = 39 67
240                if (inputs.c_up) {
241                    outputs.leftStickX = 128 + (directions.x * 39);
242                    outputs.leftStickY = 128 + (directions.y * 67);
243                }
244                // (62.42) = 35 67
245                if (inputs.c_right) {
246                    outputs.leftStickX = 128 + (directions.x * 35);
247                    outputs.leftStickY = 128 + (directions.y * 67);
248                }
249            }
250
251            // MY Pivot Uptilt/Dtilt
252            if (inputs.a) {
253                outputs.leftStickX = 128 + (directions.x * 34);
254                outputs.leftStickY = 128 + (directions.y * 38);
255            }
256        }
257    }
258
259    // C-stick ASDI Slideoff angle overrides any other C-stick modifiers (such as
260    // angled fsmash).
261    if (directions.cx != 0 && directions.cy != 0) {
262        // 5250 8500 = 42 68
263        outputs.rightStickX = 128 + (directions.cx * 42);
264        outputs.rightStickY = 128 + (directions.cy * 68);
265    }
266
267    if (inputs.l) {
268        outputs.triggerLAnalog = 140;
269    }
270
271    if (inputs.r) {
272        outputs.triggerRAnalog = 140;
273    }
274
275    // Shut off C-stick when using D-Pad layer.
276    if ((inputs.mod_x && inputs.mod_y) || inputs.up2) {
277        outputs.rightStickX = 128;
278        outputs.rightStickY = 128;
279    }
280
281    // Turns off Start when holding Mod Y
282    if ((inputs.mod_y)) {
283        outputs.start = false;
284    }  
285
286    // Nunchuk overrides left stick.
287    if (inputs.nunchuk_connected) {
288        outputs.leftStickX = inputs.nunchuk_x;
289        outputs.leftStickY = inputs.nunchuk_y;
290    }
291}