fork/GramFirmware
git clone https://git.julia.blue/fork/GramFirmware
33045e9
master
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 ) { 10Serial .end (); 11_xinput = new Adafruit_USBD_XInput (); 12_xinput -> begin (); 13Serial .begin (115200 ); 14 15TinyUSBDevice .setID (0x0738 ,0x4726 ); 16 17while (!_xinput -> ready ()) { 18delay (1 ); 19 } 20} 21 22XInputBackend ::~XInputBackend () { 23delete _xinput ; 24} 25 26void XInputBackend ::SendReport () { 27ScanInputs (InputScanSpeed ::SLOW ); 28ScanInputs (InputScanSpeed ::MEDIUM ); 29 30while (!_xinput -> ready ()) { 31tight_loop_contents (); 32 } 33 34ScanInputs (InputScanSpeed ::FAST ); 35 36UpdateOutputs (); 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}