fork/GramFirmware
git clone https://git.julia.blue/fork/GramFirmware
818d962
gram
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 ( 9InputState & inputs , 10InputSource ** input_sources , 11size_t input_source_count 12) 13 :CommunicationBackend (inputs ,input_sources ,input_source_count ), 14_xinput () { 15Serial .end (); 16_xinput .begin (); 17Serial .begin (115200 ); 18 19TinyUSBDevice .setID (0x0738 ,0x4726 ); 20} 21 22CommunicationBackendId XInputBackend ::BackendId () { 23return COMMS_BACKEND_XINPUT ; 24} 25 26void XInputBackend ::SendReport () { 27if (!_gamemode -> isMelee ()) { 28ScanInputs (InputScanSpeed ::SLOW ); 29ScanInputs (InputScanSpeed ::MEDIUM ); 30 } 31 32while (!_xinput .ready ()) { 33tight_loop_contents (); 34 } 35 36if (!_gamemode -> isMelee ()) { 37ScanInputs (InputScanSpeed ::FAST ); 38 39UpdateOutputs (); 40 } 41 42if (!_gamemode -> isMelee ()) { 43// Digital outputs 44_report .a = _outputs .a ; 45_report .b = _outputs .b ; 46_report .x = _outputs .x ; 47_report .y = _outputs .y ; 48_report .lb = _outputs .buttonL ; 49_report .rb = _outputs .buttonR ; 50_report .lt = _outputs .triggerLDigital ?255 :_outputs .triggerLAnalog ; 51_report .rt = _outputs .triggerRDigital ?255 :_outputs .triggerRAnalog ; 52_report .start = _outputs .start ; 53_report .back = _outputs .select ; 54_report .home = _outputs .home ; 55_report .dpad_up = _outputs .dpadUp ; 56_report .dpad_down = _outputs .dpadDown ; 57_report .dpad_left = _outputs .dpadLeft ; 58_report .dpad_right = _outputs .dpadRight ; 59_report .ls = _outputs .leftStickClick ; 60_report .rs = _outputs .rightStickClick ; 61 62_report .lx = (_outputs .leftStickX - 128 )* 65535 /255 + 128 ; 63_report .ly = (_outputs .leftStickY - 128 )* 65535 /255 + 128 ; 64_report .rx = (_outputs .rightStickX - 128 )* 65535 /255 + 128 ; 65_report .ry = (_outputs .rightStickY - 128 )* 65535 /255 + 128 ; 66 }else { 67// Digital outputs 68_report .a = _finalOutputs .a ; 69_report .b = _finalOutputs .b ; 70_report .x = _finalOutputs .x ; 71_report .y = _finalOutputs .y ; 72_report .lb = _finalOutputs .buttonL ; 73_report .rb = _finalOutputs .buttonR ; 74_report .lt = _finalOutputs .triggerLDigital ?255 :_finalOutputs .triggerLAnalog ; 75_report .rt = _finalOutputs .triggerRDigital ?255 :_finalOutputs .triggerRAnalog ; 76_report .start = _finalOutputs .start ; 77_report .back = _finalOutputs .select ; 78_report .home = _finalOutputs .home ; 79_report .dpad_up = _finalOutputs .dpadUp ; 80_report .dpad_down = _finalOutputs .dpadDown ; 81_report .dpad_left = _finalOutputs .dpadLeft ; 82_report .dpad_right = _finalOutputs .dpadRight ; 83_report .ls = _finalOutputs .leftStickClick ; 84_report .rs = _finalOutputs .rightStickClick ; 85 86_report .lx = (_finalOutputs .leftStickX - 128 )* 65535 /255 + 128 ; 87_report .ly = (_finalOutputs .leftStickY - 128 )* 65535 /255 + 128 ; 88_report .rx = (_finalOutputs .rightStickX - 128 )* 65535 /255 + 128 ; 89_report .ry = (_finalOutputs .rightStickY - 128 )* 65535 /255 + 128 ; 90 } 91 92_xinput .sendReport (& _report ); 93}