From 6867ff3ba89f55fdf9ff9f80fa6cb4c29f6513f7 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 28 Dec 2017 12:14:31 +0100 Subject: [PATCH] Make the HID facade implementation external Instead of implementing the HID adaptors within Kaleidoscope, provide an API only (by marking the symbols `extern`). For the sake of backwards compatibility, pull in `Kaleidoscope-HIDAdaptor-KeyboardioHID`, a new shim library implementing the status quo. Signed-off-by: Gergely Nagy --- src/Kaleidoscope.h | 2 + src/kaleidoscope/hid.cpp | 188 --------------------------------------- src/kaleidoscope/hid.h | 58 ++++++------ 3 files changed, 31 insertions(+), 217 deletions(-) delete mode 100644 src/kaleidoscope/hid.cpp diff --git a/src/Kaleidoscope.h b/src/Kaleidoscope.h index 96e237ad..8c6e6a4b 100644 --- a/src/Kaleidoscope.h +++ b/src/Kaleidoscope.h @@ -2,6 +2,8 @@ #include +#include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h" + //end of add your includes here #ifdef __cplusplus extern "C" { diff --git a/src/kaleidoscope/hid.cpp b/src/kaleidoscope/hid.cpp deleted file mode 100644 index f04e93de..00000000 --- a/src/kaleidoscope/hid.cpp +++ /dev/null @@ -1,188 +0,0 @@ -#include "hid.h" - -#ifdef ARDUINO_VIRTUAL -#include "VirtualHID/VirtualHID.h" -#else -#include "KeyboardioHID.h" -#endif - -namespace kaleidoscope { -namespace hid { -void initializeKeyboard() { - Keyboard.begin(); -} - -void pressRawKey(Key mappedKey) { - Keyboard.press(mappedKey.keyCode); - -} - -void _pressModifierKey(Key mappedKey) { - pressRawKey(mappedKey); - - /* On at least ChromeOS 51-60, first sending a "press shift" key event in the same report - * as the key report for some shifted keys causes the shift event to be missed. - * - * Specifically, Shift + [ in the same key report do not genereate a { - * - * This workaround causes an extra key report to be sent to toggle on the modifier key - * before sending the key event we're trying to modify as part of a key report - * - * I (Jesse) don't believe we need a similar workaround for toggling the modifer _off_ - */ - - if (!wasModifierKeyActive(mappedKey)) { - sendKeyboardReport(); - } -} - -void pressKey(Key mappedKey) { - if (mappedKey.flags & SHIFT_HELD) { - _pressModifierKey(Key_LeftShift); - } - if (mappedKey.flags & CTRL_HELD) { - _pressModifierKey(Key_LeftControl); - } - if (mappedKey.flags & LALT_HELD) { - _pressModifierKey(Key_LeftAlt); - } - if (mappedKey.flags & RALT_HELD) { - _pressModifierKey(Key_RightAlt); - } - if (mappedKey.flags & GUI_HELD) { - _pressModifierKey(Key_LeftGui); - } - - pressRawKey(mappedKey); -} - -void releaseRawKey(Key mappedKey) { - Keyboard.release(mappedKey.keyCode); - -} - -void releaseAllKeys() { - Keyboard.releaseAll(); - ConsumerControl.releaseAll(); -} - -void releaseKey(Key mappedKey) { - if (mappedKey.flags & SHIFT_HELD) { - releaseRawKey(Key_LeftShift); - } - if (mappedKey.flags & CTRL_HELD) { - releaseRawKey(Key_LeftControl); - } - if (mappedKey.flags & LALT_HELD) { - releaseRawKey(Key_LeftAlt); - } - if (mappedKey.flags & RALT_HELD) { - releaseRawKey(Key_RightAlt); - } - if (mappedKey.flags & GUI_HELD) { - releaseRawKey(Key_LeftGui); - } - releaseRawKey(mappedKey); -} - -boolean isModifierKeyActive(Key mappedKey) { - return Keyboard.isModifierActive(mappedKey.keyCode); -} - -boolean wasModifierKeyActive(Key mappedKey) { - return Keyboard.wasModifierActive(mappedKey.keyCode); -} - -uint8_t getKeyboardLEDs() { - return Keyboard.getLEDs(); -} - - -void sendKeyboardReport() { - Keyboard.sendReport(); - ConsumerControl.sendReport(); -} - -void initializeConsumerControl() { - ConsumerControl.begin(); -} - -void pressConsumerControl(Key mappedKey) { - ConsumerControl.press(CONSUMER(mappedKey)); -} - -void releaseConsumerControl(Key mappedKey) { - ConsumerControl.release(CONSUMER(mappedKey)); -} - - -void initializeSystemControl() { - SystemControl.begin(); -} - -void pressSystemControl(Key mappedKey) { - SystemControl.press(mappedKey.keyCode); -} - -void releaseSystemControl(Key mappedKey) { - SystemControl.release(); -} - - -// Mouse events - -void initializeMouse() { - Mouse.begin(); -} - -void moveMouse(signed char x, signed char y, signed char vWheel, signed char hWheel) { - Mouse.move(x, y, vWheel, hWheel); -} - -void clickMouseButtons(uint8_t buttons) { - Mouse.click(buttons); -} - -void pressMouseButtons(uint8_t buttons) { - Mouse.press(buttons); -} - -void releaseMouseButtons(uint8_t buttons) { - Mouse.release(buttons); -} - -void releaseAllMouseButtons(void) { - Mouse.releaseAll(); -} - -void sendMouseReport(void) { - Mouse.sendReport(); -} - -/** SingleAbsolute mouse (grapahics tablet) events */ - -void initializeAbsoluteMouse() { - SingleAbsoluteMouse.begin(); -} - -void moveAbsoluteMouse(signed char x, signed char y, signed char wheel) { - SingleAbsoluteMouse.move(x, y, wheel); -} -void moveAbsoluteMouseTo(uint16_t x, uint16_t y, signed char wheel) { - SingleAbsoluteMouse.moveTo(x, y, wheel); -} - -void clickAbsoluteMouseButtons(uint8_t buttons) { - SingleAbsoluteMouse.click(buttons); -} - -void pressAbsoluteMouseButtons(uint8_t buttons) { - SingleAbsoluteMouse.press(buttons); -} - -void releaseAbsoluteMouseButtons(uint8_t buttons) { - SingleAbsoluteMouse.release(buttons); -} - -} -}; diff --git a/src/kaleidoscope/hid.h b/src/kaleidoscope/hid.h index 384f7c89..56e5eb54 100644 --- a/src/kaleidoscope/hid.h +++ b/src/kaleidoscope/hid.h @@ -7,47 +7,47 @@ namespace hid { // A facade on top of our HID implementation -void initializeKeyboard(); +extern void initializeKeyboard(); -void pressKey(Key mappedKey); -void releaseKey(Key mappedKey); -void releaseAllKeys(); -void pressRawKey(Key mappedKey); -void releaseRawKey(Key mappedKey); +extern void pressKey(Key mappedKey); +extern void releaseKey(Key mappedKey); +extern void releaseAllKeys(); +extern void pressRawKey(Key mappedKey); +extern void releaseRawKey(Key mappedKey); /** Flushes any pending regular key switch events and sends them out */ -void sendKeyboardReport(); +extern void sendKeyboardReport(); -boolean isModifierKeyActive(Key mappedKey); -boolean wasModifierKeyActive(Key mappedKey); +extern boolean isModifierKeyActive(Key mappedKey); +extern boolean wasModifierKeyActive(Key mappedKey); -uint8_t getKeyboardLEDs(); +extern uint8_t getKeyboardLEDs(); -void initializeConsumerControl(); +extern void initializeConsumerControl(); -void pressConsumerControl(Key mappedKey); -void releaseConsumerControl(Key mappedKey); +extern void pressConsumerControl(Key mappedKey); +extern void releaseConsumerControl(Key mappedKey); -void initializeSystemControl(); +extern void initializeSystemControl(); -void pressSystemControl(Key mappedKey); -void releaseSystemControl(Key mappedKey); +extern void pressSystemControl(Key mappedKey); +extern void releaseSystemControl(Key mappedKey); -void initializeMouse(); +extern void initializeMouse(); -void moveMouse(signed char x, signed char y, signed char vWheel = 0, signed char hWheel = 0); -void clickMouseButtons(uint8_t buttons); -void pressMouseButtons(uint8_t buttons); -void releaseMouseButtons(uint8_t buttons); -void releaseAllMouseButtons(void); -void sendMouseReport(void); +extern void moveMouse(signed char x, signed char y, signed char vWheel = 0, signed char hWheel = 0); +extern void clickMouseButtons(uint8_t buttons); +extern void pressMouseButtons(uint8_t buttons); +extern void releaseMouseButtons(uint8_t buttons); +extern void releaseAllMouseButtons(void); +extern void sendMouseReport(void); -void initializeAbsoluteMouse(); +extern void initializeAbsoluteMouse(); -void moveAbsoluteMouse(signed char x, signed char y, signed char wheel); -void moveAbsoluteMouseTo(uint16_t x, uint16_t y, signed char wheel); -void clickAbsoluteMouseButtons(uint8_t buttons); -void pressAbsoluteMouseButtons(uint8_t buttons); -void releaseAbsoluteMouseButtons(uint8_t buttons); +extern void moveAbsoluteMouse(signed char x, signed char y, signed char wheel); +extern void moveAbsoluteMouseTo(uint16_t x, uint16_t y, signed char wheel); +extern void clickAbsoluteMouseButtons(uint8_t buttons); +extern void pressAbsoluteMouseButtons(uint8_t buttons); +extern void releaseAbsoluteMouseButtons(uint8_t buttons); } };