|
|
@ -21,21 +21,21 @@
|
|
|
|
using namespace KaleidoscopePlugins::Ranges;
|
|
|
|
using namespace KaleidoscopePlugins::Ranges;
|
|
|
|
|
|
|
|
|
|
|
|
namespace KaleidoscopePlugins {
|
|
|
|
namespace KaleidoscopePlugins {
|
|
|
|
// ---- state ---------
|
|
|
|
// ---- state ---------
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t OneShot::startTime = 0;
|
|
|
|
uint32_t OneShot::startTime = 0;
|
|
|
|
uint16_t OneShot::timeOut = 2500;
|
|
|
|
uint16_t OneShot::timeOut = 2500;
|
|
|
|
uint16_t OneShot::holdTimeOut = 250;
|
|
|
|
uint16_t OneShot::holdTimeOut = 250;
|
|
|
|
OneShot::state_t OneShot::State;
|
|
|
|
OneShot::state_t OneShot::State;
|
|
|
|
OneShot::state_t OneShot::stickyState;
|
|
|
|
OneShot::state_t OneShot::stickyState;
|
|
|
|
OneShot::state_t OneShot::pressedState;
|
|
|
|
OneShot::state_t OneShot::pressedState;
|
|
|
|
uint32_t OneShot::leftMask;
|
|
|
|
uint32_t OneShot::leftMask;
|
|
|
|
uint32_t OneShot::rightMask;
|
|
|
|
uint32_t OneShot::rightMask;
|
|
|
|
Key OneShot::prevKey;
|
|
|
|
Key OneShot::prevKey;
|
|
|
|
bool OneShot::shouldCancel = false;
|
|
|
|
bool OneShot::shouldCancel = false;
|
|
|
|
bool OneShot::shouldCancelStickies = false;
|
|
|
|
bool OneShot::shouldCancelStickies = false;
|
|
|
|
|
|
|
|
|
|
|
|
// --- helper macros ------
|
|
|
|
// --- helper macros ------
|
|
|
|
|
|
|
|
|
|
|
|
#define isOS(key) (key.raw >= OS_FIRST && key.raw <= OS_LAST)
|
|
|
|
#define isOS(key) (key.raw >= OS_FIRST && key.raw <= OS_LAST)
|
|
|
|
#define isModifier(key) (key.raw >= Key_LeftControl.raw && key.raw <= Key_RightGui.raw)
|
|
|
|
#define isModifier(key) (key.raw >= Key_LeftControl.raw && key.raw <= Key_RightGui.raw)
|
|
|
@ -58,9 +58,9 @@ namespace KaleidoscopePlugins {
|
|
|
|
|
|
|
|
|
|
|
|
#define hasTimedOut() (millis () - startTime >= timeOut)
|
|
|
|
#define hasTimedOut() (millis () - startTime >= timeOut)
|
|
|
|
|
|
|
|
|
|
|
|
// ---- OneShot stuff ----
|
|
|
|
// ---- OneShot stuff ----
|
|
|
|
void
|
|
|
|
void
|
|
|
|
OneShot::injectNormalKey (uint8_t idx, uint8_t keyState) {
|
|
|
|
OneShot::injectNormalKey (uint8_t idx, uint8_t keyState) {
|
|
|
|
Key key;
|
|
|
|
Key key;
|
|
|
|
|
|
|
|
|
|
|
|
if (idx < 8) {
|
|
|
|
if (idx < 8) {
|
|
|
@ -72,21 +72,21 @@ namespace KaleidoscopePlugins {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
handle_keyswitch_event (key, UNKNOWN_KEYSWITCH_LOCATION, keyState | INJECTED);
|
|
|
|
handle_keyswitch_event (key, UNKNOWN_KEYSWITCH_LOCATION, keyState | INJECTED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
OneShot::activateOneShot (uint8_t idx) {
|
|
|
|
OneShot::activateOneShot (uint8_t idx) {
|
|
|
|
injectNormalKey (idx, IS_PRESSED);
|
|
|
|
injectNormalKey (idx, IS_PRESSED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
OneShot::cancelOneShot (uint8_t idx) {
|
|
|
|
OneShot::cancelOneShot (uint8_t idx) {
|
|
|
|
clearOneShot (idx);
|
|
|
|
clearOneShot (idx);
|
|
|
|
injectNormalKey (idx, WAS_PRESSED);
|
|
|
|
injectNormalKey (idx, WAS_PRESSED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
OneShot::mask (byte row, byte col) {
|
|
|
|
OneShot::mask (byte row, byte col) {
|
|
|
|
if (row >= ROWS || col >= COLS)
|
|
|
|
if (row >= ROWS || col >= COLS)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
@ -95,10 +95,10 @@ namespace KaleidoscopePlugins {
|
|
|
|
rightMask |= SCANBIT (row, col);
|
|
|
|
rightMask |= SCANBIT (row, col);
|
|
|
|
} else
|
|
|
|
} else
|
|
|
|
leftMask |= SCANBIT (row, col);
|
|
|
|
leftMask |= SCANBIT (row, col);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
OneShot::unmask (byte row, byte col) {
|
|
|
|
OneShot::unmask (byte row, byte col) {
|
|
|
|
if (row >= ROWS || col >= COLS)
|
|
|
|
if (row >= ROWS || col >= COLS)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
@ -107,10 +107,10 @@ namespace KaleidoscopePlugins {
|
|
|
|
rightMask &= ~(SCANBIT (row, col));
|
|
|
|
rightMask &= ~(SCANBIT (row, col));
|
|
|
|
} else
|
|
|
|
} else
|
|
|
|
leftMask &= ~(SCANBIT (row, col));
|
|
|
|
leftMask &= ~(SCANBIT (row, col));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
OneShot::isMasked (byte row, byte col) {
|
|
|
|
OneShot::isMasked (byte row, byte col) {
|
|
|
|
if (row >= ROWS || col >= COLS)
|
|
|
|
if (row >= ROWS || col >= COLS)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
@ -119,10 +119,10 @@ namespace KaleidoscopePlugins {
|
|
|
|
return rightMask & SCANBIT (row, col);
|
|
|
|
return rightMask & SCANBIT (row, col);
|
|
|
|
} else
|
|
|
|
} else
|
|
|
|
return leftMask & SCANBIT (row, col);
|
|
|
|
return leftMask & SCANBIT (row, col);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Key
|
|
|
|
Key
|
|
|
|
OneShot::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) {
|
|
|
|
OneShot::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) {
|
|
|
|
uint8_t idx;
|
|
|
|
uint8_t idx;
|
|
|
|
|
|
|
|
|
|
|
|
if (keyState & INJECTED)
|
|
|
|
if (keyState & INJECTED)
|
|
|
@ -203,10 +203,10 @@ namespace KaleidoscopePlugins {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return mappedKey;
|
|
|
|
return mappedKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
OneShot::loopHook (bool postClear) {
|
|
|
|
OneShot::loopHook (bool postClear) {
|
|
|
|
if (!State.all)
|
|
|
|
if (!State.all)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
@ -237,42 +237,42 @@ namespace KaleidoscopePlugins {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// --- glue code ---
|
|
|
|
// --- glue code ---
|
|
|
|
|
|
|
|
|
|
|
|
OneShot::OneShot (void) {
|
|
|
|
OneShot::OneShot (void) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
OneShot::begin (void) {
|
|
|
|
OneShot::begin (void) {
|
|
|
|
event_handler_hook_use (eventHandlerHook);
|
|
|
|
event_handler_hook_use (eventHandlerHook);
|
|
|
|
loop_hook_use (loopHook);
|
|
|
|
loop_hook_use (loopHook);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
OneShot::isActive (void) {
|
|
|
|
OneShot::isActive (void) {
|
|
|
|
return (State.all && !hasTimedOut ());
|
|
|
|
return (State.all && !hasTimedOut ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
OneShot::isModifierActive (Key key) {
|
|
|
|
OneShot::isModifierActive (Key key) {
|
|
|
|
if (key.raw < Key_LeftControl.raw || key.raw > Key_RightGui.raw)
|
|
|
|
if (key.raw < Key_LeftControl.raw || key.raw > Key_RightGui.raw)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
return isOneShot (key.keyCode - Key_LeftControl.keyCode);
|
|
|
|
return isOneShot (key.keyCode - Key_LeftControl.keyCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
OneShot::cancel (bool withStickies) {
|
|
|
|
OneShot::cancel (bool withStickies) {
|
|
|
|
shouldCancel = true;
|
|
|
|
shouldCancel = true;
|
|
|
|
shouldCancelStickies = withStickies;
|
|
|
|
shouldCancelStickies = withStickies;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
OneShot::inject (Key key, uint8_t keyState) {
|
|
|
|
OneShot::inject (Key key, uint8_t keyState) {
|
|
|
|
eventHandlerHook (key, 255, 255, keyState);
|
|
|
|
eventHandlerHook (key, 255, 255, keyState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|