fork/GramFirmware

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

Skywalker1127Add files via upload007edc4

v0.1.0
3.1 KiB94 linesraw
1#include "modes/FgcMode.hpp"
2
3#define ANALOG_STICK_MIN 0
4#define ANALOG_STICK_NEUTRAL 128
5#define ANALOG_STICK_MAX 255
6
7FgcMode::FgcMode(socd::SocdType horizontal_socd, socd::SocdType vertical_socd) {
8    _socd_pair_count = 6;
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::down,  &InputState::mod_x, vertical_socd           },
18        socd::SocdPair{ &InputState::down,  &InputState::up2,   vertical_socd           },
19        socd::SocdPair{ &InputState::down,  &InputState::c_up,  vertical_socd           },
20    };
21}
22
23void FgcMode::UpdateDigitalOutputs(InputState &inputs, OutputState &outputs) {
24    // Directions
25    outputs.dpadLeft = inputs.left;
26    outputs.dpadRight = inputs.right;
27    outputs.dpadDown = inputs.down;
28    outputs.dpadUp = inputs.mod_x || inputs.up2 || inputs.c_up;
29
30    // L3 & R3
31    outputs.leftStickClick = inputs.l || inputs.c_left; 
32    outputs.rightStickClick = inputs.a;                       
33
34    // Menu keys
35    outputs.start = inputs.start;
36    outputs.select = inputs.select;
37    outputs.home = inputs.home;
38
39    // Activate select/home by holding Mod Y
40    if ((inputs.mod_y)) {
41        outputs.select = inputs.midshield;
42        outputs.home = inputs.start;
43    }
44
45    // Right hand bottom row
46    outputs.a = inputs.b;
47    outputs.b = inputs.x;
48    outputs.triggerRDigital = inputs.z;
49    outputs.triggerLDigital = inputs.up;
50
51    // Right hand top row
52    outputs.x = inputs.r;
53    outputs.y = inputs.y;
54    outputs.buttonR = inputs.lightshield;
55    outputs.buttonL = inputs.midshield;
56
57    // Turns off Start / LB when holding Mod Y
58    if ((inputs.mod_y)) {
59        outputs.start = false;
60        outputs.buttonL = false;
61        // Turn off DPad 
62        outputs.dpadLeft = false;
63        outputs.dpadRight = false;
64        outputs.dpadDown = false;
65        outputs.dpadUp = false;
66        outputs.leftStickClick = false;
67    }    
68}
69
70void FgcMode::UpdateAnalogOutputs(InputState &inputs, OutputState &outputs) {
71    outputs.leftStickX = 128;
72    outputs.leftStickY = 128;
73    outputs.rightStickX = 128;
74    outputs.rightStickY = 128;
75    outputs.triggerLAnalog = outputs.triggerLDigital ? 255 : 0;
76    outputs.triggerRAnalog = outputs.triggerRDigital ? 255 : 0;
77
78    //Hold Mod Y to use analog input.
79    if ((inputs.mod_y)) {
80    UpdateDirections(
81    inputs.left,
82    inputs.right,
83    inputs.down,
84    inputs.up2,
85    inputs.c_left,
86    inputs.c_right,
87    inputs.c_down,
88    inputs.c_up,
89    ANALOG_STICK_MIN,
90    ANALOG_STICK_NEUTRAL,
91    ANALOG_STICK_MAX,
92    outputs);
93    }
94}