fork/GramFirmware

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

Skywalker1127Fixed bug with FGC Mode analog, removed redundant SOCD pairs in Ult9dc71d4

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