fork/GramFirmware

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

Jonathan HaylettSOCD revamp (#57)1f92ae6

v0.1.1
3.0 KiB93 linesraw
1#include "modes/extra/RocketLeague.hpp"
2
3#define ANALOG_STICK_MIN 0
4#define ANALOG_STICK_NEUTRAL 128
5#define ANALOG_STICK_MAX 255
6
7RocketLeague::RocketLeague(socd::SocdType socd_type) {
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::mod_x,   socd::SOCD_DIR2_PRIORITY},
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
17void RocketLeague::UpdateDigitalOutputs(InputState &inputs, OutputState &outputs) {
18    outputs.a = inputs.a;
19    outputs.b = inputs.b;
20    outputs.x = inputs.midshield;
21    outputs.y = inputs.up;
22    outputs.buttonL = inputs.l;
23    outputs.buttonR = inputs.lightshield;
24    outputs.triggerLDigital = inputs.z;
25    outputs.triggerRDigital = inputs.x;
26    outputs.leftStickClick = inputs.r;
27
28    // Hold accelerate and reverse simultaneously for rear view.
29    if (inputs.z && inputs.x) {
30        outputs.rightStickClick = true;
31        // Override (deactivate) accelerator.
32        outputs.triggerRDigital = false;
33    }
34
35    // MX + Start = Select
36    if (inputs.mod_x)
37        outputs.select = inputs.start;
38    else
39        outputs.start = inputs.start;
40
41    // D-Pad
42    if (inputs.mod_x && inputs.mod_y) {
43        outputs.dpadUp = inputs.c_up;
44        outputs.dpadDown = inputs.c_down;
45        outputs.dpadLeft = inputs.c_left;
46        outputs.dpadRight = inputs.c_right;
47    }
48}
49
50void RocketLeague::UpdateAnalogOutputs(InputState &inputs, OutputState &outputs) {
51    // Coordinate calculations to make modifier handling simpler.
52    UpdateDirections(
53        inputs.left,
54        inputs.right,
55        inputs.down,
56        inputs.mod_x,
57        inputs.c_left,
58        inputs.c_right,
59        inputs.c_down,
60        inputs.c_up,
61        ANALOG_STICK_MIN,
62        ANALOG_STICK_NEUTRAL,
63        ANALOG_STICK_MAX,
64        outputs
65    );
66
67    if (inputs.mod_y) {
68        if (directions.diagonal) {
69            outputs.leftStickX = ANALOG_STICK_NEUTRAL + (directions.x * 70);
70            // outputs.leftStickY =
71            // ANALOG_STICK_NEUTRAL + (directions.y * 76);
72        } else if (directions.horizontal) {
73            outputs.leftStickX = ANALOG_STICK_NEUTRAL + (directions.x * 35);
74        } else if (directions.vertical) {
75            outputs.leftStickY = ANALOG_STICK_NEUTRAL + (directions.y * 76);
76        }
77    } else if (directions.diagonal) {
78        // Good speed flip angle with no mods.
79        outputs.leftStickX = ANALOG_STICK_NEUTRAL + (directions.x * 70);
80    }
81
82    // Shut off right stick when using dpad layer.
83    if (inputs.mod_x && inputs.mod_y) {
84        outputs.rightStickX = ANALOG_STICK_NEUTRAL;
85        outputs.rightStickY = ANALOG_STICK_NEUTRAL;
86    }
87
88    // Nunchuk overrides left stick.
89    if (inputs.nunchuk_connected) {
90        outputs.leftStickX = inputs.nunchuk_x;
91        outputs.leftStickY = inputs.nunchuk_y;
92    }
93}