Allow to override default arrays in hidboot, so it can easily be used with other keyboard layouts

This commit is contained in:
Kristian Lauszus 2013-12-05 19:57:50 +01:00
parent fd13b87c18
commit 0a7ffe5776
2 changed files with 29 additions and 14 deletions

View file

@ -99,10 +99,10 @@ uint8_t KeyboardReportParser::HandleLockingKeys(HID *hid, uint8_t key) {
return 0; return 0;
} }
const uint8_t KeyboardReportParser::numKeys[] PROGMEM = {'!', '@', '#', '$', '%', '^', '&', '*', '(', ')'}; const uint8_t KeyboardReportParser::numKeys[10] PROGMEM = {'!', '@', '#', '$', '%', '^', '&', '*', '(', ')'};
const uint8_t KeyboardReportParser::symKeysUp[] PROGMEM = {'_', '+', '{', '}', '|', '~', ':', '"', '~', '<', '>', '?'}; const uint8_t KeyboardReportParser::symKeysUp[12] PROGMEM = {'_', '+', '{', '}', '|', '~', ':', '"', '~', '<', '>', '?'};
const uint8_t KeyboardReportParser::symKeysLo[] PROGMEM = {'-', '=', '[', ']', '\\', ' ', ';', '\'', '`', ',', '.', '/'}; const uint8_t KeyboardReportParser::symKeysLo[12] PROGMEM = {'-', '=', '[', ']', '\\', ' ', ';', '\'', '`', ',', '.', '/'};
const uint8_t KeyboardReportParser::padKeys[] PROGMEM = {'/', '*', '-', '+', 0x13}; const uint8_t KeyboardReportParser::padKeys[5] PROGMEM = {'/', '*', '-', '+', 0x13};
uint8_t KeyboardReportParser::OemToAscii(uint8_t mod, uint8_t key) { uint8_t KeyboardReportParser::OemToAscii(uint8_t mod, uint8_t key) {
uint8_t shift = (mod & 0x22); uint8_t shift = (mod & 0x22);
@ -118,24 +118,23 @@ uint8_t KeyboardReportParser::OemToAscii(uint8_t mod, uint8_t key) {
else else
return (key - 4 + 'a'); return (key - 4 + 'a');
}// Numbers }// Numbers
else if (key > 0x1d && key < 0x27) { else if (key > 0x1d && key < 0x28) {
if (shift) if (shift)
return ((uint8_t)pgm_read_byte(&numKeys[key - 0x1e])); return ((uint8_t)pgm_read_byte(&getNumKeys()[key - 0x1e]));
else else
return (key - 0x1e + '1'); return ((key == UHS_HID_BOOT_KEY_ZERO) ? '0' : key - 0x1e + '1');
}// Keypad Numbers }// Keypad Numbers
else if (key > 0x58 && key < 0x62) { else if (key > 0x58 && key < 0x62) {
if (kbdLockingKeys.kbdLeds.bmNumLock == 1) if (kbdLockingKeys.kbdLeds.bmNumLock == 1)
return (key - 0x59 + '1'); return (key - 0x59 + '1');
} else if (key > 0x2c && key < 0x39) } else if (key > 0x2c && key < 0x39)
return ((shift) ? (uint8_t)pgm_read_byte(&symKeysUp[key - 0x2d]) : (uint8_t)pgm_read_byte(&symKeysLo[key - 0x2d])); return ((shift) ? (uint8_t)pgm_read_byte(&getSymKeysUp()[key - 0x2d]) : (uint8_t)pgm_read_byte(&getSymKeysLo()[key - 0x2d]));
else if (key > 0x53 && key < 0x59) else if (key > 0x53 && key < 0x59)
return (uint8_t)pgm_read_byte(&padKeys[key - 0x54]); return (uint8_t)pgm_read_byte(&getPadKeys()[key - 0x54]);
else { else {
switch (key) { switch (key) {
case UHS_HID_BOOT_KEY_SPACE: return (0x20); case UHS_HID_BOOT_KEY_SPACE: return (0x20);
case UHS_HID_BOOT_KEY_ENTER: return (0x13); case UHS_HID_BOOT_KEY_ENTER: return (0x13);
case UHS_HID_BOOT_KEY_ZERO: return ((shift) ? ')': '0');
case UHS_HID_BOOT_KEY_ZERO2: return ((kbdLockingKeys.kbdLeds.bmNumLock == 1) ? '0': 0); case UHS_HID_BOOT_KEY_ZERO2: return ((kbdLockingKeys.kbdLeds.bmNumLock == 1) ? '0': 0);
case UHS_HID_BOOT_KEY_PERIOD: return ((kbdLockingKeys.kbdLeds.bmNumLock == 1) ? '.': 0); case UHS_HID_BOOT_KEY_PERIOD: return ((kbdLockingKeys.kbdLeds.bmNumLock == 1) ? '.': 0);
} }

View file

@ -112,10 +112,10 @@ struct KBDLEDS {
}; };
class KeyboardReportParser : public HIDReportParser { class KeyboardReportParser : public HIDReportParser {
static const uint8_t numKeys[]; static const uint8_t numKeys[10];
static const uint8_t symKeysUp[]; static const uint8_t symKeysUp[12];
static const uint8_t symKeysLo[]; static const uint8_t symKeysLo[12];
static const uint8_t padKeys[]; static const uint8_t padKeys[5];
protected: protected:
@ -150,6 +150,22 @@ protected:
virtual void OnKeyUp(uint8_t mod, uint8_t key) { virtual void OnKeyUp(uint8_t mod, uint8_t key) {
}; };
virtual const uint8_t *getNumKeys() {
return numKeys;
};
virtual const uint8_t *getSymKeysUp() {
return symKeysUp;
};
virtual const uint8_t *getSymKeysLo() {
return symKeysLo;
};
virtual const uint8_t *getPadKeys() {
return padKeys;
};
}; };
#define totalEndpoints (((BOOT_PROTOCOL & HID_PROTOCOL_KEYBOARD)? 2 : 0)+((BOOT_PROTOCOL & HID_PROTOCOL_MOUSE)? 1 : 0)) #define totalEndpoints (((BOOT_PROTOCOL & HID_PROTOCOL_KEYBOARD)? 2 : 0)+((BOOT_PROTOCOL & HID_PROTOCOL_MOUSE)? 1 : 0))