Create an abstraction on top of the KeyboardioHID interface

so that user code doesn't need to know anything about it.

(This also paves the way for @wez' EventDispatcher)
pull/144/merge
Jesse Vincent 7 years ago
parent 178dd0a5f1
commit 8b187366c7
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -25,8 +25,8 @@ Kaleidoscope_::loop(void) {
(*hook)(false);
}
Keyboard.sendReport();
Keyboard.releaseAll();
sendKeyboardReport();
releaseAllKeys();
for (byte i = 0; loopHooks[i] != NULL && i < HOOK_MAX; i++) {
loopHook hook = loopHooks[i];

@ -1,5 +1,6 @@
#include "Kaleidoscope.h"
static bool handleSyntheticKeyswitchEvent(Key mappedKey, uint8_t keyState) {
if (mappedKey.flags & RESERVED)
return false;
@ -10,15 +11,17 @@ static bool handleSyntheticKeyswitchEvent(Key mappedKey, uint8_t keyState) {
if (mappedKey.flags & IS_INTERNAL) {
return false;
} else if (mappedKey.flags & IS_CONSUMER) {
if (keyIsPressed(keyState))
ConsumerControl.press(mappedKey.keyCode);
else if (keyWasPressed(keyState))
ConsumerControl.release(mappedKey.keyCode);
if (keyIsPressed(keyState)) {
pressConsumer(mappedKey);
} else if (keyWasPressed(keyState)) {
releaseConsumer(mappedKey);
}
} else if (mappedKey.flags & IS_SYSCTL) {
if (keyIsPressed(keyState))
SystemControl.press(mappedKey.keyCode);
else if (keyWasPressed(keyState))
SystemControl.release();
if (keyIsPressed(keyState)) {
pressSystem(mappedKey);
} else if (keyWasPressed(keyState)) {
releaseSystem(mappedKey);
}
} else if (mappedKey.flags & SWITCH_TO_KEYMAP) {
// Should not happen, handled elsewhere.
}
@ -40,57 +43,137 @@ static bool handleKeyswitchEventDefault(Key mappedKey, byte row, byte col, uint8
return true;
}
void handleKeyswitchEvent(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (!(keyState & INJECTED)) {
mappedKey = Layer.lookup(row, col);
}
for (byte i = 0; Kaleidoscope.eventHandlers[i] != NULL && i < HOOK_MAX; i++) {
Kaleidoscope_::eventHandlerHook handler = Kaleidoscope.eventHandlers[i];
mappedKey = (*handler)(mappedKey, row, col, keyState);
if (mappedKey.raw == Key_NoKey.raw)
return;
}
mappedKey = Layer.eventHandler(mappedKey, row, col, keyState);
if (mappedKey.raw == Key_NoKey.raw)
return;
handleKeyswitchEventDefault(mappedKey, row, col, keyState);
}
void pressKeyRaw(Key mappedKey) {
Keyboard.press(mappedKey.keyCode);
}
void pressKey(Key mappedKey) {
if (mappedKey.flags & SHIFT_HELD) {
Keyboard.press(Key_LeftShift.keyCode);
pressKeyRaw(Key_LeftShift);
}
if (mappedKey.flags & CTRL_HELD) {
Keyboard.press(Key_LeftControl.keyCode);
pressKeyRaw(Key_LeftControl);
}
if (mappedKey.flags & LALT_HELD) {
Keyboard.press(Key_LeftAlt.keyCode);
pressKeyRaw(Key_LeftAlt);
}
if (mappedKey.flags & RALT_HELD) {
Keyboard.press(Key_RightAlt.keyCode);
pressKeyRaw(Key_RightAlt);
}
if (mappedKey.flags & GUI_HELD) {
Keyboard.press(Key_LeftGui.keyCode);
pressKeyRaw(Key_LeftGui);
}
Keyboard.press(mappedKey.keyCode);
pressKeyRaw(mappedKey);
}
void releaseKeyRaw(Key mappedKey) {
Keyboard.release(mappedKey.keyCode);
}
void releaseAllKeys() {
Keyboard.releaseAll();
}
void releaseKey(Key mappedKey) {
if (mappedKey.flags & SHIFT_HELD) {
Keyboard.release(Key_LeftShift.keyCode);
releaseKeyRaw(Key_LeftShift);
}
if (mappedKey.flags & CTRL_HELD) {
Keyboard.release(Key_LeftControl.keyCode);
releaseKeyRaw(Key_LeftControl);
}
if (mappedKey.flags & LALT_HELD) {
Keyboard.release(Key_LeftAlt.keyCode);
releaseKeyRaw(Key_LeftAlt);
}
if (mappedKey.flags & RALT_HELD) {
Keyboard.release(Key_RightAlt.keyCode);
releaseKeyRaw(Key_RightAlt);
}
if (mappedKey.flags & GUI_HELD) {
Keyboard.release(Key_LeftGui.keyCode);
releaseKeyRaw(Key_LeftGui);
}
Keyboard.release(mappedKey.keyCode);
releaseKeyRaw(mappedKey);
}
void handleKeyswitchEvent(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (!(keyState & INJECTED)) {
mappedKey = Layer.lookup(row, col);
void sendKeyboardReport() {
Keyboard.sendReport();
}
for (byte i = 0; Kaleidoscope.eventHandlers[i] != NULL && i < HOOK_MAX; i++) {
Kaleidoscope_::eventHandlerHook handler = Kaleidoscope.eventHandlers[i];
mappedKey = (*handler)(mappedKey, row, col, keyState);
if (mappedKey.raw == Key_NoKey.raw)
return;
void pressConsumer(Key mappedKey) {
ConsumerControl.press(mappedKey.keyCode);
}
mappedKey = Layer.eventHandler(mappedKey, row, col, keyState);
if (mappedKey.raw == Key_NoKey.raw)
return;
handleKeyswitchEventDefault(mappedKey, row, col, keyState);
void releaseConsumer(Key mappedKey) {
ConsumerControl.release(mappedKey.keyCode);
}
void pressSystem(Key mappedKey) {
SystemControl.press(mappedKey.keyCode);
}
void releaseSystem(Key mappedKey) {
SystemControl.release();
}
/** Mouse events
* See above for commentary on connectionMask. */
void moveMouse(signed char x, signed char y, signed char wheel) {
Mouse.move(x, y, wheel);
}
void clickMouseButtons(uint8_t buttons) {
Mouse.click(buttons);
}
void pressMouseButtons(uint8_t buttons) {
Mouse.press(buttons);
}
void releaseMouseButtons(uint8_t buttons) {
Mouse.release(buttons);
}
/** Absolute mouse (grapahics tablet) events
* See above for commentary on connectionMask. */
void moveAbsoluteMouse(signed char x, signed char y, signed char wheel) {
AbsoluteMouse.move(x, y, wheel);
}
void moveAbsoluteMouseTo(uint16_t x, uint16_t y, signed char wheel) {
AbsoluteMouse.moveTo(x, y, wheel);
}
void clickAbsoluteMouseButtons(uint8_t buttons) {
AbsoluteMouse.click(buttons);
}
void pressAbsoluteMouseButtons(uint8_t buttons) {
AbsoluteMouse.press(buttons);
}
void releaseAbsoluteMouseButtons(uint8_t buttons) {
AbsoluteMouse.release(buttons);
}

@ -43,6 +43,30 @@ extern const Key keymaps[][ROWS][COLS];
*/
void handleKeyswitchEvent(Key mappedKey, byte row, byte col, uint8_t keyState);
// Internal use
/** Flushes any pending regular key switch events and sends them out */
void sendKeyboardReport();
// A facade on top of our HID implementation
void pressKey(Key mappedKey);
void releaseKey(Key mappedKey);
void releaseAllKeys();
void pressKeyRaw(Key mappedKey);
void releaseKeyRaw(Key mappedKey);
void pressConsumer(Key mappedKey);
void releaseConsumer(Key mappedKey);
void pressSystem(Key mappedKey);
void releaseSystem(Key mappedKey);
void moveMouse(signed char x, signed char y, signed char wheel);
void clickMouseButtons(uint8_t buttons);
void pressMouseButtons(uint8_t buttons);
void releaseMouseButtons(uint8_t buttons);
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);

Loading…
Cancel
Save