diff --git a/JoystickProxyWin/Joystick Proxy/Form1.cs b/JoystickProxyWin/Joystick Proxy/Form1.cs index 4a24ace..2d803e8 100644 --- a/JoystickProxyWin/Joystick Proxy/Form1.cs +++ b/JoystickProxyWin/Joystick Proxy/Form1.cs @@ -96,7 +96,10 @@ private void ScanJoysticks() List removedDevices = new List(); List addedDevices = new List(); //_directInput.GetDevices().ToList().ConvertAll(device => new ControllerDevice(_directInput, device)); - List foundDeviceInstances = _directInput.GetDevices().ToList(); //.ToDictionary(d => d.InstanceGuid, d => d); + List oldDeviceInstances = _devices.ToList().ConvertAll(d => d.DeviceInstance); + List foundDeviceInstances = _directInput.GetDevices().ToList(); + + //List removedDeviceInstances = oldDeviceInstances.Except(foundDeviceInstances).Where(d => !IsSupported(d)).ToList(); foreach(DeviceInstance deviceInstance in foundDeviceInstances) { @@ -106,7 +109,7 @@ private void ScanJoysticks() addedDevices.Add(new ControllerDevice(_directInput, deviceInstance)); } } - + foreach(ControllerDevice device in _devices) { bool match = false; @@ -132,6 +135,16 @@ private void ScanJoysticks() } } + private bool IsSupported(DeviceInstance deviceInstance) + { + return IsSupported(ControllerDevice.ProductGuidToUSBID(deviceInstance.ProductGuid)); + } + + private bool IsSupported(string usbId) + { + return SupportedDevices.ContainsKey(usbId); + } + private void AddDevice(ControllerDevice addedDevice) { if (SupportedDevices.ContainsKey(addedDevice.UsbId)) diff --git a/JoystickProxyWin/Joystick Proxy/settings.ini b/JoystickProxyWin/Joystick Proxy/settings.ini index b98a9b0..69cfb3c 100644 --- a/JoystickProxyWin/Joystick Proxy/settings.ini +++ b/JoystickProxyWin/Joystick Proxy/settings.ini @@ -18,6 +18,8 @@ 06a3:0762 = Saitek X52 Pro HOTAS 0738:a215 = Saitek X55 Throttle 0738:2215 = Saitek X55 Joystick +0738:a221 = Saitek X56 Throttle +0738:2221 = Saitek X56 Joystick 06a3:0c2d = Saitek Pro Flight Throttle Quadrant 06a3:2541 = Saitek X45 HOTAS (2541) 06a3:053c = Saitek X45 HOTAS (053c) diff --git a/JoystickVisualizer/Assets/Devices/Saitek X56 Stick.meta b/JoystickVisualizer/Assets/Devices/Saitek X56 Stick.meta new file mode 100644 index 0000000..133eb95 --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/Saitek X56 Stick.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5b389d58a20549840a019bd19eb522c0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/JoystickVisualizer/Assets/Devices/Saitek X56 Stick/SaitekX56Stick.cs b/JoystickVisualizer/Assets/Devices/Saitek X56 Stick/SaitekX56Stick.cs new file mode 100644 index 0000000..a2a7580 --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/Saitek X56 Stick/SaitekX56Stick.cs @@ -0,0 +1,62 @@ +using Assets; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class SaitekX56Stick : MonoBehaviour { + public const string USB_ID = "0738:2221"; + //public const string USB_ID = "044f:0402"; + + public GameObject Model; + + public GameObject StickGimbal; + + // 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": + StickGimbal.transform.localEulerAngles = new Vector3(StickGimbal.transform.localEulerAngles.x, ConvertRange(entry.Value, 0, 65535, 25, -25), StickGimbal.transform.localEulerAngles.z); + break; + case "Y": + StickGimbal.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, -25, 25), StickGimbal.transform.localEulerAngles.y, StickGimbal.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/Saitek X56 Stick/SaitekX56Stick.cs.meta b/JoystickVisualizer/Assets/Devices/Saitek X56 Stick/SaitekX56Stick.cs.meta new file mode 100644 index 0000000..474ea0f --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/Saitek X56 Stick/SaitekX56Stick.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0bce42bc9f7cd834f945e9648395433f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/JoystickVisualizer/Assets/Devices/Saitek X56 Throttle.meta b/JoystickVisualizer/Assets/Devices/Saitek X56 Throttle.meta new file mode 100644 index 0000000..89f1d56 --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/Saitek X56 Throttle.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 27d1b9623f2d481488fcf88411056d11 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/JoystickVisualizer/Assets/Devices/Saitek X56 Throttle/SaitekX56Throttle.cs b/JoystickVisualizer/Assets/Devices/Saitek X56 Throttle/SaitekX56Throttle.cs new file mode 100644 index 0000000..b61c9d7 --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/Saitek X56 Throttle/SaitekX56Throttle.cs @@ -0,0 +1,133 @@ +using Assets; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class SaitekX56Throttle : MonoBehaviour { + public const string USB_ID = "0738:a221"; + //public const string USB_ID = "044f:0404"; + + public GameObject Model; + + public GameObject LeftThrottle; + public GameObject RightThrottle; + + public GameObject SW1_SW2; + public GameObject SW3_SW4; + public GameObject SW5_SW6; + + public GameObject RTY3; + public GameObject RTY4; + + public GameObject TGL1; + public GameObject TGL2; + public GameObject TGL3; + public GameObject TGL4; + + // 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": // Left brake + // Rotate Z between 0 and 20 + LeftThrottle.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 40, 0), 0, 0); + break; + case "Y": + RightThrottle.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 40, 0), 0, 0); + break; + + case "RotationY": + RTY3.transform.localEulerAngles = new Vector3(0, 0, ConvertRange(entry.Value, 0, 65535, -150, 150)); + break; + + case "RotationZ": + RTY4.transform.localEulerAngles = new Vector3(0, 0, ConvertRange(entry.Value, 0, 65535, -150, 150)); + break; + + case "Buttons5": + SW1_SW2.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : 30, 0, 0); + break; + case "Buttons6": + SW1_SW2.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : -30, 0, 0); + break; + + case "Buttons7": + SW3_SW4.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : 30, 0, 0); + break; + case "Buttons8": + SW3_SW4.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : -30, 0, 0); + break; + + case "Buttons9": + SW5_SW6.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : 30, 0, 0); + break; + case "Buttons10": + SW5_SW6.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : -30, 0, 0); + break; + + case "Buttons11": + TGL1.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : 30, 0, 0); + break; + case "Buttons12": + TGL1.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : -30, 0, 0); + break; + + case "Buttons13": + TGL2.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : 30, 0, 0); + break; + case "Buttons14": + TGL2.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : -30, 0, 0); + break; + + case "Buttons15": + TGL3.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : 30, 0, 0); + break; + case "Buttons16": + TGL3.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : -30, 0, 0); + break; + + case "Buttons17": + TGL4.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : 30, 0, 0); + break; + case "Buttons18": + TGL4.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : -30, 0, 0); + 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 X56 Throttle/SaitekX56Throttle.cs.meta b/JoystickVisualizer/Assets/Devices/Saitek X56 Throttle/SaitekX56Throttle.cs.meta new file mode 100644 index 0000000..ef4cb9e --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/Saitek X56 Throttle/SaitekX56Throttle.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c810a9b6c68387048aab4b269599657f +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 ff75555..dfbec06 100644 Binary files a/JoystickVisualizer/Assets/JoystickVisualizer.unity and b/JoystickVisualizer/Assets/JoystickVisualizer.unity differ