diff --git a/JoystickProxy/JoystickProxy/settings.ini b/JoystickProxy/JoystickProxy/settings.ini index 98f8c7a..316539e 100644 --- a/JoystickProxy/JoystickProxy/settings.ini +++ b/JoystickProxy/JoystickProxy/settings.ini @@ -11,6 +11,7 @@ Port = 11011 231d:011f = VKB Gunfighter 046d:c215 = Logitech 3D Pro 06a3:075c = Saitek X52 HOTAS +06a3:0762 = Saitek X52 Pro HOTAS 0738:a215 = Saitek X55 Throttle 0738:2215 = Saitek X55 Joystick 06a3:0c2d = Saitek Pro Flight Throttle Quadrant diff --git a/JoystickVisualizer/Assets/Devices/Saitek X52 Pro Joystick.meta b/JoystickVisualizer/Assets/Devices/Saitek X52 Pro Joystick.meta new file mode 100644 index 0000000..a0ba72b --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/Saitek X52 Pro Joystick.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 8af6fcdf308d64d4faf3c5b98e665568 +folderAsset: yes +timeCreated: 1520968947 +licenseType: Free +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/JoystickVisualizer/Assets/Devices/Saitek X52 Pro Joystick/SaitekX52ProJoystick.cs b/JoystickVisualizer/Assets/Devices/Saitek X52 Pro Joystick/SaitekX52ProJoystick.cs new file mode 100644 index 0000000..26ae436 --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/Saitek X52 Pro Joystick/SaitekX52ProJoystick.cs @@ -0,0 +1,53 @@ +using Assets; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class SaitekX52ProJoystick : MonoBehaviour { + public const string USB_ID = "06a3:0762"; + 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; + } + + foreach (KeyValuePair entry in state.Data) + { + switch (entry.Key) + { + case "X": + Model.SetActive(true); + Joystick.transform.eulerAngles = new Vector3(Joystick.transform.eulerAngles.x, Joystick.transform.eulerAngles.y, ConvertRange(entry.Value, 0, 65535, 20, -20)); + break; + case "Y": + Model.SetActive(true); + Joystick.transform.eulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 20, -20), Joystick.transform.eulerAngles.y, Joystick.transform.eulerAngles.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/Saitek X52 Pro Joystick/SaitekX52ProJoystick.cs.meta b/JoystickVisualizer/Assets/Devices/Saitek X52 Pro Joystick/SaitekX52ProJoystick.cs.meta new file mode 100644 index 0000000..7e9b630 --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/Saitek X52 Pro Joystick/SaitekX52ProJoystick.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 38dfca6a1b48a304586b28d4e7f92269 +timeCreated: 1520968948 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/JoystickVisualizer/Assets/Devices/Saitek X52 Pro Throttle/SaitekX52ProThrottle.cs b/JoystickVisualizer/Assets/Devices/Saitek X52 Pro Throttle/SaitekX52ProThrottle.cs new file mode 100644 index 0000000..f6b83cc --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/Saitek X52 Pro Throttle/SaitekX52ProThrottle.cs @@ -0,0 +1,56 @@ +using Assets; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class SaitekX52ProThrottle : MonoBehaviour { + public const string USB_ID = "06a3:0762"; + private const float FLIP_SWITCH_ROTATION = 20.0f; + public GameObject Model; + + public GameObject GimbalLeft; + public GameObject GimbalRight; + + // 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; + } + + foreach (KeyValuePair entry in state.Data) + { + switch (entry.Key) + { + case "Z": // Throttle + Model.SetActive(true); + + // Rotate X between -30 and 30 + GimbalLeft.transform.eulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 40, -25), GimbalLeft.transform.eulerAngles.y, GimbalLeft.transform.eulerAngles.z); + GimbalRight.transform.eulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 40, -25), GimbalRight.transform.eulerAngles.y, GimbalRight.transform.eulerAngles.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/Saitek X52 Pro Throttle/SaitekX52ProThrottle.cs.meta b/JoystickVisualizer/Assets/Devices/Saitek X52 Pro Throttle/SaitekX52ProThrottle.cs.meta new file mode 100644 index 0000000..97c4ed8 --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/Saitek X52 Pro Throttle/SaitekX52ProThrottle.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 04821ce75d0909f4cb9b9f757542abb1 +timeCreated: 1520969022 +licenseType: Free +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 a448c1e..7916156 100644 Binary files a/JoystickVisualizer/Assets/JoystickVisualizer.unity and b/JoystickVisualizer/Assets/JoystickVisualizer.unity differ