first release for keyboard
Fork of F401RE-USBHost by
Revision 24:75435a7ab25b, committed 2016-10-30
- Comitter:
- Ownasaurus
- Date:
- Sun Oct 30 15:58:04 2016 +0000
- Parent:
- 23:4ab8bc835303
- Child:
- 25:0d73d8154e04
- Commit message:
- Added new callback to send entire keyboard state
Changed in this revision
--- a/USBHostHID/USBHostKeyboard.cpp Sun May 01 03:18:11 2016 +0000 +++ b/USBHostHID/USBHostKeyboard.cpp Sun Oct 30 15:58:04 2016 +0000 @@ -133,6 +133,7 @@ return false; } +// this is called every keyboard update, including presses, releases and every so often void USBHostKeyboard::rxHandler() { int len = int_in->getLengthTransferred(); int index = (len == 9) ? 1 : 0; @@ -140,7 +141,12 @@ uint8_t key = 0; if (len == 8 || len == 9) { uint8_t modifier = (report[index] == 4) ? 3 : report[index]; - len_listen = len; + len_listen = len; + // add new callback to send raw state + if (onKeyRaw) + { + (*onKeyRaw)(report); + } key = keymap[modifier][report[index + 2]]; if (key && onKey) { (*onKey)(key);
--- a/USBHostHID/USBHostKeyboard.h Sun May 01 03:18:11 2016 +0000 +++ b/USBHostHID/USBHostKeyboard.h Sun Oct 30 15:58:04 2016 +0000 @@ -69,6 +69,17 @@ onKeyCode = ptr; } } + + /** + * Attach a callback called when a keyboard event is received + * + * @param ptr function pointer + */ + inline void attach(void (*ptr)(uint8_t rep[9])) { + if (ptr != NULL) { + onKeyRaw = ptr; + } + } protected: //From IUSBEnumerator @@ -90,6 +101,8 @@ void (*onKey)(uint8_t key); void (*onKeyCode)(uint8_t key, uint8_t modifier); + void (*onKeyRaw)(uint8_t rep[9]); + // TODO: add new callback function to send raw state int report_id;