diff --git a/JoystickProxy/JoystickProxy/Program.cs b/JoystickProxy/JoystickProxy/Program.cs index b190d05..a5bd70f 100644 --- a/JoystickProxy/JoystickProxy/Program.cs +++ b/JoystickProxy/JoystickProxy/Program.cs @@ -12,11 +12,14 @@ using IniParser; using IniParser.Model; using System.Collections.Concurrent; +using System.Diagnostics; namespace JoystickProxy { class Program { + private static int FPS = 30; + private static int FrameTime; private bool Debug = true; private static Dictionary SupportedDevices = new Dictionary(); private static Dictionary InstanceGuidToUsbIdLookup = new Dictionary(); @@ -30,6 +33,7 @@ static void Main(string[] args) host = IPAddress.Parse(data["Config"]["Host"]); port = Int32.Parse(data["Config"]["Port"]); + FrameTime = 1000 / Int32.Parse(data["Config"]["FPS"]); Console.WriteLine("JoystickProxy"); Console.WriteLine("============="); @@ -84,8 +88,10 @@ public Program() while (true) { - foreach(Joystick joystick in connectedJoysticks.Values) + Stopwatch sw = new Stopwatch(); + foreach (Joystick joystick in connectedJoysticks.Values) { + sw.Start(); try { joystick.Poll(); @@ -108,8 +114,12 @@ public Program() {} } - - Thread.Sleep(20); + sw.Stop(); + int sleepTime = FrameTime - (int)sw.ElapsedMilliseconds; + if (sleepTime > 0) + { + Thread.Sleep(sleepTime); + } } } catch (Exception e) diff --git a/JoystickProxy/JoystickProxy/settings.ini b/JoystickProxy/JoystickProxy/settings.ini index 316539e..7eb0ed2 100644 --- a/JoystickProxy/JoystickProxy/settings.ini +++ b/JoystickProxy/JoystickProxy/settings.ini @@ -1,12 +1,14 @@ [Config] Host = 127.0.0.1 Port = 11011 +FPS = 60 [Devices] 044f:0402 = Warthog Joystick 044f:0404 = Warthog Throttle 044f:b10a = T.16000M -# 06a3:0764 = Saitek Pro Combat Rudder +06a3:0763 = Saitek Rudder Pedals +06a3:0764 = Saitek Combat Rudder Pedals 068e:00f = CH Pro Pedals 231d:011f = VKB Gunfighter 046d:c215 = Logitech 3D Pro diff --git a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/BasicRudder.fbx b/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/BasicRudder.fbx deleted file mode 100644 index 1b92fdf..0000000 Binary files a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/BasicRudder.fbx and /dev/null differ diff --git a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Materials/Aluminium.mat b/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Materials/Aluminium.mat deleted file mode 100644 index 7f5e52c..0000000 Binary files a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Materials/Aluminium.mat and /dev/null differ diff --git a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Materials/Black Plastic.mat b/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Materials/Black Plastic.mat deleted file mode 100644 index 0a81215..0000000 Binary files a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Materials/Black Plastic.mat and /dev/null differ diff --git a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Saitek Combat Rudder Pedals.blend b/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Saitek Combat Rudder Pedals.blend new file mode 100644 index 0000000..1eef47a Binary files /dev/null and b/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Saitek Combat Rudder Pedals.blend differ diff --git a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/BasicRudder.fbx.meta b/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Saitek Combat Rudder Pedals.blend.meta similarity index 60% rename from JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/BasicRudder.fbx.meta rename to JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Saitek Combat Rudder Pedals.blend.meta index 3837013..9be3562 100644 --- a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/BasicRudder.fbx.meta +++ b/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Saitek Combat Rudder Pedals.blend.meta @@ -1,61 +1,47 @@ fileFormatVersion: 2 -guid: 83cbab5fb62585f4e99be2d242d25c96 -timeCreated: 1510347881 +guid: 919f1200ecdbf7c448a0881c7e3cdb69 +timeCreated: 1522163754 licenseType: Free ModelImporter: serializedVersion: 22 fileIDToRecycleName: - 100000: Base - 100002: Base.001 - 100004: //RootNode - 100006: Brake - 100008: Brake.001 - 100010: Left Pedal - 100012: Right Pedal - 400000: Base - 400002: Base.001 - 400004: //RootNode - 400006: Brake - 400008: Brake.001 - 400010: Left Pedal - 400012: Right Pedal - 2300000: Base - 2300002: Base.001 - 2300004: //RootNode - 2300006: Brake - 2300008: Brake.001 - 2300010: Left Pedal - 2300012: Right Pedal - 3300000: Base - 3300002: Base.001 - 3300004: //RootNode - 3300006: Brake - 3300008: Brake.001 - 3300010: Left Pedal - 3300012: Right Pedal - 4300000: Base Plate - 4300002: Left Pedal - 4300004: Base.001 - 4300006: Brake.001 - 4300008: Right Pedal - 4300010: Base - 4300012: Brake - externalObjects: - - first: - type: UnityEngine:Material - assembly: UnityEngine.CoreModule - name: Aluminium - second: {fileID: 2100000, guid: 740fbc9822e723f499b1ff61095845e7, type: 2} - - first: - type: UnityEngine:Material - assembly: UnityEngine.CoreModule - name: Black Plastic - second: {fileID: 2100000, guid: 2f41a312ce23f444393f69f320b11f0a, type: 2} + 100000: Left_Foot + 100002: LeftPedal + 100004: Right_Foot + 100006: RightPedal + 100008: //RootNode + 400000: Left_Foot + 400002: LeftPedal + 400004: Right_Foot + 400006: RightPedal + 400008: //RootNode + 2100000: Black + 2100002: Grey + 2100004: Material_001 + 2100006: unnamed + 2300000: Left_Foot + 2300002: LeftPedal + 2300004: Right_Foot + 2300006: RightPedal + 2300008: //RootNode + 3300000: Left_Foot + 3300002: LeftPedal + 3300004: Right_Foot + 3300006: RightPedal + 3300008: //RootNode + 4300000: Saitek_pedales + 4300002: LeftPedal + 4300004: Left_Foot + 4300006: RightPedal + 4300008: Right_Foot + 7400000: Default Take + 9500000: //RootNode + externalObjects: {} materials: importMaterials: 1 materialName: 0 materialSearch: 1 - materialLocation: 0 + materialLocation: 1 animations: legacyGenerateAnimations: 4 bakeSimulation: 0 @@ -93,6 +79,8 @@ ModelImporter: optimizeMeshForGPU: 1 keepQuads: 0 weldVertices: 1 + preserveHierarchy: 0 + indexFormat: 0 secondaryUVAngleDistortion: 8 secondaryUVAreaDistortion: 15.000001 secondaryUVHardAngle: 88 @@ -122,7 +110,7 @@ ModelImporter: hasExtraRoot: 0 skeletonHasParents: 1 lastHumanDescriptionAvatarSource: {instanceID: 0} - animationType: 0 + animationType: 2 humanoidOversampling: 1 additionalBone: 0 userData: diff --git a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Saitek Combat Rudder Pedals.blend1 b/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Saitek Combat Rudder Pedals.blend1 new file mode 100644 index 0000000..95d6815 Binary files /dev/null and b/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Saitek Combat Rudder Pedals.blend1 differ diff --git a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Materials/Aluminium.mat.meta b/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Saitek Combat Rudder Pedals.blend1.meta similarity index 50% rename from JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Materials/Aluminium.mat.meta rename to JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Saitek Combat Rudder Pedals.blend1.meta index 8c11bf8..491a2df 100644 --- a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Materials/Aluminium.mat.meta +++ b/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Saitek Combat Rudder Pedals.blend1.meta @@ -1,10 +1,9 @@ fileFormatVersion: 2 -guid: 740fbc9822e723f499b1ff61095845e7 -timeCreated: 1510347881 +guid: cf8ad5c71e89f314e8e78c1e49413749 +timeCreated: 1522163950 licenseType: Free -NativeFormatImporter: +DefaultImporter: externalObjects: {} - mainObjectFileID: 2100000 userData: assetBundleName: assetBundleVariant: diff --git a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/SaitekCombatRudder.cs b/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/SaitekCombatRudder.cs index 5856f4c..0c7473d 100644 --- a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/SaitekCombatRudder.cs +++ b/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/SaitekCombatRudder.cs @@ -43,16 +43,15 @@ void StickEvent(JoystickState state) Model.SetActive(entry.Value == 1); break; - case "RotationZ": // Pedal Position -0.05 0.05 - LeftPedal.transform.position = new Vector3(LeftPedal.transform.position.x, LeftPedal.transform.position.y, ConvertRange(entry.Value, 0, 65535, 3, -3)); - RightPedal.transform.position = new Vector3(RightPedal.transform.position.x, RightPedal.transform.position.y, ConvertRange(entry.Value, 0, 65535, -3, 3)); + case "RotationZ": + LeftPedal.transform.localPosition = new Vector3(LeftPedal.transform.localPosition.x, ConvertRange(entry.Value, 0, 65535, 2.4, -2.4), LeftPedal.transform.localPosition.z); + RightPedal.transform.localPosition = new Vector3(RightPedal.transform.localPosition.x, ConvertRange(entry.Value, 0, 65535, -2.4, 2.4), RightPedal.transform.localPosition.z); break; case "X": // Left brake - // Rotate Z between 0 and 20 - LeftPedalBrake.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 0, 20), 0, 0); + LeftPedalBrake.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 20, 0), 0, 0); break; case "Y": // Right brake - RightPedalBrake.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 0, 20), 0, 0); + RightPedalBrake.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 20, 0), 0, 0); break; } } diff --git a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Materials.meta b/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals.meta similarity index 70% rename from JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Materials.meta rename to JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals.meta index 2006e11..3abffbf 100644 --- a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Materials.meta +++ b/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: 07cfdfb047a38b144aa192d1f6ba93f0 +guid: 4e993e31f1c91ca4bbe951b7f2d93d55 folderAsset: yes -timeCreated: 1510347881 +timeCreated: 1522166653 licenseType: Free DefaultImporter: externalObjects: {} diff --git a/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals/Saitek Rudder Pedals.blend b/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals/Saitek Rudder Pedals.blend new file mode 100644 index 0000000..aa7501e Binary files /dev/null and b/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals/Saitek Rudder Pedals.blend differ diff --git a/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals/Saitek Rudder Pedals.blend.meta b/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals/Saitek Rudder Pedals.blend.meta new file mode 100644 index 0000000..a3504f1 --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals/Saitek Rudder Pedals.blend.meta @@ -0,0 +1,116 @@ +fileFormatVersion: 2 +guid: b0b9a5baecf25d54f91d204985018e60 +timeCreated: 1522166675 +licenseType: Free +ModelImporter: + serializedVersion: 22 + fileIDToRecycleName: + 100000: LeftFoot + 100002: LeftPedal + 100004: RightFoot + 100006: RightPedal + 100008: //RootNode + 400000: LeftFoot + 400002: LeftPedal + 400004: RightFoot + 400006: RightPedal + 400008: //RootNode + 2100000: Black + 2100002: Grey + 2300000: LeftFoot + 2300002: LeftPedal + 2300004: RightFoot + 2300006: RightPedal + 2300008: //RootNode + 3300000: LeftFoot + 3300002: LeftPedal + 3300004: RightFoot + 3300006: RightPedal + 3300008: //RootNode + 4300000: Saitek_pedales + 4300002: LeftPedal + 4300004: LeftFoot + 4300006: RightPedal + 4300008: RightFoot + 7400000: Default Take + 9500000: //RootNode + externalObjects: {} + materials: + importMaterials: 1 + materialName: 0 + materialSearch: 1 + materialLocation: 1 + animations: + legacyGenerateAnimations: 4 + bakeSimulation: 0 + resampleCurves: 1 + optimizeGameObjects: 0 + motionNodeName: + rigImportErrors: + rigImportWarnings: + animationImportErrors: + animationImportWarnings: + animationRetargetingWarnings: + animationDoRetargetingWarnings: 0 + importAnimatedCustomProperties: 0 + animationCompression: 1 + animationRotationError: 0.5 + animationPositionError: 0.5 + animationScaleError: 0.5 + animationWrapMode: 0 + extraExposedTransformPaths: [] + extraUserProperties: [] + clipAnimations: [] + isReadable: 1 + meshes: + lODScreenPercentages: [] + globalScale: 1 + meshCompression: 0 + addColliders: 0 + importVisibility: 1 + importBlendShapes: 1 + importCameras: 1 + importLights: 1 + swapUVChannels: 0 + generateSecondaryUV: 0 + useFileUnits: 1 + optimizeMeshForGPU: 1 + keepQuads: 0 + weldVertices: 1 + preserveHierarchy: 0 + indexFormat: 0 + secondaryUVAngleDistortion: 8 + secondaryUVAreaDistortion: 15.000001 + secondaryUVHardAngle: 88 + secondaryUVPackMargin: 4 + useFileScale: 1 + tangentSpace: + normalSmoothAngle: 60 + normalImportMode: 0 + tangentImportMode: 3 + normalCalculationMode: 4 + importAnimation: 1 + copyAvatar: 0 + humanDescription: + serializedVersion: 2 + human: [] + skeleton: [] + armTwist: 0.5 + foreArmTwist: 0.5 + upperLegTwist: 0.5 + legTwist: 0.5 + armStretch: 0.05 + legStretch: 0.05 + feetSpacing: 0 + rootMotionBoneName: + rootMotionBoneRotation: {x: 0, y: 0, z: 0, w: 1} + hasTranslationDoF: 0 + hasExtraRoot: 0 + skeletonHasParents: 1 + lastHumanDescriptionAvatarSource: {instanceID: 0} + animationType: 2 + humanoidOversampling: 1 + additionalBone: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals/Saitek Rudder Pedals.blend1 b/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals/Saitek Rudder Pedals.blend1 new file mode 100644 index 0000000..a05127c Binary files /dev/null and b/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals/Saitek Rudder Pedals.blend1 differ diff --git a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Materials/Black Plastic.mat.meta b/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals/Saitek Rudder Pedals.blend1.meta similarity index 50% rename from JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Materials/Black Plastic.mat.meta rename to JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals/Saitek Rudder Pedals.blend1.meta index 7d6e653..4236e52 100644 --- a/JoystickVisualizer/Assets/Devices/Saitek Combat Rudder/Materials/Black Plastic.mat.meta +++ b/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals/Saitek Rudder Pedals.blend1.meta @@ -1,10 +1,9 @@ fileFormatVersion: 2 -guid: 2f41a312ce23f444393f69f320b11f0a -timeCreated: 1510347881 +guid: 16a6857460b8c2642b5c95807835183d +timeCreated: 1522167261 licenseType: Free -NativeFormatImporter: +DefaultImporter: externalObjects: {} - mainObjectFileID: 2100000 userData: assetBundleName: assetBundleVariant: diff --git a/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals/SaitekRudderPedals.cs b/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals/SaitekRudderPedals.cs new file mode 100644 index 0000000..2ba4f0a --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals/SaitekRudderPedals.cs @@ -0,0 +1,70 @@ +using Assets; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class SaitekRudderPedals : MonoBehaviour { + public const string USB_ID = "06a3:0763"; + //public const string USB_ID = "06a3:0764"; + + public GameObject Model; + + public GameObject LeftPedal; + public GameObject RightPedal; + + public GameObject LeftPedalBrake; + public GameObject RightPedalBrake; + + // 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 "RotationZ": + LeftPedal.transform.localPosition = new Vector3(LeftPedal.transform.localPosition.x, ConvertRange(entry.Value, 0, 65535, 1.2, -1.2), LeftPedal.transform.localPosition.z); + RightPedal.transform.localPosition = new Vector3(RightPedal.transform.localPosition.x, ConvertRange(entry.Value, 0, 65535, -1.2, 1.2), RightPedal.transform.localPosition.z); + break; + case "X": // Left brake + LeftPedalBrake.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 0, -20), 0, 0); + break; + case "Y": // Right brake + RightPedalBrake.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 0, -20), 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 Rudder Pedals/SaitekRudderPedals.cs.meta b/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals/SaitekRudderPedals.cs.meta new file mode 100644 index 0000000..91b2243 --- /dev/null +++ b/JoystickVisualizer/Assets/Devices/Saitek Rudder Pedals/SaitekRudderPedals.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: b55e78f869a25064b8dd71dbb456b4fc +timeCreated: 1522166861 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/JoystickVisualizer/Assets/Devices/Saitek X52 Throttle/SaitekX52Throttle.cs b/JoystickVisualizer/Assets/Devices/Saitek X52 Throttle/SaitekX52Throttle.cs index 16ee49b..fd1383b 100644 --- a/JoystickVisualizer/Assets/Devices/Saitek X52 Throttle/SaitekX52Throttle.cs +++ b/JoystickVisualizer/Assets/Devices/Saitek X52 Throttle/SaitekX52Throttle.cs @@ -34,7 +34,7 @@ void StickEvent(JoystickState state) { case "Z": // Throttle Model.SetActive(true); - Throttle.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 30, -20), Throttle.transform.localEulerAngles.y, Throttle.transform.localEulerAngles.z); + Throttle.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, -30, 20), Throttle.transform.localEulerAngles.y, Throttle.transform.localEulerAngles.z); break; } } diff --git a/JoystickVisualizer/Assets/JoystickVisualizer.unity b/JoystickVisualizer/Assets/JoystickVisualizer.unity index 3c9c6eb..1540763 100644 Binary files a/JoystickVisualizer/Assets/JoystickVisualizer.unity and b/JoystickVisualizer/Assets/JoystickVisualizer.unity differ diff --git a/README.md b/README.md index 4d3bcb9..a3ed08c 100644 --- a/README.md +++ b/README.md @@ -73,9 +73,11 @@ The Visualizer was created in Unity3D, and the Proxy is a normal C# application * https://3dwarehouse.sketchup.com/model.html?id=1870c8e3d1267a38c023ee32d47e2fa9 -3D model of the Saitek X55 RHINO stick and throttle were made by By-Jokese +3D model by By-Jokese (https://byjokese.com) -* https://byjokese.com +* Saitek X55 RHINO stick and throttle +* Saitek Rudder Pedals +* Saitek Combat Rudder Pedals ## Contact