Based on Alfredo Guerrero's WiiClassicControllerReader although I had to do additional decoding of packet. KL25Z talking to Wii classic controller.
Dependencies: CommonTypes WiiClassicControllerLib mbed
Revision 3:21e262cee052, committed 2013-06-30
- Comitter:
- RichardE
- Date:
- Sun Jun 30 12:08:06 2013 +0000
- Parent:
- 2:b75eb2fe5d2b
- Child:
- 4:71f5e3d2b0c6
- Commit message:
- Uses newer version of WiiClassicControllerLib with calibration. Not finished though.
Changed in this revision
WiiClassicControllerLib.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/WiiClassicControllerLib.lib Sat Jun 29 22:16:37 2013 +0000 +++ b/WiiClassicControllerLib.lib Sun Jun 30 12:08:06 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/RichardE/code/WiiClassicControllerLib/#9e766313a668 +http://mbed.org/users/RichardE/code/WiiClassicControllerLib/#52c4a0b3a509
--- a/main.cpp Sat Jun 29 22:16:37 2013 +0000 +++ b/main.cpp Sun Jun 30 12:08:06 2013 +0000 @@ -1,77 +1,75 @@ -/* - * SOURCE FILE : main.cpp - * - * Test program to test out WiiClassicController class. - * - */ - -#include "mbed.h" -#include "WiiClassicController.h" - -// Define this to dump packet in hex. -#define DUMP_PACKET - -#define LOOP_DELAY 1 // seconds - -// global declarations -Serial pc(USBTX, USBRX); - -/* Read from the Wii classic controller and display results on serial port output. - * @param ctrlr Controller to read from. - * @param portname Name of port you are reading from. - */ -static void ReadAndReport( WiiClassicController* const ctrlr, const char* const portname ) { - if( ctrlr->Read() ) { - - pc.printf("%s: ", portname); - - #ifdef DUMP_PACKET - int bufSize = ctrlr->GetReadBufSize(); - UInt8 *bufPtr = ctrlr->GetReadBuf(); - for (int i = 0; i < bufSize; i++) { - pc.printf("%x ", bufPtr[i]); - } - pc.printf("\r\n"); - #endif - - pc.printf("\r\nA\tB\tX\tY\tZL\tZR\tDU\tDD\tDL\tDR\tH\r\n"); - pc.printf("%u\t", ctrlr->GetButtonA()); - pc.printf("%u\t", ctrlr->GetButtonB()); - pc.printf("%u\t", ctrlr->GetButtonX()); - pc.printf("%u\t", ctrlr->GetButtonY()); - pc.printf("%u\t", ctrlr->GetButtonZL()); - pc.printf("%u\t", ctrlr->GetButtonZR()); - pc.printf("%u\t", ctrlr->GetButtonUp()); - pc.printf("%u\t", ctrlr->GetButtonDown()); - pc.printf("%u\t", ctrlr->GetButtonLeft()); - pc.printf("%u\t", ctrlr->GetButtonRight()); - pc.printf("%u\t", ctrlr->GetButtonHome()); - pc.printf("\r\nSEL\tSTART\tLT\tLC\tRT\tRC\tLX\tLY\tRX\tRY\r\n"); - pc.printf("%u\t", ctrlr->GetButtonSelect()); - pc.printf("%u\t", ctrlr->GetButtonStart()); - pc.printf("%u\t", ctrlr->GetLeftTrigger()); - pc.printf("%u\t", ctrlr->GetButtonLT()); - pc.printf("%u\t", ctrlr->GetRightTrigger()); - pc.printf("%u\t", ctrlr->GetButtonRT()); - pc.printf("%u\t", ctrlr->GetLJoyX()); - pc.printf("%u\t", ctrlr->GetLJoyY()); - pc.printf("%u\t", ctrlr->GetRJoyX()); - pc.printf("%u\t", ctrlr->GetRJoyY()); - pc.printf("\r\n\n\n"); - } - else { - pc.puts( "READ FAILURE\r\n" ); - } -} - -/** Main program. - */ -int main() { - WiiClassicController ctrlrA( PTE0, PTE1 ); - while (true) { - ReadAndReport( &ctrlrA, "PORT A" ); - wait(LOOP_DELAY); - } - // Never gets here. - // return EXIT_SUCCESS; +/* + * SOURCE FILE : main.cpp + * + * Test program to test out WiiClassicController class. + * + */ + +#include "mbed.h" +#include "WiiClassicControllerWithCalibration.h" + +// Define this to dump packet in hex. +#define DUMP_PACKET + +#define LOOP_DELAY 1 // seconds + +// global declarations +Serial pc(USBTX, USBRX); + +/* Read from the Wii classic controller and display results on serial port output. + * @param ctrlr Controller to read from. + * @param portname Name of port you are reading from. + */ +static void ReadAndReport( WiiClassicControllerWithCalibration *ctrlr, const char *portname ) { + if( ctrlr->Read() ) { + + pc.printf( "%c[H", 27 ); // VT100 home cursor + pc.printf("%s: ", portname); + + #ifdef DUMP_PACKET + int bufSize = ctrlr->GetReadBufSize(); + UInt8 *bufPtr = ctrlr->GetReadBuf(); + for (int i = 0; i < bufSize; i++) { + pc.printf("%x ", bufPtr[i]); + } + pc.printf("\r\n"); + #endif + + pc.printf("A=%u\r\n", ctrlr->GetButtonA()); + pc.printf("B=%u\r\n", ctrlr->GetButtonB()); + pc.printf("X=%u\r\n", ctrlr->GetButtonX()); + pc.printf("Y=%u\r\n", ctrlr->GetButtonY()); + pc.printf("ZL=%u\r\n", ctrlr->GetButtonZL()); + pc.printf("ZR=%u\r\n", ctrlr->GetButtonZR()); + pc.printf("Up=%u\r\n", ctrlr->GetButtonUp()); + pc.printf("Down=%u\r\n", ctrlr->GetButtonDown()); + pc.printf("Left=%u\r\n", ctrlr->GetButtonLeft()); + pc.printf("Right=%u\r\n", ctrlr->GetButtonRight()); + pc.printf("Home=%u\r\n", ctrlr->GetButtonHome()); + pc.printf("Select=%u\r\n", ctrlr->GetButtonSelect()); + pc.printf("Start=%u\r\n", ctrlr->GetButtonStart()); + pc.printf("LeftTrigger=%2u (%5.3f)\r\n", ctrlr->GetLeftTrigger(), ctrlr->GetCalLeftTrigger() ); + pc.printf("ButtonLT=%u\r\n", ctrlr->GetButtonLT()); + pc.printf("RightTrigger=%2u (%5.3f)\r\n", ctrlr->GetRightTrigger(), ctrlr->GetCalRightTrigger() ); + pc.printf("ButtonRT=%u\r\n", ctrlr->GetButtonRT()); + pc.printf("LJoyX=%2u (%5.3f)\r\n", ctrlr->GetLJoyX(), ctrlr->GetCalLJoyX() ); + pc.printf("LJoyY=%2u (%5.3f)\r\n", ctrlr->GetLJoyY(), ctrlr->GetCalLJoyY() ); + pc.printf("RJoyX=%2u (%5.3f)\r\n", ctrlr->GetRJoyX(), ctrlr->GetCalRJoyX() ); + pc.printf("RJoyY=%2u (%5.3f)\r\n", ctrlr->GetRJoyY(), ctrlr->GetCalRJoyY() ); + } + else { + pc.puts( "READ FAILURE\r\n" ); + } } + +/** Main program. + */ +int main() { + WiiClassicControllerWithCalibration ctrlrA( PTE0, PTE1 ); + while (true) { + ReadAndReport( &ctrlrA, "PORT A" ); + wait(LOOP_DELAY); + } + // Never gets here. + // return EXIT_SUCCESS; +}