USBHost Mouse example.

Dependencies:   USBHost mbed

Committer:
bcostm
Date:
Thu Aug 03 13:03:07 2017 +0000
Revision:
0:4456c264d862
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:4456c264d862 1 #include "mbed.h"
bcostm 0:4456c264d862 2 #include "USBHostMouse.h"
bcostm 0:4456c264d862 3
bcostm 0:4456c264d862 4 DigitalOut led(LED1);
bcostm 0:4456c264d862 5
bcostm 0:4456c264d862 6 void onMouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z)
bcostm 0:4456c264d862 7 {
bcostm 0:4456c264d862 8 printf("Buttons: %d, x: %d, y: %d, z: %d\r\n", buttons, x, y, z);
bcostm 0:4456c264d862 9 }
bcostm 0:4456c264d862 10
bcostm 0:4456c264d862 11 void mouse_task(void const *)
bcostm 0:4456c264d862 12 {
bcostm 0:4456c264d862 13 USBHostMouse mouse;
bcostm 0:4456c264d862 14
bcostm 0:4456c264d862 15 printf("Mouse started\n");
bcostm 0:4456c264d862 16
bcostm 0:4456c264d862 17 while(1) {
bcostm 0:4456c264d862 18
bcostm 0:4456c264d862 19 // Try to connect a USB mouse
bcostm 0:4456c264d862 20 while(!mouse.connect()) {
bcostm 0:4456c264d862 21 Thread::wait(500);
bcostm 0:4456c264d862 22 }
bcostm 0:4456c264d862 23
bcostm 0:4456c264d862 24 // When connected, attach handler called on mouse event
bcostm 0:4456c264d862 25 mouse.attachEvent(onMouseEvent);
bcostm 0:4456c264d862 26
bcostm 0:4456c264d862 27 // Wait until the mouse is disconnected
bcostm 0:4456c264d862 28 while(mouse.connected()) {
bcostm 0:4456c264d862 29 Thread::wait(500);
bcostm 0:4456c264d862 30 }
bcostm 0:4456c264d862 31
bcostm 0:4456c264d862 32 printf("Mouse disconnected\n");
bcostm 0:4456c264d862 33 }
bcostm 0:4456c264d862 34 }
bcostm 0:4456c264d862 35
bcostm 0:4456c264d862 36 int main()
bcostm 0:4456c264d862 37 {
bcostm 0:4456c264d862 38 Thread mouseTask(mouse_task, NULL, osPriorityNormal, 1024* 4);
bcostm 0:4456c264d862 39 while(1) {
bcostm 0:4456c264d862 40 led = !led;
bcostm 0:4456c264d862 41 Thread::wait(500);
bcostm 0:4456c264d862 42 }
bcostm 0:4456c264d862 43 }