-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
250 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
JoystickVisualizer/Assets/Devices/Saitek X56 Stick/SaitekX56Stick.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 SaitekX56Stick : MonoBehaviour { | ||
public const string USB_ID = "0738:2221"; | ||
//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)); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
JoystickVisualizer/Assets/Devices/Saitek X56 Stick/SaitekX56Stick.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
133 changes: 133 additions & 0 deletions
133
JoystickVisualizer/Assets/Devices/Saitek X56 Throttle/SaitekX56Throttle.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
using Assets; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class SaitekX56Throttle : MonoBehaviour { | ||
public const string USB_ID = "0738:a221"; | ||
//public const string USB_ID = "044f:0404"; | ||
|
||
public GameObject Model; | ||
|
||
public GameObject LeftThrottle; | ||
public GameObject RightThrottle; | ||
|
||
public GameObject SW1_SW2; | ||
public GameObject SW3_SW4; | ||
public GameObject SW5_SW6; | ||
|
||
public GameObject RTY3; | ||
public GameObject RTY4; | ||
|
||
public GameObject TGL1; | ||
public GameObject TGL2; | ||
public GameObject TGL3; | ||
public GameObject TGL4; | ||
|
||
// 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": // Left brake | ||
// Rotate Z between 0 and 20 | ||
LeftThrottle.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 40, 0), 0, 0); | ||
break; | ||
case "Y": | ||
RightThrottle.transform.localEulerAngles = new Vector3(ConvertRange(entry.Value, 0, 65535, 40, 0), 0, 0); | ||
break; | ||
|
||
case "RotationY": | ||
RTY3.transform.localEulerAngles = new Vector3(0, 0, ConvertRange(entry.Value, 0, 65535, -150, 150)); | ||
break; | ||
|
||
case "RotationZ": | ||
RTY4.transform.localEulerAngles = new Vector3(0, 0, ConvertRange(entry.Value, 0, 65535, -150, 150)); | ||
break; | ||
|
||
case "Buttons5": | ||
SW1_SW2.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : 30, 0, 0); | ||
break; | ||
case "Buttons6": | ||
SW1_SW2.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : -30, 0, 0); | ||
break; | ||
|
||
case "Buttons7": | ||
SW3_SW4.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : 30, 0, 0); | ||
break; | ||
case "Buttons8": | ||
SW3_SW4.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : -30, 0, 0); | ||
break; | ||
|
||
case "Buttons9": | ||
SW5_SW6.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : 30, 0, 0); | ||
break; | ||
case "Buttons10": | ||
SW5_SW6.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : -30, 0, 0); | ||
break; | ||
|
||
case "Buttons11": | ||
TGL1.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : 30, 0, 0); | ||
break; | ||
case "Buttons12": | ||
TGL1.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : -30, 0, 0); | ||
break; | ||
|
||
case "Buttons13": | ||
TGL2.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : 30, 0, 0); | ||
break; | ||
case "Buttons14": | ||
TGL2.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : -30, 0, 0); | ||
break; | ||
|
||
case "Buttons15": | ||
TGL3.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : 30, 0, 0); | ||
break; | ||
case "Buttons16": | ||
TGL3.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : -30, 0, 0); | ||
break; | ||
|
||
case "Buttons17": | ||
TGL4.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : 30, 0, 0); | ||
break; | ||
case "Buttons18": | ||
TGL4.transform.localEulerAngles = new Vector3(entry.Value == 0 ? 0 : -30, 0, 0); | ||
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)); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
JoystickVisualizer/Assets/Devices/Saitek X56 Throttle/SaitekX56Throttle.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.