Merge pull request #19 from keyboardio/f/plugin-v2

Updated to use the new plugin APIs
pull/365/head
Gergely Nagy 7 years ago committed by GitHub
commit 6efbc3b780
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -34,9 +34,9 @@ illustrated with an example:
Key_mouseUp, Key_mouseDn, Key_mouseL, Key_mouseR,
Key_mouseBtnL, Key_mouseBtnR
void setup() {
Kaleidoscope.use(&MouseKeys);
KALEIDOSCOPE_INIT_PLUGINS(MouseKeys);
void setup() {
Kaleidoscope.setup ();
}
```
@ -121,15 +121,15 @@ As described above, MouseKeys warps the pointer using a grid model that reflects
locations on the screen. By default, the plugin uses a 2x2 grid. To understand
how warping works, examine this diagram of a screen split into that 2x2 grid:
+-----------------------+-----------------------+
+-----------------------|-----------------------+
| | | |
| G | tab | |
| | | |
|-----------+-----------| tab |
|-----------|-----------| tab |
| | | |
| B | esc | |
| | | |
+-----------------------+-----------------------+
+-----------------------|-----------------------+
| | |
| | |
| | |
@ -137,7 +137,7 @@ how warping works, examine this diagram of a screen split into that 2x2 grid:
| | |
| | |
| | |
+-----------------------+-----------------------+
+-----------------------|-----------------------+
Each quadrant is labed with a key that, when pressed, moves the mouse pointer
to the center of that quadrant. With this layout, pressing <kbd>G</kbd> warps
@ -162,33 +162,33 @@ diagram shows a screen with a key label that warps to each sector. As we can
see, pressing <kbd>W</kbd> warps the pointer into the top-left sector, and
pressing <kbd>V</kbd> warps to the bottom-right corner within that sector:
+-----------------+-----------------+-----------------+
+-----------------|-----------------|-----------------+
| W | E | R | | |
|-----+-----+-----| | |
|-----|-----|-----| | |
| S | D | F | E | R |
|-----+-----+-----| | |
|-----|-----|-----| | |
| X | C | V | | |
+-----------------+-----------------+-----------------+
+-----------------|-----------------|-----------------+
| | | |
| | | |
| S | D | F |
| | | |
| | | |
+-----------------+-----------------+-----------------+
+-----------------|-----------------|-----------------+
| | | |
| | | |
| X | C | V |
| | | |
| | | |
+-----------------+-----------------+-----------------+
+-----------------|-----------------|-----------------+
To use a 3x3 warp grid, we may need to remap some keys. A suggested warp key
mapping is shown below on the left side of a keyboard with a QWERTY layout:
W | E | R T A - End Warping (Key_mouseWarpEnd)
---+---+--- W - Warp NW Sector (Key_mouseWarpNW)
---|---|--- W - Warp NW Sector (Key_mouseWarpNW)
A S | D | F G E - Warp N Sector (Key_mouseWarpN)
---+---+--- R - Warp NE Sector (Key_mouseWarpNE)
---|---|--- R - Warp NE Sector (Key_mouseWarpNE)
X | C | V B S - Warp E Sector (Key_mouseWarpE)
D - Warp/Zoom Center (Key_mouseWarpIn)
F - Warp W Sector (Key_mouseWarpW)

@ -39,23 +39,24 @@ void MouseKeys_::scrollWheel(uint8_t keyCode) {
kaleidoscope::hid::moveMouse(0, 0, 0, wheelSpeed);
}
void MouseKeys_::loopHook(bool postClear) {
if (postClear) {
kaleidoscope::EventHandlerResult MouseKeys_::afterEachCycle() {
kaleidoscope::hid::sendMouseReport();
kaleidoscope::hid::releaseAllMouseButtons();
mouseMoveIntent = 0;
return;
return kaleidoscope::EventHandlerResult::OK;
}
kaleidoscope::EventHandlerResult MouseKeys_::beforeReportingState() {
if (mouseMoveIntent == 0) {
MouseWrapper.accelStep = 0;
endTime = 0;
accelEndTime = 0;
return;
return kaleidoscope::EventHandlerResult::OK;
}
if (millis() < endTime)
return;
return kaleidoscope::EventHandlerResult::OK;
endTime = millis() + speedDelay;
@ -79,11 +80,13 @@ void MouseKeys_::loopHook(bool postClear) {
moveX = speed;
MouseWrapper.move(moveX, moveY);
return kaleidoscope::EventHandlerResult::OK;
}
Key MouseKeys_::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
kaleidoscope::EventHandlerResult MouseKeys_::onKeyswitchEvent(Key &mappedKey, byte row, byte col, uint8_t keyState) {
if (mappedKey.flags != (SYNTHETIC | IS_MOUSE_KEY))
return mappedKey;
return kaleidoscope::EventHandlerResult::OK;
if (mappedKey.keyCode & KEY_MOUSE_BUTTON && !(mappedKey.keyCode & KEY_MOUSE_WARP)) {
uint8_t button = mappedKey.keyCode & ~KEY_MOUSE_BUTTON;
@ -122,17 +125,37 @@ Key MouseKeys_::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyS
}
}
return Key_NoKey;
return kaleidoscope::EventHandlerResult::EVENT_CONSUMED;
}
kaleidoscope::EventHandlerResult MouseKeys_::onSetup(void) {
MouseWrapper.begin();
return kaleidoscope::EventHandlerResult::OK;
}
MouseKeys_::MouseKeys_(void) {
// Legacy V1 API
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void MouseKeys_::begin() {
onSetup();
Kaleidoscope.useEventHandlerHook(legacyEventHandler);
Kaleidoscope.useLoopHook(legacyLoopHook);
}
void
MouseKeys_::begin(void) {
MouseWrapper.begin();
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
Kaleidoscope.useLoopHook(loopHook);
Key MouseKeys_::legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state) {
kaleidoscope::EventHandlerResult r = MouseKeys.onKeyswitchEvent(mapped_key, row, col, key_state);
if (r == kaleidoscope::EventHandlerResult::OK)
return mapped_key;
return Key_NoKey;
}
void MouseKeys_::legacyLoopHook(bool is_post_clear) {
if (is_post_clear) {
MouseKeys.afterEachCycle();
} else {
MouseKeys.beforeReportingState();
}
}
#endif
MouseKeys_ MouseKeys;

@ -4,11 +4,9 @@
#include "MouseKeyDefs.h"
#include "MouseWarpModes.h"
class MouseKeys_ : public KaleidoscopePlugin {
class MouseKeys_ : public kaleidoscope::Plugin {
public:
MouseKeys_(void);
void begin(void) final;
MouseKeys_(void) {}
static uint8_t speed;
static uint16_t speedDelay;
@ -19,6 +17,18 @@ class MouseKeys_ : public KaleidoscopePlugin {
static void setWarpGridSize(uint8_t grid_size);
kaleidoscope::EventHandlerResult onSetup();
kaleidoscope::EventHandlerResult beforeReportingState();
kaleidoscope::EventHandlerResult afterEachCycle();
kaleidoscope::EventHandlerResult onKeyswitchEvent(Key &mappedKey, byte row, byte col, uint8_t keyState);
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
protected:
void begin();
static Key legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state);
static void legacyLoopHook(bool is_post_clear);
#endif
private:
static uint8_t mouseMoveIntent;
static uint32_t endTime;
@ -26,8 +36,6 @@ class MouseKeys_ : public KaleidoscopePlugin {
static uint32_t wheelEndTime;
static void scrollWheel(uint8_t keyCode);
static void loopHook(bool postClear);
static Key eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState);
};
extern MouseKeys_ MouseKeys;

Loading…
Cancel
Save