Skip to content

Commit

Permalink
add support for Saitek X56 HOTAS
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjarv committed May 23, 2018
1 parent 2dccb4a commit e1b0362
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 2 deletions.
17 changes: 15 additions & 2 deletions JoystickProxyWin/Joystick Proxy/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ private void ScanJoysticks()
List<ControllerDevice> removedDevices = new List<ControllerDevice>();
List<ControllerDevice> addedDevices = new List<ControllerDevice>(); //_directInput.GetDevices().ToList().ConvertAll(device => new ControllerDevice(_directInput, device));

List<DeviceInstance> foundDeviceInstances = _directInput.GetDevices().ToList(); //.ToDictionary(d => d.InstanceGuid, d => d);
List<DeviceInstance> oldDeviceInstances = _devices.ToList().ConvertAll(d => d.DeviceInstance);
List<DeviceInstance> foundDeviceInstances = _directInput.GetDevices().ToList();

//List<DeviceInstance> removedDeviceInstances = oldDeviceInstances.Except(foundDeviceInstances).Where(d => !IsSupported(d)).ToList();

foreach(DeviceInstance deviceInstance in foundDeviceInstances)
{
Expand All @@ -106,7 +109,7 @@ private void ScanJoysticks()
addedDevices.Add(new ControllerDevice(_directInput, deviceInstance));
}
}

foreach(ControllerDevice device in _devices)
{
bool match = false;
Expand All @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions JoystickProxyWin/Joystick Proxy/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions JoystickVisualizer/Assets/Devices/Saitek X56 Stick.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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<string, int> 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));
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions JoystickVisualizer/Assets/Devices/Saitek X56 Throttle.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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<string, int> 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));
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified JoystickVisualizer/Assets/JoystickVisualizer.unity
Binary file not shown.

0 comments on commit e1b0362

Please sign in to comment.