Skip to content

Commit

Permalink
add saitek x45 with models from x52 throttle and warthog stick
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjarv committed Mar 27, 2018
1 parent 2f5ff90 commit 65e0f5f
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 0 deletions.
1 change: 1 addition & 0 deletions JoystickProxy/JoystickProxy/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ FPS = 60
0738:a215 = Saitek X55 Throttle
0738:2215 = Saitek X55 Joystick
06a3:0c2d = Saitek Pro Flight Throttle Quadrant
06a3:2541 = Saitek X45 HOTAS
10 changes: 10 additions & 0 deletions JoystickVisualizer/Assets/Devices/Saitek X45 HOTAS.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,56 @@
using Assets;
using System.Collections.Generic;
using UnityEngine;

public class SaitekX45Joystick : MonoBehaviour {
public const string USB_ID = "06a3:2541";
//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<string, int> entry in state.Data)
{
switch (entry.Key)
{
case "X":
Joystick.transform.eulerAngles = new Vector3(Joystick.transform.eulerAngles.x, Joystick.transform.eulerAngles.y, ConvertRange(entry.Value, 0, 65535, 20, -20));
break;
case "Y":
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));
}

}

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,53 @@
using Assets;
using System.Collections.Generic;
using UnityEngine;

public class SaitekX45Throttle : MonoBehaviour {
public const string USB_ID = "06a3:2541";
//public const string USB_ID = "044f:0404";

public GameObject Model;

public GameObject Throttle;

// 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 "Sliders0": // Throttle
Throttle.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, -25, 28), Throttle.transform.localEulerAngles.y, Throttle.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.

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

0 comments on commit 65e0f5f

Please sign in to comment.