Skip to content

Commit

Permalink
add VPC-StarCitizen left and right sticks
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjarv committed Jun 19, 2018
1 parent 144282f commit f0e1c7a
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 1 deletion.
2 changes: 2 additions & 0 deletions JoystickProxyWin/Joystick Proxy/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@
06a3:053c = Saitek X45 HOTAS (053c)
06a3:0464 = Saitek Cyborg Evo
03eb:2043 = Virpil Mongoos T-50
03ef:2004 = VPC-Star-Citizen-L
03ec:2005 = VPC-Star-Citizen-R
8 changes: 8 additions & 0 deletions JoystickVisualizer/Assets/Devices/VPC-Star-Citizen.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,59 @@
using Assets;
using System.Collections.Generic;
using UnityEngine;

public class VPCStarCitizenL : MonoBehaviour {
public const string USB_ID = "03ef:2004";
//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));
}
}

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,59 @@
using Assets;
using System.Collections.Generic;
using UnityEngine;

public class VPCStarCitizenR : MonoBehaviour {
public const string USB_ID = "03ec:2005";
//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));
}
}

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.
Binary file modified JoystickVisualizer/ProjectSettings/ProjectSettings.asset
Binary file not shown.
2 changes: 1 addition & 1 deletion JoystickVisualizer/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
m_EditorVersion: 2018.1.4f1
m_EditorVersion: 2018.1.5f1

0 comments on commit f0e1c7a

Please sign in to comment.