Skip to content

Commit

Permalink
Bug Fixes, Rework Wiimote Plus Demo
Browse files Browse the repository at this point in the history
- Fixed a bug where the Wii U Pro controller was not being identified correctly
- Redid the visuals of the Wii Motion Plus demo
- Disabled Classic Controller Pro (as it apparently uses a different protocol than the traditional classic controller)
  • Loading branch information
Flafla2 committed Aug 26, 2015
1 parent 8f364f4 commit 75ddce2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
5 changes: 3 additions & 2 deletions Assets/Scripts/WiimoteDemo.cs
Expand Up @@ -182,7 +182,7 @@ void OnGUI()
GUILayout.Label("Stick: " + data.stick[0] + ", " + data.stick[1]);
GUILayout.Label("C: " + data.c);
GUILayout.Label("Z: " + data.z);
} else if (wiimote.current_ext == ExtensionController.CLASSIC || wiimote.current_ext == ExtensionController.CLASSIC_PRO) {
} else if (wiimote.current_ext == ExtensionController.CLASSIC) {
GUILayout.Label("Classic Controller:", bold);
ClassicControllerData data = wiimote.ClassicController;
GUILayout.Label("Stick Left: " + data.lstick[0] + ", " + data.lstick[1]);
Expand Down Expand Up @@ -218,7 +218,8 @@ void OnGUI()
if (GUILayout.Button("Zero Out WMP"))
{
data.SetZeroValues();
model.rot.localRotation = Quaternion.LookRotation(Vector3.right, GetAccelVector());
model.rot.rotation = Quaternion.FromToRotation(model.rot.rotation*GetAccelVector(), Vector3.up) * model.rot.rotation;
model.rot.rotation = Quaternion.FromToRotation(model.rot.forward, Vector3.forward) * model.rot.rotation;
}
if(GUILayout.Button("Reset Offset"))
wmpOffset = Vector3.zero;
Expand Down
10 changes: 1 addition & 9 deletions Assets/Wiimote/Scripts/Wiimote.cs
Expand Up @@ -130,12 +130,6 @@ public Wiimote(IntPtr hidapi_handle, string hidapi_path, WiimoteType Type)
_Status = new StatusData(this);
_Extension = null;

Debug.Log(Type.ToString());
if(Type == WiimoteType.PROCONTROLLER) {
_current_ext = ExtensionController.CLASSIC;
_Extension = new ClassicControllerData(this);
}

RequestIdentifyWiiMotionPlus(); // why not?
}

Expand Down Expand Up @@ -207,8 +201,7 @@ private void RespondIdentifyExtension(byte[] data)
else if (val == ID_ClassicPro)
{
_current_ext = ExtensionController.CLASSIC_PRO;
if (_Extension == null || _Extension.GetType() != typeof(ClassicControllerData))
_Extension = new ClassicControllerData(this);
_Extension = null;
}
else if (val == ID_Nunchuck)
{
Expand All @@ -231,7 +224,6 @@ private void RespondIdentifyExtension(byte[] data)
}
else
{
Debug.Log(val.ToString("X12"));
_current_ext = ExtensionController.NONE;
_Extension = null;
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Wiimote/Scripts/WiimoteData/MotionPlusData.cs
Expand Up @@ -69,7 +69,7 @@ public class MotionPlusData : WiimoteData
// any better in the future. Realistically this value is the result of the Analog/Digital converter
// in the Wii Motion Plus along with the analog output of the gyros, but the documentation is so
// shitty that I don't even care anymore.
private const float MagicCalibrationConstant = 0.03076f;
private const float MagicCalibrationConstant = 0.0326173f;

public MotionPlusData(Wiimote Owner) : base(Owner) { }

Expand Down
17 changes: 9 additions & 8 deletions Assets/Wiimote/Scripts/WiimoteManager.cs
Expand Up @@ -10,10 +10,8 @@ namespace WiimoteApi {
public class WiimoteManager
{
public const ushort vendor_id_wiimote = 0x057e;
public const ushort vendor_id_procontroller = 0x0b6a;
public const ushort product_id_wiimote = 0x0306;
public const ushort product_id_wiimoteplus = 0x0330;
public const ushort product_id_procontroller = 0xa132;

/// A list of all currently connected Wii Remotes.
public static List<Wiimote> Wiimotes { get { return _Wiimotes; } }
Expand All @@ -39,7 +37,6 @@ public static bool FindWiimotes()
{
bool ret = _FindWiimotes(WiimoteType.WIIMOTE);
ret = ret || _FindWiimotes(WiimoteType.WIIMOTEPLUS);
ret = ret || _FindWiimotes(WiimoteType.PROCONTROLLER);
return ret;
}

Expand All @@ -54,12 +51,9 @@ private static bool _FindWiimotes(WiimoteType type)
if(type == WiimoteType.WIIMOTE) {
vendor = vendor_id_wiimote;
product = product_id_wiimote;
} else if(type == WiimoteType.WIIMOTEPLUS) {
} else if(type == WiimoteType.WIIMOTEPLUS || type == WiimoteType.PROCONTROLLER) {
vendor = vendor_id_wiimote;
product = product_id_wiimoteplus;
} else if(type == WiimoteType.PROCONTROLLER) {
vendor = vendor_id_procontroller;
product = product_id_procontroller;
}

IntPtr ptr = HIDapi.hid_enumerate(vendor, product);
Expand Down Expand Up @@ -91,7 +85,14 @@ private static bool _FindWiimotes(WiimoteType type)
{
IntPtr handle = HIDapi.hid_open_path(enumerate.path);

remote = new Wiimote(handle, enumerate.path, type);
WiimoteType trueType = type;

// Wii U Pro Controllers have the same identifiers as the newer Wii Remote Plus except for product
// string (WHY nintendo...)
if(enumerate.product_string.EndsWith("UC"))
trueType = WiimoteType.PROCONTROLLER;

remote = new Wiimote(handle, enumerate.path, trueType);

if (Debug_Messages)
Debug.Log("Found New Remote: " + remote.hidapi_path);
Expand Down

0 comments on commit 75ddce2

Please sign in to comment.