diff --git a/JoystickProxyWin/Joystick Proxy/settings.ini b/JoystickProxyWin/Joystick Proxy/settings.ini index 8797afc..2c2cda5 100644 --- a/JoystickProxyWin/Joystick Proxy/settings.ini +++ b/JoystickProxyWin/Joystick Proxy/settings.ini @@ -25,3 +25,5 @@ 06a3:053c = Saitek X45 HOTAS (053c) 06a3:0464 = Saitek Cyborg Evo 03eb:2043 = Virpil Mongoos T-50 +03ef:2004 = VPC-Star-Citizen-L +03ec:2005 = VPC-Star-Citizen-R diff --git a/JoystickVisualizer/Assets/Devices/VPC-Star-Citizen.meta b/JoystickVisualizer/Assets/Devices/VPC-Star-Citizen.meta new file mode 100644 index 0000000..e9f4b36 --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/VPC-Star-Citizen.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8965ad1ed9b5867409baa27c7baed4d6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/JoystickVisualizer/Assets/Devices/VPC-Star-Citizen/VPCStarCitizenL.cs b/JoystickVisualizer/Assets/Devices/VPC-Star-Citizen/VPCStarCitizenL.cs new file mode 100644 index 0000000..a3f8419 --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/VPC-Star-Citizen/VPCStarCitizenL.cs @@ -0,0 +1,59 @@ +using Assets; +using System.Collections.Generic; +using UnityEngine; + +public class VPCStarCitizenL : MonoBehaviour { + public const string USB_ID = "03ef:2004"; + //public const string USB_ID = "044f:0402"; + + public GameObject Model; + public GameObject Joystick; + + // Use this for initialization + void Start() + { + UDPListener.StickEventListener += StickEvent; + } + + // Update is called once per frame + void Update() + { + } + + void StickEvent(JoystickState state) + { + if (state.UsbID != USB_ID) + { + return; + } + + Model.SetActive(true); + + foreach (KeyValuePair entry in state.Data) + { + switch (entry.Key) + { + case "Connected": + if (Model.activeInHierarchy) + Model.SetActive(entry.Value == 1); + break; + + case "X": + Joystick.transform.localEulerAngles = new Vector3(Joystick.transform.localEulerAngles.x, Joystick.transform.localEulerAngles.y, ConvertRange(entry.Value, 0, 65535, -20, 20)); + break; + case "Y": + Joystick.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, -20, 20), Joystick.transform.localEulerAngles.y, Joystick.transform.localEulerAngles.z); + break; + } + } + } + + public static float ConvertRange( + double value, // value to convert + double originalStart, double originalEnd, // original range + double newStart, double newEnd) // desired range + { + double scale = (double)(newEnd - newStart) / (originalEnd - originalStart); + return (float)(newStart + ((value - originalStart) * scale)); + } +} diff --git a/JoystickVisualizer/Assets/Devices/VPC-Star-Citizen/VPCStarCitizenL.cs.meta b/JoystickVisualizer/Assets/Devices/VPC-Star-Citizen/VPCStarCitizenL.cs.meta new file mode 100644 index 0000000..5485c31 --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/VPC-Star-Citizen/VPCStarCitizenL.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 34b3b13ffe8787543aee2bdd0e1df6a5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/JoystickVisualizer/Assets/Devices/VPC-Star-Citizen/VPCStarCitizenR.cs b/JoystickVisualizer/Assets/Devices/VPC-Star-Citizen/VPCStarCitizenR.cs new file mode 100644 index 0000000..5e29092 --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/VPC-Star-Citizen/VPCStarCitizenR.cs @@ -0,0 +1,59 @@ +using Assets; +using System.Collections.Generic; +using UnityEngine; + +public class VPCStarCitizenR : MonoBehaviour { + public const string USB_ID = "03ec:2005"; + //public const string USB_ID = "044f:0402"; + + public GameObject Model; + public GameObject Joystick; + + // Use this for initialization + void Start() + { + UDPListener.StickEventListener += StickEvent; + } + + // Update is called once per frame + void Update() + { + } + + void StickEvent(JoystickState state) + { + if (state.UsbID != USB_ID) + { + return; + } + + Model.SetActive(true); + + foreach (KeyValuePair entry in state.Data) + { + switch (entry.Key) + { + case "Connected": + if (Model.activeInHierarchy) + Model.SetActive(entry.Value == 1); + break; + + case "X": + Joystick.transform.localEulerAngles = new Vector3(Joystick.transform.localEulerAngles.x, Joystick.transform.localEulerAngles.y, ConvertRange(entry.Value, 0, 65535, -20, 20)); + break; + case "Y": + Joystick.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, -20, 20), Joystick.transform.localEulerAngles.y, Joystick.transform.localEulerAngles.z); + break; + } + } + } + + public static float ConvertRange( + double value, // value to convert + double originalStart, double originalEnd, // original range + double newStart, double newEnd) // desired range + { + double scale = (double)(newEnd - newStart) / (originalEnd - originalStart); + return (float)(newStart + ((value - originalStart) * scale)); + } +} diff --git a/JoystickVisualizer/Assets/Devices/VPC-Star-Citizen/VPCStarCitizenR.cs.meta b/JoystickVisualizer/Assets/Devices/VPC-Star-Citizen/VPCStarCitizenR.cs.meta new file mode 100644 index 0000000..95d9be5 --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/VPC-Star-Citizen/VPCStarCitizenR.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9eb79b5cb75dedc4a843f01c2c8a6c2b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/JoystickVisualizer/Assets/JoystickVisualizer.unity b/JoystickVisualizer/Assets/JoystickVisualizer.unity index 7555a99..6bb838d 100644 Binary files a/JoystickVisualizer/Assets/JoystickVisualizer.unity and b/JoystickVisualizer/Assets/JoystickVisualizer.unity differ diff --git a/JoystickVisualizer/ProjectSettings/ProjectSettings.asset b/JoystickVisualizer/ProjectSettings/ProjectSettings.asset index 7fdaa0a..e8df6b3 100644 Binary files a/JoystickVisualizer/ProjectSettings/ProjectSettings.asset and b/JoystickVisualizer/ProjectSettings/ProjectSettings.asset differ diff --git a/JoystickVisualizer/ProjectSettings/ProjectVersion.txt b/JoystickVisualizer/ProjectSettings/ProjectVersion.txt index 0379f15..454c57f 100644 --- a/JoystickVisualizer/ProjectSettings/ProjectVersion.txt +++ b/JoystickVisualizer/ProjectSettings/ProjectVersion.txt @@ -1 +1 @@ -m_EditorVersion: 2018.1.4f1 +m_EditorVersion: 2018.1.5f1