USBHostMouse Hello World for ST-Nucleo-F446RE

Dependencies:   F401RE-USBHost mbed

Fork of USBHostMouse_HelloWorld by Samuel Mokrani

Revision:
7:26cbee9ef684
Parent:
2:be0aafb2edc2
--- a/main.cpp	Thu Mar 14 14:23:16 2013 +0000
+++ b/main.cpp	Sun May 01 05:05:48 2016 +0000
@@ -7,28 +7,22 @@
     printf("buttons: %d, x: %d, y: %d, z: %d\r\n", buttons, x, y, z);
 }
 
-void mouse_task(void const *) {
-    
+int main() {
     USBHostMouse mouse;
-    
-    while(1) {
-        // try to connect a USB mouse
-        while(!mouse.connect())
-            Thread::wait(500);
-    
-        // when connected, attach handler called on mouse event
-        mouse.attachEvent(onMouseEvent);
-        
-        // wait until the mouse is disconnected
-        while(mouse.connected())
-            Thread::wait(500);
+    // connect a USB mouse
+    if (!mouse.connect()) {
+        error("USB mouse not found.\n");
+    }
+    // when connected, attach handler called on mouse event
+    mouse.attachEvent(onMouseEvent);
+    Timer t;
+    t.reset();
+    t.start();
+    for(;;) {
+        if (t.read_ms() > 500) {
+            led = !led;
+            t.reset();
+        }
+        USBHost::poll();
     }
 }
-
-int main() {
-    Thread mouseTask(mouse_task, NULL, osPriorityNormal, 256 * 4);
-    while(1) {
-        led=!led;
-        Thread::wait(500);
-    }
-}
\ No newline at end of file