-
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
6 changed files
with
82 additions
and
1 deletion.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
JoystickVisualizer/Assets/Devices/Virpil Mongoos T-50/VirpilMongoosT50.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,59 @@ | ||
using Assets; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class VirpilMongoosT50 : MonoBehaviour { | ||
public const string USB_ID = "03eb:2043"; | ||
//public const string USB_ID = "044f:0402"; | ||
|
||
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, Joystick.transform.localEulerAngles.y, ConvertRange(entry.Value, 0, 65535, -20, 20)); | ||
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)); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
JoystickVisualizer/Assets/Devices/Virpil Mongoos T-50/VirpilMongoosT50.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.
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