Skip to content

Commit

Permalink
add X52 throttle model
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjarv committed Mar 26, 2018
1 parent 0722cf0 commit bd31806
Show file tree
Hide file tree
Showing 26 changed files with 393 additions and 8 deletions.
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.

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.

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

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using Assets;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SaitekX52Throttle : MonoBehaviour {
public const string USB_ID = "06a3:075c";
private const float FLIP_SWITCH_ROTATION = 20.0f;
//public const string USB_ID = "044f:0404";

public GameObject Model;

public GameObject GimbalLeft;
public GameObject GimbalRight;
public GameObject Throttle;

// Use this for initialization
void Start()
Expand All @@ -35,10 +34,7 @@ void StickEvent(JoystickState state)
{
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);
Throttle.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 30, -20), Throttle.transform.localEulerAngles.y, Throttle.transform.localEulerAngles.z);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Assets;
using System.Collections.Generic;
using UnityEngine;

public class JoystickThrustmasterWarthog : MonoBehaviour {
public const string USB_ID = "044f:0402";
//public const string USB_ID = "044f:0404";

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 "Connected":
if (Model.activeInHierarchy)
Model.SetActive(entry.Value == 1);
break;

case "X":
Joystick.transform.localEulerAngles = new Vector3(Joystick.transform.localEulerAngles.x, ConvertRange(entry.Value, 0, 65535, -20, 20), Joystick.transform.localEulerAngles.z);
break;
case "Y":
Joystick.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, -20, 20), Joystick.transform.localEulerAngles.y, Joystick.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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Assets;
using System.Collections.Generic;
using UnityEngine;

public class ThrottleThrustmasterWarthog : MonoBehaviour {
public const string USB_ID = "044f:0404";

public GameObject Model;
public GameObject LeftThrottle;
public GameObject RightThrottle;

// 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 "RotationZ": // Left Throttle
// Rotate Z between -30 and 30
LeftThrottle.transform.eulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 40, -25), LeftThrottle.transform.eulerAngles.y, LeftThrottle.transform.eulerAngles.z);
break;

case "Z": // Right Throttle
// Rotate X between -30 and 30
RightThrottle.transform.eulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 40, -25), RightThrottle.transform.eulerAngles.y, RightThrottle.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.
10 changes: 10 additions & 0 deletions JoystickVisualizer/Assets/SplitView.meta

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

18 changes: 18 additions & 0 deletions JoystickVisualizer/Assets/SplitView/MouseRotate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MouseRotate : MonoBehaviour {

float rotSpeed = 20;

void Start()
{
Debug.Log("Mouse Rotate " + gameObject.name);
}

void OnMouseDrag()
{
Debug.Log("Dragged " + gameObject.name);
}
}
13 changes: 13 additions & 0 deletions JoystickVisualizer/Assets/SplitView/MouseRotate.cs.meta

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

Binary file not shown.
9 changes: 9 additions & 0 deletions JoystickVisualizer/Assets/SplitView/SplitView.unity.meta

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

Loading

0 comments on commit bd31806

Please sign in to comment.