fork/GramFirmware
git clone https://git.julia.blue/fork/GramFirmware
818d962
gram
1#include "core/ControllerMode.hpp" 2 3ControllerMode ::ControllerMode () :InputMode () { 4// Set up initial state. 5ResetDirections (); 6} 7 8void ControllerMode ::UpdateOutputs (const InputState & inputs ,OutputState & outputs ) { 9// Create a copy of the input state here so remapping can be many-to-one (many physical buttons 10// to one activated button). 11InputState remapped_inputs = inputs ; 12HandleRemap (inputs ,remapped_inputs ); 13HandleSocd (remapped_inputs ); 14UpdateDigitalOutputs (remapped_inputs ,outputs ); 15UpdateAnalogOutputs (remapped_inputs ,outputs ); 16} 17 18void ControllerMode ::ResetDirections () { 19directions = { 20 .horizontal = false, 21 .vertical = false, 22 .diagonal = false, 23 .x = 0 , 24 .y = 0 , 25 .cx = 0 , 26 .cy = 0 , 27 }; 28} 29 30void ControllerMode ::UpdateDirections ( 31bool lsLeft , 32bool lsRight , 33bool lsDown , 34bool lsUp , 35bool rsLeft , 36bool rsRight , 37bool rsDown , 38bool rsUp , 39uint8_t analogStickMin , 40uint8_t analogStickNeutral , 41uint8_t analogStickMax , 42OutputState & outputs 43) { 44ResetDirections (); 45 46outputs .leftStickX = analogStickNeutral ; 47outputs .leftStickY = analogStickNeutral ; 48outputs .rightStickX = analogStickNeutral ; 49outputs .rightStickY = analogStickNeutral ; 50 51// Coordinate calculations to make modifier handling simpler. 52if (lsLeft || lsRight ) { 53directions .horizontal = true; 54if (lsLeft ) { 55directions .x = -1 ; 56outputs .leftStickX = analogStickMin ; 57 }else { 58directions .x = 1 ; 59outputs .leftStickX = analogStickMax ; 60 } 61 } 62if (lsDown || lsUp ) { 63directions .vertical = true; 64if (lsDown ) { 65directions .y = -1 ; 66outputs .leftStickY = analogStickMin ; 67 }else { 68directions .y = 1 ; 69outputs .leftStickY = analogStickMax ; 70 } 71 } 72if (directions .horizontal && directions .vertical ) 73directions .diagonal = true; 74 75if (rsLeft || rsRight ) { 76if (rsLeft ) { 77directions .cx = -1 ; 78outputs .rightStickX = analogStickMin ; 79 }else { 80directions .cx = 1 ; 81outputs .rightStickX = analogStickMax ; 82 } 83 } 84if (rsDown || rsUp ) { 85if (rsDown ) { 86directions .cy = -1 ; 87outputs .rightStickY = analogStickMin ; 88 }else { 89directions .cy = 1 ; 90outputs .rightStickY = analogStickMax ; 91 } 92 } 93}