public int Get(ref GameControllerValues toFill, uint idx) { /* set the device mask bits, these are global */ _gpInts[16] = (int)_maskBits; const uint numDwords = 17; /* only send params to be read */ return(SyncGet(ref toFill, numDwords)); }
public int Sync(ref GameControllerValues toFill, uint rumbleL, uint rumbleR, uint ledCode, uint controlFlags, uint idx) { /* save commands */ _gpInts[20] = (int)rumbleL; _gpInts[21] = (int)rumbleR; _gpInts[22] = (int)ledCode; _gpInts[23] = (int)controlFlags; /* set the device mask bits, these are global */ _gpInts[16] = (int)_maskBits; return(SyncGet(ref toFill, (uint)_gpInts.Length)); }
void Awake() { GameObject[] objs = GameObject.FindGameObjectsWithTag("GameController"); if (objs.Length > 1) { Destroy(this.gameObject); } savedValues = new GameControllerValues(); DontDestroyOnLoad(this.gameObject); gameRandom = new System.Random(); }
////////////////////////////////////// /// Debug helper functions ////////////////////////////////////// void printGamepadAxes() { GameControllerValues values = new GameControllerValues(); js0.GetAllValues(ref values); string output = ""; for (int i = 0; i < values.axes.Length; ++i) { output += values.axes[i] + ","; } Debug.Print(output); }
void printGamepadButtons() { GameControllerValues values = new GameControllerValues(); js0.GetAllValues(ref values); string output = ""; for (int i = 0; i < 15; ++i) { uint current = values.btns & 0x1; values.btns = values.btns >> 1; output += current + ","; } Debug.Print(output); }
static void LoadGameController() { string directoryPath = Application.persistentDataPath + "/" + fileSlot; if (File.Exists(directoryPath + "/GameController.save")) { GameControllerValues loadedController = new GameControllerValues(); BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(directoryPath + "/GameController.save", FileMode.Open); loadedController = (GameControllerValues)bf.Deserialize(file); file.Close(); Commands.GetGameCont().LoadGameControllerData(loadedController); } else { Debug.Log("No save file found for slot!"); } }
/** * Interface for anything that provides gamepad/joystick values (could be from a host pc or from USB attached gamepad). * @return Negative If values could not be retrieved due to connection issue. toFill is cleared. * Zero if values are stale (no new data). toFill is left untouched. * Positive if values are updated. toFill is filled in. */ private int SyncGet(ref GameControllerValues toFill, uint numDwords) { /* always get latest data for now */ updateCnt = 0; int ret = CTRE.Native.HDU.GetJoy(ref updateCnt, _gpInts, (uint)numDwords, _gpFlts, (uint)_gpFlts.Length); if (ret < 0) { /* negative error code means data is unreliable */ if (toFill != null) { toFill.Copy(GameControllerValues.ZeroGameControllerValues); } /* on the next poll, always get latest */ updateCnt = 0; } else if (ret == 0) { /* no changes*/ } else { /* new data, copy it over */ if (toFill != null) { toFill.axes[0] = _gpFlts[0]; toFill.axes[1] = _gpFlts[1]; toFill.axes[2] = _gpFlts[2]; toFill.axes[3] = _gpFlts[3]; toFill.axes[4] = _gpFlts[4]; toFill.axes[5] = _gpFlts[5]; toFill.btns = (uint)_gpInts[0]; toFill.pov = _gpInts[1]; toFill.vid = (uint)_gpInts[6]; toFill.pid = (uint)_gpInts[7]; toFill.vendorSpecF = _gpFlts; toFill.vendorSpecI = _gpInts; toFill.flagBits = (uint)_gpInts[8]; } } return(ret); }
/** * This will allow for Logitech gamepads with DInput selected. * Selecting XInput on the gamepad will cause joystick to * disconnect (typically disabling robot). * This is the default setting for freshly powered HEROs, and also what * is hardcoded in previous HERO releases. */ //public static void EnableDInputDevices() //{ // _maskBits = 0; //} /** * This will allow for Logitech gamepads with XInput selected. * Selecting Dinput on the gamepad will cause joystick to * disconnect (typically disabling robot). * This can be used to leverage the advanced features of the F710 series * gamepad (analog triggers, vibration, more resolute axis data). */ //public static void EnableXInputDevices() //{ // _maskBits = 2 + 4; //} public void SetSelectableXInputFilter(SelectableXInputFilter filter) { switch (filter) { case SelectableXInputFilter.BothDInputAndXInput: _maskBits = 4; break; case SelectableXInputFilter.DInputDevices: _maskBits = 0; break; case SelectableXInputFilter.XInputDevices: _maskBits = 2 + 4; break; } /* ignore return */ GameControllerValues gv = null; Get(ref gv, index); }
public void LoadGameControllerData(GameControllerValues loadedController) { savedValues.currentMode = loadedController.currentMode; newGame = false; }
public static void Main() { var casterDrive = new CasterDrive(); // uncomment this if you need to zero the swerves /*while (true) * { * Debug.Print("Angle: " + casterDrive.casters[0].Angle + "\t" + casterDrive.casters[1].Angle + "\t" + casterDrive.casters[2].Angle); * }*/ var cannon = new Cannon(); // TODO: Move controller stuff to operator input class var controller = new GameController(UsbHostDevice.GetInstance()); Debug.Print("Program started"); var controllerValues = new GameControllerValues(); var stopwatch = new Stopwatch(); var watchdogListener = new Listener(false); var shootModeToggler = new Toggler(true); var shootListener = new Listener(true); var zeroListener = new Listener(false); while (true) { double dt = stopwatch.Duration; stopwatch.Start(); controller.GetAllValues(ref controllerValues); bool isEnabled = controller.GetButton(5); if (isEnabled && controller.GetConnectionStatus() == UsbDeviceConnection.Connected) { Watchdog.Feed(); } double turn = -controller.GetAxis(2); casterDrive.Drive(new Vector2(-controller.GetAxis(0), controller.GetAxis(1)), turn); bool shootMode = shootModeToggler.Get(isEnabled && controller.GetButton(1)); if (zeroListener.Get(controller.GetButton(3))) { Debug.Print("Zeroing Gyro"); casterDrive.ZeroGyro(); } bool firing = isEnabled && shootListener.Get(controller.GetButton(6)); if (watchdogListener.Get(Watchdog.IsEnabled())) { cannon.Setpoint = cannon.Angle; } double adjust; if (controllerValues.pov == 0) { adjust = 30.0 * dt; } else if (controllerValues.pov == 4) { adjust = -30.0 * dt; } else { adjust = 0.0; } cannon.Update(shootMode, firing, adjust); //Debug.Print(controllerValues.pov +""); //Debug.Print(dt +""); //cannon.DebugPID(); /* * leftMax = Math.Max(leftMax, casterDrive.casters[0].TurnCurrent); * rightMax = Math.Max(rightMax, casterDrive.casters[1].TurnCurrent); * backMax = Math.Max(backMax, casterDrive.casters[2].TurnCurrent); * Debug.Print("Left: " + leftMax + "\tRight: " + rightMax + "\tBack: " + backMax); */ } }