Merge pull request #279 from keyboardio/f/hid/pluggable-with-default

Pluggable HID facade
pull/258/merge
Jesse Vincent 7 years ago committed by GitHub
commit 8f2eccaeba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,6 +18,7 @@
*/
#include "Kaleidoscope.h"
#include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h"
#include "Kaleidoscope-HostOS.h"
#include "Kaleidoscope/HostOS-select.h"

@ -8,6 +8,7 @@
#include "Kaleidoscope-Macros.h"
#include "Kaleidoscope-LEDControl.h"
#include "Kaleidoscope-Numlock.h"
#include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h"
#include "Kaleidoscope.h"
#include "LED-Off.h"

@ -2,6 +2,8 @@
#include <Arduino.h>
#include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h"
//end of add your includes here
#ifdef __cplusplus
extern "C" {

@ -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);
}
}
};

@ -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);
}
};

Loading…
Cancel
Save