USBHostMouse Hello World

Dependencies:   USBHost mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "USBHostMouse.h"
00003 
00004 DigitalOut led(LED1);
00005 
00006 void onMouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z) {
00007     printf("buttons: %d, x: %d, y: %d, z: %d\r\n", buttons, x, y, z);
00008 }
00009 
00010 void mouse_task(void const *) {
00011     
00012     USBHostMouse mouse;
00013     
00014     while(1) {
00015         // try to connect a USB mouse
00016         while(!mouse.connect())
00017             Thread::wait(500);
00018     
00019         // when connected, attach handler called on mouse event
00020         mouse.attachEvent(onMouseEvent);
00021         
00022         // wait until the mouse is disconnected
00023         while(mouse.connected())
00024             Thread::wait(500);
00025     }
00026 }
00027 
00028 int main() {
00029     Thread mouseTask(mouse_task, NULL, osPriorityNormal, 256 * 4);
00030     while(1) {
00031         led=!led;
00032         Thread::wait(500);
00033     }
00034 }