Skip to content

Commit

Permalink
add x52 pro hotas
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjarv committed Mar 13, 2018
1 parent b74280e commit dbd81d3
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 @@ -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
10 changes: 10 additions & 0 deletions JoystickVisualizer/Assets/Devices/Saitek X52 Pro Joystick.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,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<string, int> 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));
}
}

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;
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<string, int> 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));
}

}

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 dbd81d3

Please sign in to comment.