fork/GramFirmware

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

Jonathan HaylettSOCD revamp (#57)1f92ae6

v0.1.2
6.4 KiB187 linesraw
1/* Ultimate2 profile by Taker */
2#include "modes/extra/Ultimate2.hpp"
3
4#define ANALOG_STICK_MIN 28
5#define ANALOG_STICK_NEUTRAL 128
6#define ANALOG_STICK_MAX 228
7
8Ultimate2::Ultimate2(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 Ultimate2::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.buttonR = inputs.z;
24    outputs.triggerLDigital = inputs.l;
25    outputs.triggerRDigital = inputs.r;
26    outputs.start = inputs.start;
27
28    // Turn on D-Pad layer by holding Mod X + Mod Y, or Nunchuk C button.
29    if ((inputs.mod_x && inputs.mod_y) || inputs.nunchuk_c) {
30        outputs.dpadUp = inputs.c_up;
31        outputs.dpadDown = inputs.c_down;
32        outputs.dpadLeft = inputs.c_left;
33        outputs.dpadRight = inputs.c_right;
34    }
35
36    if (inputs.select)
37        outputs.dpadLeft = true;
38    if (inputs.home)
39        outputs.dpadRight = true;
40}
41
42void Ultimate2::UpdateAnalogOutputs(InputState &inputs, OutputState &outputs) {
43    // Coordinate calculations to make modifier handling simpler.
44    UpdateDirections(
45        inputs.left,
46        inputs.right,
47        inputs.down,
48        inputs.up,
49        inputs.c_left,
50        inputs.c_right,
51        inputs.c_down,
52        inputs.c_up,
53        ANALOG_STICK_MIN,
54        ANALOG_STICK_NEUTRAL,
55        ANALOG_STICK_MAX,
56        outputs
57    );
58
59    bool shield_button_pressed = inputs.l || inputs.r || inputs.lightshield || inputs.midshield;
60
61    if (inputs.mod_x) {
62        // MX + Horizontal = 6625 = 53
63        if (directions.horizontal) {
64            outputs.leftStickX = 128 + (directions.x * 53);
65            // Horizontal Shield tilt = 51
66            if (shield_button_pressed) {
67                outputs.leftStickX = 128 + (directions.x * 51);
68            }
69            // Horizontal Tilts = 36
70            if (inputs.a) {
71                outputs.leftStickX = 128 + (directions.x * 36);
72            }
73        }
74        // MX + Vertical = 44
75        if (directions.vertical) {
76            outputs.leftStickY = 128 + (directions.y * 44);
77            // Vertical Shield Tilt = 51
78            if (shield_button_pressed) {
79                outputs.leftStickY = 128 + (directions.y * 51);
80            }
81        }
82        if (directions.diagonal) {
83            // MX + q1/2/3/4 = 53 40
84            outputs.leftStickX = 128 + (directions.x * 53);
85            outputs.leftStickY = 128 + (directions.y * 40);
86            if (shield_button_pressed) {
87                // MX + L, R, LS, and MS + q1/2/3/4 = 6375 3750 = 51 30
88                outputs.leftStickX = 128 + (directions.x * 51);
89                outputs.leftStickY = 128 + (directions.y * 30);
90            }
91        }
92
93        // Angled fsmash/ftilt with C-Stick + MX
94        if (directions.cx != 0) {
95            outputs.rightStickX = 128 + (directions.cx * 127);
96            outputs.rightStickY = 128 + (directions.y * 59);
97        }
98
99        /* Up B angles */
100        if (directions.diagonal && !shield_button_pressed) {
101            // (33.44) = 53 40
102            outputs.leftStickX = 128 + (directions.x * 53);
103            outputs.leftStickY = 128 + (directions.y * 40);
104
105            // Angled Ftilts
106            if (inputs.a) {
107                outputs.leftStickX = 128 + (directions.x * 36);
108                outputs.leftStickY = 128 + (directions.y * 26);
109            }
110        }
111    }
112
113    if (inputs.mod_y) {
114        // MY + Horizontal (even if shield is held) = 41
115        if (directions.horizontal) {
116            outputs.leftStickX = 128 + (directions.x * 41);
117            // MY Horizontal Tilts
118            if (inputs.a) {
119                outputs.leftStickX = 128 + (directions.x * 36);
120            }
121        }
122        // MY + Vertical (even if shield is held) = 44
123        if (directions.vertical) {
124            outputs.leftStickY = 128 + (directions.y * 44);
125            // MY Vertical Tilts
126            if (inputs.a) {
127                outputs.leftStickY = 128 + (directions.y * 36);
128            }
129        }
130        if (directions.diagonal) {
131            // MY + q1/2/3/4 = 41 44
132            outputs.leftStickX = 128 + (directions.x * 41);
133            outputs.leftStickY = 128 + (directions.y * 44);
134            if (shield_button_pressed) {
135                // MY + L, R, LS, and MS + q1/2 = 38 70
136                outputs.leftStickX = 128 + (directions.x * 38);
137                outputs.leftStickY = 128 + (directions.y * 70);
138                // MY + L, R, LS, and MS + q3/4 = 40 68
139                if (directions.x == -1) {
140                    outputs.leftStickX = 128 + (directions.x * 40);
141                    outputs.leftStickY = 128 + (directions.y * 68);
142                }
143            }
144        }
145
146        /* Up B angles */
147        if (directions.diagonal && !shield_button_pressed) {
148            // (56.56) = 41 44
149            outputs.leftStickX = 128 + (directions.x * 41);
150            outputs.leftStickY = 128 + (directions.y * 44);
151
152            // MY Pivot Uptilt/Dtilt
153            if (inputs.a) {
154                outputs.leftStickX = 128 + (directions.x * 34);
155                outputs.leftStickY = 128 + (directions.y * 38);
156            }
157        }
158    }
159
160    // C-stick ASDI Slideoff angle overrides any other C-stick modifiers (such as
161    // angled fsmash).
162    if (directions.cx != 0 && directions.cy != 0) {
163        // 5250 8500 = 42 68
164        outputs.rightStickX = 128 + (directions.cx * 42);
165        outputs.rightStickY = 128 + (directions.cy * 68);
166    }
167
168    if (inputs.l) {
169        outputs.triggerLAnalog = 140;
170    }
171
172    if (inputs.r) {
173        outputs.triggerRAnalog = 140;
174    }
175
176    // Shut off C-stick when using D-Pad layer.
177    if ((inputs.mod_x && inputs.mod_y) || inputs.nunchuk_c) {
178        outputs.rightStickX = 128;
179        outputs.rightStickY = 128;
180    }
181
182    // Nunchuk overrides left stick.
183    if (inputs.nunchuk_connected) {
184        outputs.leftStickX = inputs.nunchuk_x;
185        outputs.leftStickY = inputs.nunchuk_y;
186    }
187}