Updated to use the new plugin APIs

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/365/head
Gergely Nagy 7 years ago
parent 2130521b6d
commit 0bd1711371

@ -34,9 +34,9 @@ illustrated with an example:
Key_mouseUp, Key_mouseDn, Key_mouseL, Key_mouseR, Key_mouseUp, Key_mouseDn, Key_mouseL, Key_mouseR,
Key_mouseBtnL, Key_mouseBtnR Key_mouseBtnL, Key_mouseBtnR
void setup() { KALEIDOSCOPE_INIT_PLUGINS(MouseKeys);
Kaleidoscope.use(&MouseKeys);
void setup() {
Kaleidoscope.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 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: how warping works, examine this diagram of a screen split into that 2x2 grid:
+-----------------------+-----------------------+ +-----------------------|-----------------------+
| | | | | | | |
| G | tab | | | G | tab | |
| | | | | | | |
|-----------+-----------| tab | |-----------|-----------| tab |
| | | | | | | |
| B | esc | | | 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 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 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 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: pressing <kbd>V</kbd> warps to the bottom-right corner within that sector:
+-----------------+-----------------+-----------------+ +-----------------|-----------------|-----------------+
| W | E | R | | | | W | E | R | | |
|-----+-----+-----| | | |-----|-----|-----| | |
| S | D | F | E | R | | S | D | F | E | R |
|-----+-----+-----| | | |-----|-----|-----| | |
| X | C | V | | | | X | C | V | | |
+-----------------+-----------------+-----------------+ +-----------------|-----------------|-----------------+
| | | | | | | |
| | | | | | | |
| S | D | F | | S | D | F |
| | | | | | | |
| | | | | | | |
+-----------------+-----------------+-----------------+ +-----------------|-----------------|-----------------+
| | | | | | | |
| | | | | | | |
| X | C | V | | X | C | V |
| | | | | | | |
| | | | | | | |
+-----------------+-----------------+-----------------+ +-----------------|-----------------|-----------------+
To use a 3x3 warp grid, we may need to remap some keys. A suggested warp key 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: 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 | 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) 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) X | C | V B S - Warp E Sector (Key_mouseWarpE)
D - Warp/Zoom Center (Key_mouseWarpIn) D - Warp/Zoom Center (Key_mouseWarpIn)
F - Warp W Sector (Key_mouseWarpW) F - Warp W Sector (Key_mouseWarpW)

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

@ -4,11 +4,9 @@
#include "MouseKeyDefs.h" #include "MouseKeyDefs.h"
#include "MouseWarpModes.h" #include "MouseWarpModes.h"
class MouseKeys_ : public KaleidoscopePlugin { class MouseKeys_ : public kaleidoscope::Plugin {
public: public:
MouseKeys_(void); MouseKeys_(void) {}
void begin(void) final;
static uint8_t speed; static uint8_t speed;
static uint16_t speedDelay; static uint16_t speedDelay;
@ -19,6 +17,18 @@ class MouseKeys_ : public KaleidoscopePlugin {
static void setWarpGridSize(uint8_t grid_size); 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: private:
static uint8_t mouseMoveIntent; static uint8_t mouseMoveIntent;
static uint32_t endTime; static uint32_t endTime;
@ -26,8 +36,6 @@ class MouseKeys_ : public KaleidoscopePlugin {
static uint32_t wheelEndTime; static uint32_t wheelEndTime;
static void scrollWheel(uint8_t keyCode); 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; extern MouseKeys_ MouseKeys;

Loading…
Cancel
Save