Athena: Wiimote and Mac OS X
Button Status Reports
This is slightly more complex. The Wiimote can issues reports, but only at the request of the host application, which can specify whether they are continuous or only when something changes.
And more annoyingly is that these reports stop when an extension such as the nunchuk is plugged in, and you have to request them to start again.
So lets start off with the code to get the input reports being sent, but we’ll only need them when states are changed – in our case, the buttons.
//
//
#define INPUT_REPORT_TYPE_BUTTONS 0x30
#define INPUT_REPORT_CONTINUOUS ( 1 << 2 )
#define INPUT_REPORT_NOTCONTINUOUS ( 0 << 2 )
//
//
void HIDInput::Wiimote::RequestInputReport( IOHIDDeviceRef inDeviceRef, const bool inIsContinuous, const bool inVibrate )
{
//
unsigned char kFlags = 1 << 1;
kFlags |= inVibrate ? WIIMOTE_VIBRATE : WIIMOTE_NOVIBRATE;
kFlags |= inContinuous ? INPUT_REPORT_CONTINUOUS : INPUT_REPORT_NOTCONTINUOUS;
//
const Core::u8 kReportType = 0x12;
const Core::u8 kReportSize = 3;
const Core::byte kReportData[kReportSize] =
{
kReportType,
kFlags,
INPUT_REPORT_TYPE_BUTTONS
};
//
DeviceSendReport( inDeviceRef, kReportType, kReportData, kReportSize );
}
The first byte after the report type lets the Wiimote know whether we want continuous updates or not, as well as whether to turn the motor on or off. The second byte tells it which report we would like sent.
I’ll only cover buttons in this guide, I might write up the accelerometer at some point when I figure out what the LSB are used for.
With that done, you should now start receiving messages from the Wiimote where the first byte is set to 0×30.
//
//
#define BUTTON_REPORT_PLUS ( 1 << 4 )
#define BUTTON_REPORT_MINUS ( 1 << 4 )
#define BUTTON_REPORT_DPAD_UP ( 1 << 3 )
#define BUTTON_REPORT_DPAD_DOWN ( 1 << 2 )
#define BUTTON_REPORT_DPAD_LEFT ( 1 << 0 )
#define BUTTON_REPORT_DPAD_RIGHT ( 1 << 1 )
#define BUTTON_REPORT_HOME ( 1 << 7 )
#define BUTTON_REPORT_A ( 1 << 3 )
#define BUTTON_REPORT_B ( 1 << 2 )
#define BUTTON_REPORT_1 ( 1 << 1 )
#define BUTTON_REPORT_2 ( 1 << 0 )
//
//
void HIDInput::Wiimote::DeviceIOHIDReportCallback( const unsigned char * inReportData, const unsigned int inSize )
{
switch( inReportData[0] )
{
// Command Status
case 0x22:
{
// ...
}
break;
// Button Input Report
case 0x30:
{
GetButtonData( &inReport[1] );
}
break;
default:
break;
}
}
//
//
void HIDInput::Wiimote::GetButtonData( const unsigned char * inData )
{
printf( "DPAD Up: %s\n", inData[0] & BUTTON_REPORT_DPAD_UP ? "true" : "false" );
printf( "DPAD Down: %s\n", inData[0] & BUTTON_REPORT_DPAD_DOWN ? "true" : "false" );
printf( "DPAD Left: %s\n", inData[0] & BUTTON_REPORT_DPAD_LEFT ? "true" : "false" );
printf( "DPAD Right: %s\n", inData[0] & BUTTON_REPORT_DPAD_RIGHT ? "true" : "false" );
printf( "A: %s\n", inData[1] & BUTTON_REPORT_A ? "true" : "false" );
printf( "B: %s\n", inData[1] & BUTTON_REPORT_B ? "true" : "false" );
printf( "Plus: %s\n", inData[0] & BUTTON_REPORT_PLUS ? "true" : "false" );
printf( "Home: %s\n", inData[1] & BUTTON_REPORT_HOME ? "true" : "false" );
printf( "Minus: %s\n", inData[1] & BUTTON_REPORT_MINUS ? "true" : "false" );
printf( "1: %s\n", inData[1] & BUTTON_REPORT_1 ? "true" : "false" );
printf( "2: %s\n", inData[1] & BUTTON_REPORT_2 ? "true" : "false" );
printf( "\n" );
}
The button input report message only contains button data, almost all the input reports contain button data as the first two bytes as well.
[Previous Page...] [Next Page...]No Comments »
RSS feed for comments on this post. TrackBack URL
Leave a comment
You must be logged in to post a comment.