private void ControllerReadingUpdate() { for (int i = 0; i < gamepads.Count; i++) { RawGameController gamepad = gamepads[i]; bool[] buttonArray = new bool[gamepad.ButtonCount]; GameControllerSwitchPosition[] switchArray = new GameControllerSwitchPosition[gamepad.SwitchCount]; double[] axisArray = new double[gamepad.AxisCount]; ulong timestamp = gamepad.GetCurrentReading(buttonArray, switchArray, axisArray); for (int j = 0; j < gamepad.AxisCount; j++) { AddOrUpdateValue($"HID/Gamepad/{i}/Axis/{j}", axisArray[j], true); } for (int j = 0; j < gamepad.ButtonCount; j++) { AddOrUpdateValue($"HID/Gamepad/{i}/Button/{j}", buttonArray[j], true); } for (int j = 0; j < gamepad.SwitchCount; j++) { AddOrUpdateValue($"HID/Gamepad/{i}/Switch/{j}", (int)switchArray[j], true); } //AddOrUpdateValue($"HID/Gamepad/{i}/Battery", (int)gamepad.TryGetBatteryReport().Status, true); } }
public RawGameControllerModel(RawGameController controller) { Axes = new double[controller.AxisCount]; Switches = new GameControllerSwitchPosition[controller.SwitchCount]; Buttons = new bool[controller.ButtonCount]; Controller = controller; }
/// <summary> /// ButtonBackPressed maps to the Share button on a Playstation controller, or Back button of a Xbox controller. /// </summary> /// <returns> /// ButtonBackPressed returns true if pressed, false otherwise; /// </returns> public bool ButtonBackPressed() { if (Controller == null) { return(false); } Boolean[] ButtonArray = new Boolean[20]; GameControllerSwitchPosition[] SwitchArray = new GameControllerSwitchPosition[20]; Double[] AxisArray = new Double[20]; Controller.GetCurrentReading(ButtonArray, SwitchArray, AxisArray); return(ButtonArray[8]); }
/// <summary> /// ThumbRightX maps to the position of the right thumbstick on the X-Axis for the controller. /// </summary> /// <returns> /// ThumbRightX returns a value between 0 and 100, where 50 lies on the origin of the X-Axis. /// </returns> public double ThumbRightX() { if (Controller == null) { return(50); } Boolean[] ButtonArray = new Boolean[20]; GameControllerSwitchPosition[] SwitchArray = new GameControllerSwitchPosition[20]; Double[] AxisArray = new Double[20]; Controller.GetCurrentReading(ButtonArray, SwitchArray, AxisArray); return(100 * AxisArray[2]); }