Skip to content

Commit

Permalink
update model for x55 throttle and add model for x55 joystick
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjarv committed Mar 4, 2018
1 parent bf18f52 commit cdf11c1
Show file tree
Hide file tree
Showing 21 changed files with 437 additions and 155 deletions.
3 changes: 2 additions & 1 deletion JoystickProxy/JoystickProxy/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ Port = 11011
231d:011f = VKB Gunfighter
046d:c215 = Logitech 3D Pro
06a3:075c = Saitek X52 Throttle
0738:a215 = Saitek X55 Throttle
0738:a215 = Saitek X55 Throttle
0738:2215 = Saitek X55 Joystick
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class TMWarthogJoystick : MonoBehaviour {

public Boolean ButtonIndicator = false;

public GameObject Particles;
public GameObject IndicatorOn;
public GameObject IndicatorOff;

public GameObject Model;
public GameObject StickGimbal;
Expand Down Expand Up @@ -66,19 +67,19 @@ void StickEvent(JoystickState state)

case "Buttons10":
DMS.transform.localEulerAngles = new Vector3(((entry.Value == 0) ? 0.0f : 10.0f), DMS.transform.localEulerAngles.y, DMS.transform.localEulerAngles.z);
SpawnIndicator(DMS);
SpawnIndicator(DMS, entry.Value > 0);
break;
case "Buttons11":
DMS.transform.localEulerAngles = new Vector3(DMS.transform.localEulerAngles.x, ((entry.Value == 0) ? 0.0f : -10.0f), DMS.transform.localEulerAngles.z);
SpawnIndicator(DMS);
SpawnIndicator(DMS, entry.Value > 0);
break;
case "Buttons12":
DMS.transform.localEulerAngles = new Vector3(((entry.Value == 0) ? 0.0f : -10.0f), DMS.transform.localEulerAngles.y, DMS.transform.localEulerAngles.z);
SpawnIndicator(DMS);
SpawnIndicator(DMS, entry.Value > 0);
break;
case "Buttons13":
DMS.transform.localEulerAngles = new Vector3(DMS.transform.localEulerAngles.x, ((entry.Value == 0) ? 0.0f : 10.0f), DMS.transform.localEulerAngles.z);
SpawnIndicator(DMS);
SpawnIndicator(DMS, entry.Value > 0);
break;

case "Buttons14":
Expand Down Expand Up @@ -112,31 +113,31 @@ void StickEvent(JoystickState state)

case "Buttons1":
Pickle.transform.localPosition = new Vector3(Pickle.transform.localPosition.x, Pickle.transform.localPosition.y, ((entry.Value == 0) ? 0.0f : 0.25f));
SpawnIndicator(Pickle);
SpawnIndicator(Pickle, entry.Value > 0);
break;

case "Buttons4":
MasterMode.transform.localPosition = new Vector3(((entry.Value == 0) ? 0.0f : -0.20f), MasterMode.transform.localPosition.y, MasterMode.transform.localPosition.z);
SpawnIndicator(MasterMode);
SpawnIndicator(MasterMode, entry.Value > 0);
break;

case "Buttons2":
PinkyButton.transform.localPosition = new Vector3(PinkyButton.transform.localPosition.x, PinkyButton.transform.localPosition.y, ((entry.Value == 0) ? 0.0f : -0.20f));
SpawnIndicator(PinkyButton);
SpawnIndicator(PinkyButton, entry.Value > 0);
break;

case "Buttons3":
PinkyLever.transform.localEulerAngles = new Vector3(((entry.Value == 0) ? 0.0f : -10.0f), PinkyLever.transform.localEulerAngles.y, PinkyLever.transform.localEulerAngles.z);
SpawnIndicator(PinkyLever);
SpawnIndicator(PinkyLever, entry.Value > 0);
break;

case "Buttons0":
Trigger.transform.localEulerAngles = new Vector3(((entry.Value == 0) ? 0.0f : 10.0f), Trigger.transform.localEulerAngles.y, Trigger.transform.localEulerAngles.z);
SpawnIndicator(Trigger);
SpawnIndicator(Trigger, entry.Value > 0);
break;
case "Buttons5":
Trigger.transform.localEulerAngles = new Vector3(((entry.Value == 0) ? 10.0f : 20.0f), Trigger.transform.localEulerAngles.y, Trigger.transform.localEulerAngles.z);
SpawnIndicator(Trigger);
SpawnIndicator(Trigger, entry.Value > 0);
break;

case "PointOfViewControllers0":
Expand Down Expand Up @@ -175,11 +176,11 @@ void StickEvent(JoystickState state)
}
}

private void SpawnIndicator(GameObject gimbal)
private void SpawnIndicator(GameObject gimbal, bool on = true)
{
if (ButtonIndicator)
{
GameObject indicator = Instantiate(Particles, gimbal.transform) as GameObject;
GameObject indicator = on ? Instantiate(IndicatorOn, gimbal.transform) as GameObject : Instantiate(IndicatorOff, gimbal.transform) as GameObject;
Transform parent = gimbal.GetComponentInChildren<MeshFilter>().transform;
indicator.transform.position = parent.GetComponent<Renderer>().bounds.center;
indicator.SetActive(true);
Expand Down
10 changes: 10 additions & 0 deletions JoystickVisualizer/Assets/Devices/Saitek X55 Stick.meta

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

10 changes: 10 additions & 0 deletions JoystickVisualizer/Assets/Devices/Saitek X55 Stick/Materials.meta

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

Binary file not shown.

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

Binary file not shown.

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 SaitekX55Stick : MonoBehaviour {
public const string USB_ID = "0738:2215";
//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.

Binary file not shown.
145 changes: 145 additions & 0 deletions JoystickVisualizer/Assets/Devices/Saitek X55 Stick/x55-stick.fbx.meta

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.
Loading

0 comments on commit cdf11c1

Please sign in to comment.