![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Acts a USB HID keyboard, and socket server. Forwards characters from TCP ip socket to keyboard
Dependencies: mbed EthernetNetIf
USBKeyboardMouse/USBMouse.cpp@1:d866a9d23e49, 2018-12-14 (annotated)
- Committer:
- henryeherman
- Date:
- Fri Dec 14 01:15:44 2018 +0000
- Revision:
- 1:d866a9d23e49
- Parent:
- 0:beb124b81ef5
init
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
henryeherman | 0:beb124b81ef5 | 1 | #include "USBMouse.h" |
henryeherman | 0:beb124b81ef5 | 2 | |
henryeherman | 0:beb124b81ef5 | 3 | USBMouse::USBMouse() { |
henryeherman | 0:beb124b81ef5 | 4 | _buttons = 0; |
henryeherman | 0:beb124b81ef5 | 5 | } |
henryeherman | 0:beb124b81ef5 | 6 | |
henryeherman | 0:beb124b81ef5 | 7 | void USBMouse::move(int x, int y) { |
henryeherman | 0:beb124b81ef5 | 8 | while(x > 127) { |
henryeherman | 0:beb124b81ef5 | 9 | mouse(127, 0, _buttons, 0); |
henryeherman | 0:beb124b81ef5 | 10 | x = x - 127; |
henryeherman | 0:beb124b81ef5 | 11 | } |
henryeherman | 0:beb124b81ef5 | 12 | while(x < -128) { |
henryeherman | 0:beb124b81ef5 | 13 | mouse(-128, 0, _buttons, 0); |
henryeherman | 0:beb124b81ef5 | 14 | x = x + 128; |
henryeherman | 0:beb124b81ef5 | 15 | } |
henryeherman | 0:beb124b81ef5 | 16 | while(y > 127) { |
henryeherman | 0:beb124b81ef5 | 17 | mouse(0, 127, _buttons, 0); |
henryeherman | 0:beb124b81ef5 | 18 | y = y - 127; |
henryeherman | 0:beb124b81ef5 | 19 | } |
henryeherman | 0:beb124b81ef5 | 20 | while(y < -128) { |
henryeherman | 0:beb124b81ef5 | 21 | mouse(0, -128, _buttons, 0); |
henryeherman | 0:beb124b81ef5 | 22 | y = y + 128; |
henryeherman | 0:beb124b81ef5 | 23 | } |
henryeherman | 0:beb124b81ef5 | 24 | mouse(x, y, _buttons, 0); |
henryeherman | 0:beb124b81ef5 | 25 | } |
henryeherman | 0:beb124b81ef5 | 26 | |
henryeherman | 0:beb124b81ef5 | 27 | void USBMouse::scroll(int z) { |
henryeherman | 0:beb124b81ef5 | 28 | while(z > 127) { |
henryeherman | 0:beb124b81ef5 | 29 | mouse(0, 0, _buttons, 127); |
henryeherman | 0:beb124b81ef5 | 30 | z = z - 127; |
henryeherman | 0:beb124b81ef5 | 31 | } |
henryeherman | 0:beb124b81ef5 | 32 | while(z < -128) { |
henryeherman | 0:beb124b81ef5 | 33 | mouse(0, 0, _buttons, -128); |
henryeherman | 0:beb124b81ef5 | 34 | z = z + 128; |
henryeherman | 0:beb124b81ef5 | 35 | } |
henryeherman | 0:beb124b81ef5 | 36 | mouse(0, 0, _buttons, z); |
henryeherman | 0:beb124b81ef5 | 37 | } |
henryeherman | 0:beb124b81ef5 | 38 | |
henryeherman | 0:beb124b81ef5 | 39 | void USBMouse::buttons(int left, int middle, int right) { |
henryeherman | 0:beb124b81ef5 | 40 | int _buttons = 0; |
henryeherman | 0:beb124b81ef5 | 41 | if(left) { |
henryeherman | 0:beb124b81ef5 | 42 | _buttons |= MOUSE_L; |
henryeherman | 0:beb124b81ef5 | 43 | } |
henryeherman | 0:beb124b81ef5 | 44 | if(middle) { |
henryeherman | 0:beb124b81ef5 | 45 | _buttons |= MOUSE_M; |
henryeherman | 0:beb124b81ef5 | 46 | } |
henryeherman | 0:beb124b81ef5 | 47 | if(right) { |
henryeherman | 0:beb124b81ef5 | 48 | _buttons |= MOUSE_R; |
henryeherman | 0:beb124b81ef5 | 49 | } |
henryeherman | 0:beb124b81ef5 | 50 | mouse(0,0, _buttons, 0); |
henryeherman | 0:beb124b81ef5 | 51 | } |