From f38a0f65157af628ca5f7706499748c199f0611b Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Wed, 4 Dec 2013 21:11:25 -0500 Subject: [PATCH] Refactor conflicting defines --- hidboot.cpp | 18 +++++++++--------- hidboot.h | 44 ++++++++------------------------------------ 2 files changed, 17 insertions(+), 45 deletions(-) diff --git a/hidboot.cpp b/hidboot.cpp index c7f33789..2737b7b9 100644 --- a/hidboot.cpp +++ b/hidboot.cpp @@ -56,7 +56,7 @@ void KeyboardReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t if (prevState.bInfo[0x00] != buf[0x00]) { OnControlKeysChanged(prevState.bInfo[0x00], buf[0x00]); } - + for (uint8_t i = 2; i < 8; i++) { bool down = false; bool up = false; @@ -82,13 +82,13 @@ uint8_t KeyboardReportParser::HandleLockingKeys(HID *hid, uint8_t key) { uint8_t old_keys = kbdLockingKeys.bLeds; switch (key) { - case KEY_NUM_LOCK: + case UHS_HID_BOOT_KEY_NUM_LOCK: kbdLockingKeys.kbdLeds.bmNumLock = ~kbdLockingKeys.kbdLeds.bmNumLock; break; - case KEY_CAPS_LOCK: + case UHS_HID_BOOT_KEY_CAPS_LOCK: kbdLockingKeys.kbdLeds.bmCapsLock = ~kbdLockingKeys.kbdLeds.bmCapsLock; break; - case KEY_SCROLL_LOCK: + case UHS_HID_BOOT_KEY_SCROLL_LOCK: kbdLockingKeys.kbdLeds.bmScrollLock = ~kbdLockingKeys.kbdLeds.bmScrollLock; break; } @@ -133,11 +133,11 @@ uint8_t KeyboardReportParser::OemToAscii(uint8_t mod, uint8_t key) { return (uint8_t)pgm_read_byte(&padKeys[key - 0x54]); else { switch (key) { - case KEY_SPACE: return (0x20); - case KEY_ENTER: return (0x13); - case KEY_ZERO: return ((shift) ? ')': '0'); - case KEY_ZERO2: return ((kbdLockingKeys.kbdLeds.bmNumLock == 1) ? '0': 0); - case KEY_PERIOD: return ((kbdLockingKeys.kbdLeds.bmNumLock == 1) ? '.': 0); + case UHS_HID_BOOT_KEY_SPACE: return (0x20); + 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_PERIOD: return ((kbdLockingKeys.kbdLeds.bmNumLock == 1) ? '.': 0); } } return ( 0); diff --git a/hidboot.h b/hidboot.h index 1faec28a..30d00ae8 100644 --- a/hidboot.h +++ b/hidboot.h @@ -19,42 +19,14 @@ e-mail : support@circuitsathome.com #include "hid.h" -// -// FIX-ME: -// Prevent teensy HID collisions. -// These are problematic. Who changes? -// The best policy for now is to take over these definitions. -// This is a classic reason why a library should prefix defines with something unique. -// I suggest prefixing with 'UHS_' for every define in the entire library. -// Yes, this could break things, but what is one to do? -// -#ifdef KEY_SPACE -#undef KEY_SPACE -#endif -#ifdef KEY_ENTER -#undef KEY_ENTER -#endif -#ifdef KEY_PERIOD -#undef KEY_PERIOD -#endif -#ifdef KEY_NUM_LOCK -#undef KEY_NUM_LOCK -#endif -#ifdef KEY_CAPS_LOCK -#undef KEY_CAPS_LOCK -#endif -#ifdef KEY_SCROLL_LOCK -#undef KEY_SCROLL_LOCK -#endif - -#define KEY_ZERO 0x27 -#define KEY_ENTER 0x28 -#define KEY_SPACE 0x2c -#define KEY_CAPS_LOCK 0x39 -#define KEY_SCROLL_LOCK 0x47 -#define KEY_NUM_LOCK 0x53 -#define KEY_ZERO2 0x62 -#define KEY_PERIOD 0x63 +#define UHS_HID_BOOT_KEY_ZERO 0x27 +#define UHS_HID_BOOT_KEY_ENTER 0x28 +#define UHS_HID_BOOT_KEY_SPACE 0x2c +#define UHS_HID_BOOT_KEY_CAPS_LOCK 0x39 +#define UHS_HID_BOOT_KEY_SCROLL_LOCK 0x47 +#define UHS_HID_BOOT_KEY_NUM_LOCK 0x53 +#define UHS_HID_BOOT_KEY_ZERO2 0x62 +#define UHS_HID_BOOT_KEY_PERIOD 0x63 struct MOUSEINFO {