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); } }

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers usbhid.h Source File

usbhid.h

00001 /* usbhid.h */
00002 /* USB HID class device */
00003 /* Copyright (c) Phil Wright 2008 */
00004 
00005 /* modified by Shinichiro Oba <http://mbed.org/users/bricklife/> */
00006 
00007 #ifndef USBHID_H
00008 #define USBHID_H
00009 
00010 #include "usbdevice.h"
00011 
00012 /* Mouse buttons */
00013 #define MOUSE_L (1<<0)
00014 #define MOUSE_M (1<<1)
00015 #define MOUSE_R (1<<2)
00016 
00017 class usbhid : public usbdevice
00018 {
00019 public:
00020     usbhid();
00021     bool keyboard(char c);
00022     bool keyboard(char *string);
00023     bool mouse(signed char x, signed char y, unsigned char buttons=0, signed char wheel=0);
00024 protected:
00025     virtual bool requestSetConfiguration();
00026     virtual void endpointEventEP1In(void);
00027     virtual void deviceEventReset(void);
00028     virtual bool requestGetDescriptor(void);
00029     virtual bool requestSetup(void);
00030 private:
00031     bool sendInputReport(unsigned char id, unsigned char *data, unsigned char size);
00032 };
00033 
00034 
00035 //
00036 // USBJoystick
00037 //
00038 
00039 #define JOYSTICK_UP    (1<<0)
00040 #define JOYSTICK_DOWN  (1<<1)
00041 #define JOYSTICK_LEFT  (1<<2)
00042 #define JOYSTICK_RIGHT (1<<3)
00043 
00044 class USBJoystick : public usbhid
00045 {
00046 public:
00047     USBJoystick();
00048     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);
00049 protected:
00050     virtual bool requestGetDescriptor(void);
00051     virtual bool requestSetup(void);
00052 private:
00053     bool sendInputReport(unsigned char *data, unsigned char size);
00054 };
00055 
00056 #endif