fork/GramFirmware

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

Skywalker1127Updated SOCD Pair # with addition of Up2b54c384

WASD_NeutralSOCD
3.2 KiB95 linesraw
1#include "modes/FgcMode.hpp"
2
3#define ANALOG_STICK_MIN 28
4#define ANALOG_STICK_NEUTRAL 128
5#define ANALOG_STICK_MAX 228
6
7FgcMode::FgcMode(socd::SocdType horizontal_socd, socd::SocdType vertical_socd) {
8    _socd_pair_count = 7;
9    _socd_pairs = new socd::SocdPair[_socd_pair_count]{
10        socd::SocdPair{&InputState::left,   &InputState::right, horizontal_socd         },
11 /* Mod X override C-Up input if both are pressed. Without this, neutral SOCD doesn't work
12  properly if Down and both Up buttons are pressed, because it first resolves Down + Mod X
13  to set both as unpressed, and then it sees C-Up as pressed but not Down, so you get an up
14  input instead of neutral. */
15        socd::SocdPair{ &InputState::mod_x, &InputState::c_up,  socd::SOCD_DIR1_PRIORITY},
16        socd::SocdPair{ &InputState::mod_x, &InputState::up2,   socd::SOCD_DIR1_PRIORITY},
17        socd::SocdPair{ &InputState::c_up,  &InputState::up2,   socd::SOCD_DIR1_PRIORITY},
18        socd::SocdPair{ &InputState::down,  &InputState::mod_x, vertical_socd           },
19        socd::SocdPair{ &InputState::down,  &InputState::up2,   vertical_socd           },
20        socd::SocdPair{ &InputState::down,  &InputState::c_up,  vertical_socd           },
21    };
22}
23
24void FgcMode::UpdateDigitalOutputs(InputState &inputs, OutputState &outputs) {
25    // Directions
26    outputs.dpadLeft = inputs.left;
27    outputs.dpadRight = inputs.right;
28    outputs.dpadDown = inputs.down;
29    outputs.dpadUp = inputs.mod_x || inputs.up2 || inputs.c_up;
30
31    // L3 & R3
32    outputs.leftStickClick = inputs.l || inputs.c_left; 
33    outputs.rightStickClick = inputs.a;                       
34
35    // Menu keys
36    outputs.start = inputs.start;
37    outputs.select = inputs.select;
38    outputs.home = inputs.home;
39
40    // Activate select/home by holding Mod Y
41    if ((inputs.mod_y)) {
42        outputs.select = inputs.midshield;
43        outputs.home = inputs.start;
44    }
45
46    // Right hand bottom row
47    outputs.a = inputs.b;
48    outputs.b = inputs.x;
49    outputs.triggerRDigital = inputs.z;
50    outputs.triggerLDigital = inputs.up;
51
52    // Right hand top row
53    outputs.x = inputs.r;
54    outputs.y = inputs.y;
55    outputs.buttonR = inputs.lightshield;
56    outputs.buttonL = inputs.midshield;
57
58    // Turns off Start / LB when holding Mod Y
59    if ((inputs.mod_y)) {
60        outputs.start = false;
61        outputs.buttonL = false;
62        // Turn off DPad 
63        outputs.dpadLeft = false;
64        outputs.dpadRight = false;
65        outputs.dpadDown = false;
66        outputs.dpadUp = false;
67        outputs.leftStickClick = false;
68    }    
69}
70
71void FgcMode::UpdateAnalogOutputs(InputState &inputs, OutputState &outputs) {
72    outputs.leftStickX = 128;
73    outputs.leftStickY = 128;
74    outputs.rightStickX = 128;
75    outputs.rightStickY = 128;
76    outputs.triggerLAnalog = outputs.triggerLDigital ? 255 : 0;
77    outputs.triggerRAnalog = outputs.triggerRDigital ? 255 : 0;
78
79    //Hold Mod Y to use analog input.
80    if ((inputs.mod_y)) {
81    UpdateDirections(
82    inputs.left,
83    inputs.right,
84    inputs.down,
85    inputs.up2,
86    inputs.c_left,
87    inputs.c_right,
88    inputs.c_down,
89    inputs.c_up,
90    ANALOG_STICK_MIN,
91    ANALOG_STICK_NEUTRAL,
92    ANALOG_STICK_MAX,
93    outputs);
94    }
95}