fork/GramFirmware

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

CarVacrebase to configurator818d962

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