Shinichiro Oba
/
USBJoystick
USB HID Joystick Example (modified USBMouse)
Revision 1:ec6deffecbd3, committed 2011-01-19
- Comitter:
- bricklife
- Date:
- Wed Jan 19 11:27:13 2011 +0000
- Parent:
- 0:d450e82033a1
- Commit message:
Changed in this revision
USBHID/usbhid.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r d450e82033a1 -r ec6deffecbd3 USBHID/usbhid.cpp --- a/USBHID/usbhid.cpp Wed Jan 19 06:17:43 2011 +0000 +++ b/USBHID/usbhid.cpp Wed Jan 19 11:27:13 2011 +0000 @@ -530,7 +530,7 @@ /* Send report */ complete = false; disableEvents(); - endpointWrite(EP1IN, report, size); /* +1 for report ID */ + endpointWrite(EP1IN, report, size); enableEvents(); /* Wait for completion */ @@ -544,23 +544,23 @@ unsigned char hatswitch; if (stick & JOYSTICK_UP) { - hatswitch = 0x0; - if (stick & JOYSTICK_RIGHT) hatswitch = 0x1; - if (stick &JOYSTICK_LEFT) hatswitch = 0x7; + hatswitch = 0; + if (stick & JOYSTICK_RIGHT) hatswitch = 1; + if (stick &JOYSTICK_LEFT) hatswitch = 7; } else if (stick & JOYSTICK_RIGHT) { - hatswitch = 0x2; - if (stick & JOYSTICK_DOWN) hatswitch = 0x3; + hatswitch = 2; + if (stick & JOYSTICK_DOWN) hatswitch = 3; } else if (stick & JOYSTICK_DOWN) { - hatswitch = 0x4; - if (stick & JOYSTICK_LEFT) hatswitch = 0x5; + hatswitch = 4; + if (stick & JOYSTICK_LEFT) hatswitch = 5; } else if (stick & JOYSTICK_LEFT) { - hatswitch = 0x6; + hatswitch = 6; } else { hatswitch = 0xf; } report[0] = buttons & 0xff; - report[1] = ((buttons >> 8) & 0x0f) | ((hatswitch << 4) & 0xf0); + report[1] = ((hatswitch << 4) & 0xf0) | ((buttons >> 8) & 0x0f); report[2] = x + 0x80; report[3] = y + 0x80; report[4] = z + 0x80;