Unity-Wiimote
Unity-Wiimote copied to clipboard
Can't Read Nunchuck Data
I'm trying to read the data off the Nunchuk but failing...I feel like there's some initialization function that I'm not calling or something like that, because the sample scene works fine for me.
Here's my code to find the Wiimote:
WiimoteManager.FindWiimotes();
if (!WiimoteManager.HasWiimote()) { return; }
wiimote = WiimoteManager.Wiimotes[0];
wiimote.SendPlayerLED(false, false, false, false);
wiimote.SendDataReportMode(InputDataType.REPORT_EXT21);
wiimote.SetupIRCamera(IRDataType.BASIC);
if (wiimote.current_ext != ExtensionController.NUNCHUCK) {
print("no nunchuck");
print(wiimote.current_ext.ToString());
return;
}
print("wiimote has nunchuck");
print("Stick: " + wiimote.Nunchuck.stick[0] + ", " + wiimote.Nunchuck.stick[1]);
I always get the no nunchuck
line printed, and wiimore.current_ext.ToString()
is reported as NONE
. AS far as I can tell, that is expected behaviour, as the nunchuck isn't even fully detected at this point; I don't see the An extension has been connected.
debug message until after these messages are printed out.
Here's my code in my Update() method:
if (!WiimoteManager.HasWiimote()) { return; }
wiimote = WiimoteManager.Wiimotes[0];
int ret;
do {
ret = wiimote.ReadWiimoteData();
} while (ret > 0);
if (wiimote.current_ext == ExtensionController.NUNCHUCK) {
NunchuckData data = wiimote.Nunchuck;
print("got nunchuk!");
// Use nunchuck data
// ...
} else {
print(wiimote.current_ext.ToString());
}
In this case, I always drop into the else
block, even after the "An extension has been connected" message is printed out.
I sprinkled in some debug statements in Wiimote.cs
and noticed that in RespondIdentifyExtension
, the val
identifier has the hex value 0xFF00A4200000
, which is almost the same as the value for ID_Nunchuck
except the highest byte is FF
instead of 00
.
I'm not sure what is causing this. Am I missing an initialization function somewhere? Am I supposed to send some data to the wiimote before trying to read nunchuck data?
Same problem =(
I'm using WiiBuddy now from the Unity Asset Store. It comes without source code, but it works out of the box and recognizes the Nunchuck.
I had to set the data report mode to REPORT_BUTTONS_ACCEL_EXT16 to get Nunchuck data from my controller. By default I was only getting switch data back from just the Wiimote. I think a better description of what data is returned for each InputDataType would help greatly.