Example of moving the mouse in mbed-os
Dependencies: USBDEVICE
Fork of USBKeyboardMouse_with_String_Descriptor by
main.cpp@1:d00335a42592, 2018-06-27 (annotated)
- Committer:
- noutram
- Date:
- Wed Jun 27 10:18:43 2018 +0000
- Revision:
- 1:d00335a42592
- Parent:
- 0:f97b1f255167
Demo of a USB HID Mouse
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
llumpu | 0:f97b1f255167 | 1 | #include "mbed.h" |
noutram | 1:d00335a42592 | 2 | #include <math.h> |
llumpu | 0:f97b1f255167 | 3 | #include "USBMouse.h" |
llumpu | 0:f97b1f255167 | 4 | #include "USBKeyboard.h" |
noutram | 1:d00335a42592 | 5 | DigitalOut led(LED1); |
noutram | 1:d00335a42592 | 6 | DigitalIn sw1(USER_BUTTON); |
noutram | 1:d00335a42592 | 7 | USBMouse mouse; //Default - relative movement |
llumpu | 0:f97b1f255167 | 8 | |
noutram | 1:d00335a42592 | 9 | int main(void) |
noutram | 1:d00335a42592 | 10 | { |
noutram | 1:d00335a42592 | 11 | uint16_t x_center = (X_MAX_ABS - X_MIN_ABS)/2; |
noutram | 1:d00335a42592 | 12 | uint16_t y_center = (Y_MAX_ABS - Y_MIN_ABS)/2; |
noutram | 1:d00335a42592 | 13 | int16_t x_screen = 0; |
noutram | 1:d00335a42592 | 14 | int16_t y_screen = 0; |
llumpu | 0:f97b1f255167 | 15 | |
noutram | 1:d00335a42592 | 16 | uint32_t x_origin = x_center; |
noutram | 1:d00335a42592 | 17 | uint32_t y_origin = y_center; |
noutram | 1:d00335a42592 | 18 | |
noutram | 1:d00335a42592 | 19 | float angle = 0.0; |
noutram | 1:d00335a42592 | 20 | |
noutram | 1:d00335a42592 | 21 | //set to good known state |
noutram | 1:d00335a42592 | 22 | mouse.update(x_origin, y_origin, 0, 0); |
llumpu | 0:f97b1f255167 | 23 | |
noutram | 1:d00335a42592 | 24 | while (1) { |
noutram | 1:d00335a42592 | 25 | x_screen = 5.0f * cos((double)angle*3.14/180.0); |
noutram | 1:d00335a42592 | 26 | y_screen = 5.0f * sin((double)angle*3.14/180.0); |
noutram | 1:d00335a42592 | 27 | |
noutram | 1:d00335a42592 | 28 | mouse.move(x_screen, y_screen); |
noutram | 1:d00335a42592 | 29 | angle += 3.0f; |
noutram | 1:d00335a42592 | 30 | wait(0.01); |
llumpu | 0:f97b1f255167 | 31 | } |
llumpu | 0:f97b1f255167 | 32 | } |