Joystick enabled version of USBHID -library. Has full Playstation 3 functionality including button pressures and a working home-button implementation, while maintaining full PC/MAC/linux -compatibility. basic operation of the lib: #include "mbed.h" #include "usbhid.h" USBJoystick joystick; int main() { while(1) { char dpad = 0xf; /*only the rightmost 4 bits matter*/ short button = 0xff; /*only the rightmost 13 bits matter*/ /*buttons are square, cross, circle, triangle, l1, r1, l2, r2, l3, r3, home.*/ char stick1x = 0; char stick1y = 0; char stick2x = 0; char stick2y = 0; joystick.joystick(dpad, buttons, stick1x, stick1y, stick2x, stick2y); wait_ms(5); } }
Diff: usbhid.h
- Revision:
- 0:237d5ef643e9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbhid.h Fri May 11 13:35:59 2012 +0000 @@ -0,0 +1,56 @@ +/* usbhid.h */ +/* USB HID class device */ +/* Copyright (c) Phil Wright 2008 */ + +/* modified by Shinichiro Oba <http://mbed.org/users/bricklife/> */ + +#ifndef USBHID_H +#define USBHID_H + +#include "usbdevice.h" + +/* Mouse buttons */ +#define MOUSE_L (1<<0) +#define MOUSE_M (1<<1) +#define MOUSE_R (1<<2) + +class usbhid : public usbdevice +{ +public: + usbhid(); + bool keyboard(char c); + bool keyboard(char *string); + bool mouse(signed char x, signed char y, unsigned char buttons=0, signed char wheel=0); +protected: + virtual bool requestSetConfiguration(); + virtual void endpointEventEP1In(void); + virtual void deviceEventReset(void); + virtual bool requestGetDescriptor(void); + virtual bool requestSetup(void); +private: + bool sendInputReport(unsigned char id, unsigned char *data, unsigned char size); +}; + + +// +// USBJoystick +// + +#define JOYSTICK_UP (1<<0) +#define JOYSTICK_DOWN (1<<1) +#define JOYSTICK_LEFT (1<<2) +#define JOYSTICK_RIGHT (1<<3) + +class USBJoystick : public usbhid +{ +public: + USBJoystick(); + bool joystick(unsigned char stick, unsigned short buttons=0, signed char x=0, signed char y=0, signed char z=0, signed char rz=0); +protected: + virtual bool requestGetDescriptor(void); + virtual bool requestSetup(void); +private: + bool sendInputReport(unsigned char *data, unsigned char size); +}; + +#endif \ No newline at end of file