fork/GramFirmware
git clone https://git.julia.blue/fork/GramFirmware
818d962
gram
1#include "comms/DInputBackend.hpp" 2 3#include "core/CommunicationBackend.hpp" 4#include "core/state.hpp" 5 6#include <Joystick.h> 7 8DInputBackend ::DInputBackend ( 9InputState & inputs , 10InputSource ** input_sources , 11size_t input_source_count 12) 13 :CommunicationBackend (inputs ,input_sources ,input_source_count ) { 14_joystick .begin (); 15 16//Set up hardware timer 17TCCR1A = 0 ; 18TCCR1B = (1 <<CS11 ) | (1 <<CS10 );//64 clock divider -> 4 microsecond resolution 19zeroTcnt1 (); 20} 21 22DInputBackend ::~DInputBackend () { 23_joystick .end (); 24} 25 26CommunicationBackendId DInputBackend ::BackendId () { 27return COMMS_BACKEND_DINPUT ; 28} 29 30void DInputBackend ::SendReport () { 31static uint sampleSpacing = 350 ; 32//static uint16_t loopTime = 16383; 33 34while (readTcnt1 ()< sampleSpacing ) { 35//spinlock to make things about 720 hz, about the fastest it'll go while running the b0xx input viewer 36 } 37 38//read how long this loop took 39//loopTime = readTcnt1();//each unit is 4 microseconds 40//zero the counter so that it doesn't overflow 41zeroTcnt1 (); 42//Serial.print("Loop time: "); 43//Serial.println(loopTime); 44 45ScanInputs (); 46 47// Run gamemode logic. 48UpdateOutputs (); 49 50//if(_nerfOn) { 51if (_gamemode -> isMelee ()) { 52//APPLY NERFS HERE 53OutputState nerfedOutputs ; 54limitOutputs (sampleSpacing ,_nerfOn ?AB_A :AB_B ,_inputs ,_outputs ,nerfedOutputs ); 55 56// Digital outputs 57_joystick -> setButton (0 ,nerfedOutputs .b ); 58_joystick -> setButton (1 ,nerfedOutputs .a ); 59_joystick -> setButton (2 ,nerfedOutputs .y ); 60_joystick -> setButton (3 ,nerfedOutputs .x ); 61_joystick -> setButton (4 ,nerfedOutputs .buttonR ); 62_joystick -> setButton (5 ,nerfedOutputs .triggerRDigital ); 63_joystick -> setButton (6 ,nerfedOutputs .buttonL ); 64_joystick -> setButton (7 ,nerfedOutputs .triggerLDigital ); 65_joystick -> setButton (8 ,nerfedOutputs .select ); 66_joystick -> setButton (9 ,nerfedOutputs .start ); 67_joystick -> setButton (10 ,nerfedOutputs .rightStickClick ); 68_joystick -> setButton (11 ,nerfedOutputs .leftStickClick ); 69_joystick -> setButton (12 ,nerfedOutputs .home ); 70 71// Analog outputs 72_joystick -> setXAxis (nerfedOutputs .leftStickX ); 73_joystick -> setYAxis (255 - nerfedOutputs .leftStickY ); 74_joystick -> setRxAxis (nerfedOutputs .rightStickX ); 75_joystick -> setRyAxis (255 - nerfedOutputs .rightStickY ); 76_joystick -> setZAxis (nerfedOutputs .triggerLAnalog + 1 ); 77_joystick -> setRzAxis (nerfedOutputs .triggerRAnalog + 1 ); 78 79// D-pad Hat Switch 80_joystick -> setHatSwitch (_outputs .dpadLeft ,_outputs .dpadRight ,_outputs .dpadDown ,_outputs .dpadUp ); 81 }else { 82// Digital outputs 83_joystick -> setButton (0 ,_outputs .b ); 84_joystick -> setButton (1 ,_outputs .a ); 85_joystick -> setButton (2 ,_outputs .y ); 86_joystick -> setButton (3 ,_outputs .x ); 87_joystick -> setButton (4 ,_outputs .buttonR ); 88_joystick -> setButton (5 ,_outputs .triggerRDigital ); 89_joystick -> setButton (6 ,_outputs .buttonL ); 90_joystick -> setButton (7 ,_outputs .triggerLDigital ); 91_joystick -> setButton (8 ,_outputs .select ); 92_joystick -> setButton (9 ,_outputs .start ); 93_joystick -> setButton (10 ,_outputs .rightStickClick ); 94_joystick -> setButton (11 ,_outputs .leftStickClick ); 95_joystick -> setButton (12 ,_outputs .home ); 96 97// Analog outputs 98_joystick -> setXAxis (_outputs .leftStickX ); 99_joystick -> setYAxis (255 - _outputs .leftStickY ); 100_joystick -> setRxAxis (_outputs .rightStickX ); 101_joystick -> setRyAxis (255 - _outputs .rightStickY ); 102_joystick -> setZAxis (_outputs .triggerLAnalog + 1 ); 103_joystick -> setRzAxis (_outputs .triggerRAnalog + 1 ); 104 105// D-pad Hat Switch 106_joystick -> setHatSwitch (_outputs .dpadLeft ,_outputs .dpadRight ,_outputs .dpadDown ,_outputs .dpadUp ); 107 } 108}