Skip to content

Commit

Permalink
add t16000m throttle with warthog model
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjarv committed Apr 24, 2018
1 parent 6711c77 commit 807ca93
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 25 deletions.
2 changes: 1 addition & 1 deletion JoystickProxyWin/Joystick Proxy/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<value>127.0.0.1</value>
</setting>
<setting name="Port" serializeAs="String">
<value>11011</value>
<value>11028</value>
</setting>
</Joystick_Proxy.Properties.Settings>
</userSettings>
Expand Down

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
Expand Up @@ -6,7 +6,7 @@
<Value Profile="(Default)">127.0.0.1</Value>
</Setting>
<Setting Name="Port" Type="System.Int32" Scope="User">
<Value Profile="(Default)">11011</Value>
<Value Profile="(Default)">11028</Value>
</Setting>
</Settings>
</SettingsFile>
1 change: 1 addition & 0 deletions JoystickProxyWin/Joystick Proxy/settings.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[Devices]
044f:b10a = Thrustmaster T.16000M
044f:b687 = Thrustmaster T.16000M Throttle
044f:b678 = Thrustmaster T.Flight Rudder Car Mode
044f:b679 = Thrustmaster T.Flight Rudder
044f:0402 = Thrustmaster Warthog Joystick
Expand Down
8 changes: 8 additions & 0 deletions JoystickVisualizer/Assets/Devices/T-16000M 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,55 @@
using Assets;
using System.Collections.Generic;
using UnityEngine;

public class T16000MThrottle : MonoBehaviour {
public const string USB_ID = "044f:b687";
//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 "Z": // Throttle
LeftThrottle.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 28, -25), LeftThrottle.transform.localEulerAngles.y, LeftThrottle.transform.localEulerAngles.z);
RightThrottle.transform.localEulerAngles = LeftThrottle.transform.localEulerAngles;
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
Expand Up @@ -4,7 +4,8 @@

public class ThrustmasterTFlightRudder : MonoBehaviour {
public const string USB_ID = "044f:b679";
//public const string USB_ID = "06a3:0764";
public const string USB_ID_2 = "044f:b687";
//public const string USB_ID_2 = "044f:0404";

public GameObject Model;

Expand All @@ -29,33 +30,54 @@ void Update()

void StickEvent(JoystickState state)
{
if (state.UsbID != USB_ID)
{
if (state.UsbID != USB_ID && state.UsbID != USB_ID_2)
return;
}

Model.SetActive(true);

foreach (KeyValuePair<string, int> entry in state.Data)
{
switch (entry.Key)
if (state.UsbID == USB_ID)
{
case "Connected":
if (Model.activeInHierarchy)
Model.SetActive(entry.Value == 1);
break;
switch (entry.Key)
{
case "Connected":
if (Model.activeInHierarchy)
Model.SetActive(entry.Value == 1);
break;

case "Z":
LeftPedal.transform.localPosition = new Vector3(LeftPedal.transform.localPosition.x, ConvertRange(entry.Value, 0, 65535, 2.0, -1.2), LeftPedal.transform.localPosition.z);
RightPedal.transform.localPosition = new Vector3(RightPedal.transform.localPosition.x, ConvertRange(entry.Value, 0, 65535, -1.2, 2.0), RightPedal.transform.localPosition.z);
CenterIndicator.transform.localEulerAngles = new Vector3(0, 0, ConvertRange(entry.Value, 0, 65535, 30, -30));
break;
case "Y": // Left brake
LeftPedalBrake.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, -20, 0), 0, 0);
break;
case "X": // Right brake
RightPedalBrake.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, -20, 0), 0, 0);
break;
case "Z":
Model.SetActive(true);
LeftPedal.transform.localPosition = new Vector3(LeftPedal.transform.localPosition.x, ConvertRange(entry.Value, 0, 65535, 2.0, -1.2), LeftPedal.transform.localPosition.z);
RightPedal.transform.localPosition = new Vector3(RightPedal.transform.localPosition.x, ConvertRange(entry.Value, 0, 65535, -1.2, 2.0), RightPedal.transform.localPosition.z);
CenterIndicator.transform.localEulerAngles = new Vector3(0, 0, ConvertRange(entry.Value, 0, 65535, 30, -30));
break;
case "Y": // Left brake
Model.SetActive(true);
LeftPedalBrake.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, -20, 0), 0, 0);
break;
case "X": // Right brake
Model.SetActive(true);
RightPedalBrake.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, -20, 0), 0, 0);
break;
}
} else if (state.UsbID == USB_ID_2)
{
switch (entry.Key)
{
case "Sliders1":
Model.SetActive(true);
LeftPedal.transform.localPosition = new Vector3(LeftPedal.transform.localPosition.x, ConvertRange(entry.Value, 0, 65535, 2.0, -1.2), LeftPedal.transform.localPosition.z);
RightPedal.transform.localPosition = new Vector3(RightPedal.transform.localPosition.x, ConvertRange(entry.Value, 0, 65535, -1.2, 2.0), RightPedal.transform.localPosition.z);
CenterIndicator.transform.localEulerAngles = new Vector3(0, 0, ConvertRange(entry.Value, 0, 65535, 30, -30));
break;
case "RotationY": // Left brake
Model.SetActive(true);
LeftPedalBrake.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, -20, 0), 0, 0);
break;
case "RotationX": // Right brake
Model.SetActive(true);
RightPedalBrake.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, -20, 0), 0, 0);
break;
}
}
}
}
Expand Down
Binary file modified JoystickVisualizer/Assets/JoystickVisualizer.unity
Binary file not shown.

0 comments on commit 807ca93

Please sign in to comment.