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.cpp@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 "USBMouse.h" |
innocopter | 0:237d5ef643e9 | 2 | |
innocopter | 0:237d5ef643e9 | 3 | USBMouse::USBMouse() { |
innocopter | 0:237d5ef643e9 | 4 | _buttons = 0; |
innocopter | 0:237d5ef643e9 | 5 | } |
innocopter | 0:237d5ef643e9 | 6 | |
innocopter | 0:237d5ef643e9 | 7 | void USBMouse::move(int x, int y) { |
innocopter | 0:237d5ef643e9 | 8 | while(x > 127) { |
innocopter | 0:237d5ef643e9 | 9 | mouse(127, 0, _buttons, 0); |
innocopter | 0:237d5ef643e9 | 10 | x = x - 127; |
innocopter | 0:237d5ef643e9 | 11 | } |
innocopter | 0:237d5ef643e9 | 12 | while(x < -128) { |
innocopter | 0:237d5ef643e9 | 13 | mouse(-128, 0, _buttons, 0); |
innocopter | 0:237d5ef643e9 | 14 | x = x + 128; |
innocopter | 0:237d5ef643e9 | 15 | } |
innocopter | 0:237d5ef643e9 | 16 | while(y > 127) { |
innocopter | 0:237d5ef643e9 | 17 | mouse(0, 127, _buttons, 0); |
innocopter | 0:237d5ef643e9 | 18 | y = y - 127; |
innocopter | 0:237d5ef643e9 | 19 | } |
innocopter | 0:237d5ef643e9 | 20 | while(y < -128) { |
innocopter | 0:237d5ef643e9 | 21 | mouse(0, -128, _buttons, 0); |
innocopter | 0:237d5ef643e9 | 22 | y = y + 128; |
innocopter | 0:237d5ef643e9 | 23 | } |
innocopter | 0:237d5ef643e9 | 24 | mouse(x, y, _buttons, 0); |
innocopter | 0:237d5ef643e9 | 25 | } |
innocopter | 0:237d5ef643e9 | 26 | |
innocopter | 0:237d5ef643e9 | 27 | void USBMouse::scroll(int z) { |
innocopter | 0:237d5ef643e9 | 28 | while(z > 127) { |
innocopter | 0:237d5ef643e9 | 29 | mouse(0, 0, _buttons, 127); |
innocopter | 0:237d5ef643e9 | 30 | z = z - 127; |
innocopter | 0:237d5ef643e9 | 31 | } |
innocopter | 0:237d5ef643e9 | 32 | while(z < -128) { |
innocopter | 0:237d5ef643e9 | 33 | mouse(0, 0, _buttons, -128); |
innocopter | 0:237d5ef643e9 | 34 | z = z + 128; |
innocopter | 0:237d5ef643e9 | 35 | } |
innocopter | 0:237d5ef643e9 | 36 | mouse(0, 0, _buttons, z); |
innocopter | 0:237d5ef643e9 | 37 | } |
innocopter | 0:237d5ef643e9 | 38 | |
innocopter | 0:237d5ef643e9 | 39 | void USBMouse::buttons(int left, int middle, int right) { |
innocopter | 0:237d5ef643e9 | 40 | int _buttons = 0; |
innocopter | 0:237d5ef643e9 | 41 | if(left) { |
innocopter | 0:237d5ef643e9 | 42 | _buttons |= MOUSE_L; |
innocopter | 0:237d5ef643e9 | 43 | } |
innocopter | 0:237d5ef643e9 | 44 | if(middle) { |
innocopter | 0:237d5ef643e9 | 45 | _buttons |= MOUSE_M; |
innocopter | 0:237d5ef643e9 | 46 | } |
innocopter | 0:237d5ef643e9 | 47 | if(right) { |
innocopter | 0:237d5ef643e9 | 48 | _buttons |= MOUSE_R; |
innocopter | 0:237d5ef643e9 | 49 | } |
innocopter | 0:237d5ef643e9 | 50 | mouse(0,0, _buttons, 0); |
innocopter | 0:237d5ef643e9 | 51 | } |