Adaptation of the official mbed USBHost repository to work with the LPC4088 Display Module
Dependents: DMSupport DMSupport DMSupport DMSupport
Fork of DM_USBHost by
Diff: USBHostHID/USBHostKeyboard.cpp
- Revision:
- 28:a55c5a98d5e9
- Parent:
- 24:868cbfe611a7
--- a/USBHostHID/USBHostKeyboard.cpp Tue Dec 02 15:16:39 2014 +0000 +++ b/USBHostHID/USBHostKeyboard.cpp Wed Dec 03 13:32:37 2014 +0000 @@ -80,8 +80,17 @@ USBHostKeyboard::USBHostKeyboard() { host = USBHost::getHostInst(); init(); + + report = host->getSafeMem(9); } +USBHostKeyboard::~USBHostKeyboard() +{ + if (report != NULL) { + host->returnSafeMem(report); + report = NULL; + } +} void USBHostKeyboard::init() { dev = NULL; @@ -141,16 +150,35 @@ if (len == 8 || len == 9) { uint8_t modifier = (report[index] == 4) ? 3 : report[index]; len_listen = len; - key = keymap[modifier][report[index + 2]]; - if (key && onKey) { - (*onKey)(key); + + // Original code gives + // 0 - no modifier + // 1 - CTRL pressed + // 32 - SHIFT pressed + // 3 - ALT pressed + // 8 - WIN pressed + // 64 - ALT GR pressed + // + // The keymap at the top of this file only really support + // "no" and SHIFT but SHIFT is at index 2 so it must be modified + // to avoid reading out of bounds. Also block all modifiers >= 4 + // as those will be out of bounds. + if (modifier == 32) { + modifier = 2; + } + if (modifier < 4) { + key = keymap[modifier][report[index + 2]]; + if (key && onKey) { + (*onKey)(key); + } } if ((report[index + 2] || modifier) && onKeyCode) { (*onKeyCode)(report[index + 2], modifier); } } - if (dev && int_in) + if (dev && int_in) { host->interruptRead(dev, int_in, report, len_listen, false); + } } /*virtual*/ void USBHostKeyboard::setVidPid(uint16_t vid, uint16_t pid)