fork/GramFirmware

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

Jonathan HaylettFix XInput D-Pad issues on Linux33045e9

v0.1.2
1.8 KiB63 linesraw
1#include "comms/XInputBackend.hpp"
2
3#include "core/CommunicationBackend.hpp"
4#include "core/state.hpp"
5
6#include <Adafruit_USBD_XInput.hpp>
7
8XInputBackend::XInputBackend(InputSource **input_sources, size_t input_source_count)
9    : CommunicationBackend(input_sources, input_source_count) {
10    Serial.end();
11    _xinput = new Adafruit_USBD_XInput();
12    _xinput->begin();
13    Serial.begin(115200);
14
15    TinyUSBDevice.setID(0x0738, 0x4726);
16
17    while (!_xinput->ready()) {
18        delay(1);
19    }
20}
21
22XInputBackend::~XInputBackend() {
23    delete _xinput;
24}
25
26void XInputBackend::SendReport() {
27    ScanInputs(InputScanSpeed::SLOW);
28    ScanInputs(InputScanSpeed::MEDIUM);
29
30    while (!_xinput->ready()) {
31        tight_loop_contents();
32    }
33
34    ScanInputs(InputScanSpeed::FAST);
35
36    UpdateOutputs();
37
38    // Digital outputs
39    _report.a = _outputs.a;
40    _report.b = _outputs.b;
41    _report.x = _outputs.x;
42    _report.y = _outputs.y;
43    _report.lb = _outputs.buttonL;
44    _report.rb = _outputs.buttonR;
45    _report.lt = _outputs.triggerLDigital ? 255 : _outputs.triggerLAnalog;
46    _report.rt = _outputs.triggerRDigital ? 255 : _outputs.triggerRAnalog;
47    _report.start = _outputs.start;
48    _report.back = _outputs.select;
49    _report.home = _outputs.home;
50    _report.dpad_up = _outputs.dpadUp;
51    _report.dpad_down = _outputs.dpadDown;
52    _report.dpad_left = _outputs.dpadLeft;
53    _report.dpad_right = _outputs.dpadRight;
54    _report.ls = _outputs.leftStickClick;
55    _report.rs = _outputs.rightStickClick;
56
57    _report.lx = (_outputs.leftStickX - 128) * 65535 / 255 + 128;
58    _report.ly = (_outputs.leftStickY - 128) * 65535 / 255 + 128;
59    _report.rx = (_outputs.rightStickX - 128) * 65535 / 255 + 128;
60    _report.ry = (_outputs.rightStickY - 128) * 65535 / 255 + 128;
61
62    _xinput->sendReport(&_report);
63}