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); } }
USBMouse.h@0:237d5ef643e9, 2012-05-11 (annotated)
- Committer:
- innocopter
- Date:
- Fri May 11 13:35:59 2012 +0000
- Revision:
- 0:237d5ef643e9
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
innocopter | 0:237d5ef643e9 | 1 | #include "usbhid.h" |
innocopter | 0:237d5ef643e9 | 2 | |
innocopter | 0:237d5ef643e9 | 3 | #ifndef MBED_USBMOUSE_H |
innocopter | 0:237d5ef643e9 | 4 | #define MBED_USBMOUSE_H |
innocopter | 0:237d5ef643e9 | 5 | |
innocopter | 0:237d5ef643e9 | 6 | /* Class: USBMouse |
innocopter | 0:237d5ef643e9 | 7 | * Emulate a USB Mouse HID device |
innocopter | 0:237d5ef643e9 | 8 | * |
innocopter | 0:237d5ef643e9 | 9 | * Example: |
innocopter | 0:237d5ef643e9 | 10 | * > #include "mbed.h" |
innocopter | 0:237d5ef643e9 | 11 | * > #include "USBMouse.h" |
innocopter | 0:237d5ef643e9 | 12 | * > |
innocopter | 0:237d5ef643e9 | 13 | * > USBMouse mouse; |
innocopter | 0:237d5ef643e9 | 14 | * > |
innocopter | 0:237d5ef643e9 | 15 | * > int main() { |
innocopter | 0:237d5ef643e9 | 16 | * > while(1) { |
innocopter | 0:237d5ef643e9 | 17 | * > mouse.move(10, 0); |
innocopter | 0:237d5ef643e9 | 18 | * > wait(2); |
innocopter | 0:237d5ef643e9 | 19 | * > } |
innocopter | 0:237d5ef643e9 | 20 | * > } |
innocopter | 0:237d5ef643e9 | 21 | */ |
innocopter | 0:237d5ef643e9 | 22 | class USBMouse : private usbhid { |
innocopter | 0:237d5ef643e9 | 23 | public: |
innocopter | 0:237d5ef643e9 | 24 | /* Constructor: USBMouse |
innocopter | 0:237d5ef643e9 | 25 | * Create a USB Mouse using the mbed USB Device interface |
innocopter | 0:237d5ef643e9 | 26 | */ |
innocopter | 0:237d5ef643e9 | 27 | USBMouse(); |
innocopter | 0:237d5ef643e9 | 28 | |
innocopter | 0:237d5ef643e9 | 29 | /* Function: move |
innocopter | 0:237d5ef643e9 | 30 | * Move the mouse |
innocopter | 0:237d5ef643e9 | 31 | * |
innocopter | 0:237d5ef643e9 | 32 | * Variables: |
innocopter | 0:237d5ef643e9 | 33 | * x - Distance to move in x-axis |
innocopter | 0:237d5ef643e9 | 34 | * y - Distance to move in y-axis |
innocopter | 0:237d5ef643e9 | 35 | */ |
innocopter | 0:237d5ef643e9 | 36 | void move(int x, int y); |
innocopter | 0:237d5ef643e9 | 37 | |
innocopter | 0:237d5ef643e9 | 38 | /* Function: scroll |
innocopter | 0:237d5ef643e9 | 39 | * Scroll the scroll wheel |
innocopter | 0:237d5ef643e9 | 40 | * |
innocopter | 0:237d5ef643e9 | 41 | * Variables: |
innocopter | 0:237d5ef643e9 | 42 | * z - Distance to scroll scroll wheel |
innocopter | 0:237d5ef643e9 | 43 | */ |
innocopter | 0:237d5ef643e9 | 44 | void scroll(int z); |
innocopter | 0:237d5ef643e9 | 45 | |
innocopter | 0:237d5ef643e9 | 46 | /* Function: buttons |
innocopter | 0:237d5ef643e9 | 47 | * Set the state of the buttons |
innocopter | 0:237d5ef643e9 | 48 | * |
innocopter | 0:237d5ef643e9 | 49 | * Variables: |
innocopter | 0:237d5ef643e9 | 50 | * left - set the left button as down (1) or up (0) |
innocopter | 0:237d5ef643e9 | 51 | * middle - set the middle button as down (1) or up (0) |
innocopter | 0:237d5ef643e9 | 52 | * right - set the right button as down (1) or up (0) |
innocopter | 0:237d5ef643e9 | 53 | */ |
innocopter | 0:237d5ef643e9 | 54 | void buttons(int left, int middle, int right); |
innocopter | 0:237d5ef643e9 | 55 | |
innocopter | 0:237d5ef643e9 | 56 | private: |
innocopter | 0:237d5ef643e9 | 57 | int _buttons; |
innocopter | 0:237d5ef643e9 | 58 | }; |
innocopter | 0:237d5ef643e9 | 59 | |
innocopter | 0:237d5ef643e9 | 60 | #endif |