2018.07.26

Dependencies:   FATFileSystem3 mbed-rtos

Fork of USBHost by mbed official

Revision:
5:e48791a1ef18
Parent:
4:b320d68e98e7
Child:
8:93da8ea2708b
diff -r b320d68e98e7 -r e48791a1ef18 USBHostHID/USBHostMouse.cpp
--- a/USBHostHID/USBHostMouse.cpp	Tue Mar 12 17:23:37 2013 +0000
+++ b/USBHostHID/USBHostMouse.cpp	Wed Mar 13 10:23:01 2013 +0000
@@ -29,10 +29,19 @@
     dev = NULL;
     int_in = NULL;
     onUpdate = NULL;
+    onButtonUpdate = NULL;
+    onXUpdate = NULL;
+    onYUpdate = NULL;
+    onZUpdate = NULL;
     report_id = 0;
     dev_connected = false;
     mouse_device_found = false;
     mouse_intf = -1;
+    
+    buttons = 0;
+    x = 0;
+    y = 0;
+    z = 0;
 }
 
 bool USBHostMouse::connected() {
@@ -40,14 +49,12 @@
 }
 
 bool USBHostMouse::connect() {
-    
-    U8 i;
-    
+
     if (dev_connected) {
         return true;
     }
     
-    for (i = 0; i < MAX_DEVICE_CONNECTED; i++) {
+    for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
         if ((dev = host->getDevice(i)) != NULL) {
 
             if(host->enumerate(dev, this))
@@ -78,10 +85,34 @@
 void USBHostMouse::rxHandler() {
     int len_listen = int_in->getSize();
     int len = int_in->getLengthTransferred();
+    
     if (onUpdate) {
         (*onUpdate)(report[0] & 0x07, report[1], report[2], report[3]);
     }
-    if (dev != NULL)
+    
+    if (onButtonUpdate && (buttons != (report[0] & 0x07))) {
+        (*onButtonUpdate)(report[0] & 0x07);
+    }
+    
+    if (onXUpdate && (x != report[1])) {
+        (*onXUpdate)(report[1]);
+    }
+    
+    if (onYUpdate && (y != report[2])) {
+        (*onYUpdate)(report[2]);
+    }
+    
+    if (onZUpdate && (z != report[3])) {
+        (*onZUpdate)(report[3]);
+    }
+        
+    // update mouse state
+    buttons = report[0] & 0x07;
+    x = report[1];
+    y = report[2];
+    z = report[3];
+    
+    if (dev)
         host->interruptRead(dev, int_in, report, len_listen, false);
 }