ST/USBHOST forked to add another HID handler for raw keyboard data to get more detail not available with current handlers (all pressed keys, all releases, and periodic updates)

Dependents:   C64-stm429_discovery

Files at this revision

API Documentation at this revision

Comitter:
davervw
Date:
Mon Apr 13 05:25:10 2020 +0000
Parent:
6:d3ac9e1c0035
Commit message:
Added handler to USBHostHID/USBHostKeyboard.cpp:; void (*onKeyData)(uint8_t len, uint8_t* data);; so can get raw keyboard data for all keys simultaneously pressed, and all releases and periodic data

Changed in this revision

USBHostHID/USBHostKeyboard.cpp Show annotated file Show diff for this revision Revisions of this file
USBHostHID/USBHostKeyboard.h Show annotated file Show diff for this revision Revisions of this file
diff -r d3ac9e1c0035 -r 9dc1cb9d5e12 USBHostHID/USBHostKeyboard.cpp
--- a/USBHostHID/USBHostKeyboard.cpp	Wed Apr 26 20:08:31 2017 +0000
+++ b/USBHostHID/USBHostKeyboard.cpp	Mon Apr 13 05:25:10 2020 +0000
@@ -146,6 +146,9 @@
     int index = (len == 9) ? 1 : 0;
     int len_listen = int_in->getSize();
     uint8_t key = 0;
+    if (len > 0 && onKeyData) {
+        (*onKeyData)(len, report);
+    }
     if (len == 8 || len == 9) {
         uint8_t modifier = (report[index] == 4) ? 3 : report[index];
         len_listen = len;
@@ -157,6 +160,7 @@
             (*onKeyCode)(report[index + 2], modifier);
         }
     }
+    
     if (dev && int_in)
         host->interruptRead(dev, int_in, report, len_listen, false);
 }
diff -r d3ac9e1c0035 -r 9dc1cb9d5e12 USBHostHID/USBHostKeyboard.h
--- a/USBHostHID/USBHostKeyboard.h	Wed Apr 26 20:08:31 2017 +0000
+++ b/USBHostHID/USBHostKeyboard.h	Mon Apr 13 05:25:10 2020 +0000
@@ -70,6 +70,17 @@
         }
     }
 
+    /**
+     * Attach a callback called when data received from keyboard
+     *
+     * @param ptr function pointer
+     */
+    inline void attach(void (*ptr)(uint8_t size, uint8_t* data)) {
+        if (ptr != NULL) {
+            onKeyData = ptr;
+        }
+    }
+
 protected:
     //From IUSBEnumerator
     virtual void setVidPid(uint16_t vid, uint16_t pid);
@@ -90,6 +101,7 @@
 
     void (*onKey)(uint8_t key);
     void (*onKeyCode)(uint8_t key, uint8_t modifier);
+    void (*onKeyData)(uint8_t len, uint8_t* data);
 
     int report_id;