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