fork/GramFirmware

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

Skywalker1127Added Up2 as taunt toggle2c36333

v0.1.1
7.0 KiB225 linesraw
1#include "modes/ProjectM.hpp"
2
3#define ANALOG_STICK_MIN 28
4#define ANALOG_STICK_NEUTRAL 128
5#define ANALOG_STICK_MAX 228
6
7ProjectM::ProjectM(socd::SocdType socd_type, ProjectMOptions options) {
8    _socd_pair_count = 4;
9    _socd_pairs = new socd::SocdPair[_socd_pair_count]{
10        socd::SocdPair{&InputState::left,    &InputState::right,   socd_type},
11        socd::SocdPair{ &InputState::down,   &InputState::up,      socd_type},
12        socd::SocdPair{ &InputState::c_left, &InputState::c_right, socd_type},
13        socd::SocdPair{ &InputState::c_down, &InputState::c_up,    socd_type},
14    };
15
16    _options = options;
17    _horizontal_socd = false;
18}
19
20void ProjectM::HandleSocd(InputState &inputs) {
21    _horizontal_socd = inputs.left && inputs.right;
22    InputMode::HandleSocd(inputs);
23}
24
25void ProjectM::UpdateDigitalOutputs(InputState &inputs, OutputState &outputs) {
26    outputs.a = inputs.a;
27    outputs.b = inputs.b;
28    outputs.x = inputs.x;
29    outputs.y = inputs.y;
30    // True Z press vs macro lightshield + A.
31    if (_options.true_z_press || inputs.mod_x) {
32        outputs.buttonR = inputs.z;
33    } else {
34        outputs.a = inputs.a || inputs.z;
35    }
36    if (inputs.nunchuk_connected) {
37        outputs.triggerLDigital = inputs.nunchuk_z;
38    } else {
39        outputs.triggerLDigital = inputs.l;
40    }
41    outputs.triggerRDigital = inputs.r;
42    outputs.start = inputs.start;
43
44    // Activate D-Pad layer by holding Mod X + Mod Y or Nunchuk C button.
45    if ((inputs.mod_x && inputs.mod_y) || inputs.up2) {
46        outputs.dpadUp = inputs.c_up;
47        outputs.dpadDown = inputs.c_down;
48        outputs.dpadLeft = inputs.c_left;
49        outputs.dpadRight = inputs.c_right;
50    }
51
52    // Don't override dpad up if it's already pressed using the MX + MY dpad
53    // layer.
54    outputs.dpadUp = outputs.dpadUp || inputs.midshield;
55
56    if (inputs.select)
57        outputs.dpadLeft = true;
58    if (inputs.home)
59        outputs.dpadRight = true;
60}
61
62void ProjectM::UpdateAnalogOutputs(InputState &inputs, OutputState &outputs) {
63    UpdateDirections(
64        inputs.left,
65        inputs.right,
66        inputs.down,
67        inputs.up,
68        inputs.c_left,
69        inputs.c_right,
70        inputs.c_down,
71        inputs.c_up,
72        ANALOG_STICK_MIN,
73        ANALOG_STICK_NEUTRAL,
74        ANALOG_STICK_MAX,
75        outputs
76    );
77
78    bool shield_button_pressed = inputs.l || inputs.lightshield;
79
80    if (directions.diagonal) {
81        if (directions.y == 1) {
82            outputs.leftStickX = 128 + (directions.x * 83);
83            outputs.leftStickY = 128 + (directions.y * 93);
84        }
85    }
86
87    if (inputs.mod_x) {
88        if (directions.horizontal) {
89            outputs.leftStickX = 128 + (directions.x * 70);
90        }
91        if (directions.vertical) {
92            outputs.leftStickY = 128 + (directions.y * 60);
93        }
94
95        if (directions.cx != 0) {
96            outputs.rightStickX = 128 + (directions.cx * 65);
97            outputs.rightStickY = 128 + (directions.y * 23);
98        }
99
100        if (directions.diagonal) {
101            outputs.leftStickX = 128 + (directions.x * 70);
102            outputs.leftStickY = 128 + (directions.y * 34);
103
104            if (inputs.b) {
105                outputs.leftStickX = 128 + (directions.x * 85);
106                outputs.leftStickY = 128 + (directions.y * 31);
107            }
108
109            if (inputs.r) {
110                outputs.leftStickX = 128 + (directions.x * 82);
111                outputs.leftStickY = 128 + (directions.y * 35);
112            }
113
114            if (inputs.c_up) {
115                outputs.leftStickX = 128 + (directions.x * 77);
116                outputs.leftStickY = 128 + (directions.y * 55);
117            }
118
119            if (inputs.c_down) {
120                outputs.leftStickX = 128 + (directions.x * 82);
121                outputs.leftStickY = 128 + (directions.y * 36);
122            }
123
124            if (inputs.c_left) {
125                outputs.leftStickX = 128 + (directions.x * 84);
126                outputs.leftStickY = 128 + (directions.y * 50);
127            }
128
129            if (inputs.c_right) {
130                outputs.leftStickX = 128 + (directions.x * 72);
131                outputs.leftStickY = 128 + (directions.y * 61);
132            }
133        }
134    }
135
136    if (inputs.mod_y) {
137        if (directions.horizontal) {
138            outputs.leftStickX = 128 + (directions.x * 35);
139        }
140        if (directions.vertical) {
141            outputs.leftStickY = 128 + (directions.y * 70);
142        }
143
144        if (directions.diagonal) {
145            outputs.leftStickX = 128 + (directions.x * 28);
146            outputs.leftStickY = 128 + (directions.y * 58);
147
148            if (inputs.b) {
149                outputs.leftStickX = 128 + (directions.x * 28);
150                outputs.leftStickY = 128 + (directions.y * 85);
151            }
152
153            if (inputs.r) {
154                outputs.leftStickX = 128 + (directions.x * 51);
155                outputs.leftStickY = 128 + (directions.y * 82);
156            }
157
158            if (inputs.c_up) {
159                outputs.leftStickX = 128 + (directions.x * 55);
160                outputs.leftStickY = 128 + (directions.y * 77);
161            }
162
163            if (inputs.c_down) {
164                outputs.leftStickX = 128 + (directions.x * 34);
165                outputs.leftStickY = 128 + (directions.y * 82);
166            }
167
168            if (inputs.c_left) {
169                outputs.leftStickX = 128 + (directions.x * 40);
170                outputs.leftStickY = 128 + (directions.y * 84);
171            }
172
173            if (inputs.c_right) {
174                outputs.leftStickX = 128 + (directions.x * 62);
175                outputs.leftStickY = 128 + (directions.y * 72);
176            }
177        }
178    }
179
180    // C-stick ASDI Slideoff angle overrides any other C-stick modifiers (such as
181    // angled fsmash).
182    // We don't apply this for c-up + c-left/c-right in case we want to implement
183    // C-stick nair somehow.
184    if (directions.cx != 0 && directions.cy == -1) {
185        // 3000 9875 = 30 78
186        outputs.rightStickX = 128 + (directions.cx * 35);
187        outputs.rightStickY = 128 + (directions.cy * 98);
188    }
189
190    // Horizontal SOCD overrides X-axis modifiers (for ledgedash maximum jump
191    // trajectory).
192    if (_options.ledgedash_max_jump_traj && _horizontal_socd && !directions.vertical &&
193        !shield_button_pressed) {
194        outputs.leftStickX = 128 + (directions.x * 100);
195    }
196
197    if (inputs.lightshield) {
198        outputs.triggerRAnalog = 49;
199    }
200
201    // Send lightshield input if we are using Z = lightshield + A macro.
202    if (inputs.z && !(inputs.mod_x || _options.true_z_press)) {
203        outputs.triggerRAnalog = 49;
204    }
205
206    if (outputs.triggerLDigital) {
207        outputs.triggerLAnalog = 140;
208    }
209
210    if (outputs.triggerRDigital) {
211        outputs.triggerRAnalog = 140;
212    }
213
214    // Shut off C-stick when using D-Pad layer.
215    if ((inputs.mod_x && inputs.mod_y) || inputs.up2) {
216        outputs.rightStickX = 128;
217        outputs.rightStickY = 128;
218    }
219
220    // Nunchuk overrides left stick.
221    if (inputs.nunchuk_connected) {
222        outputs.leftStickX = inputs.nunchuk_x;
223        outputs.leftStickY = inputs.nunchuk_y;
224    }
225}