|
|
@ -20,86 +20,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
namespace KaleidoscopePlugins {
|
|
|
|
namespace KaleidoscopePlugins {
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t SpaceCadetShift::parenNeeded;
|
|
|
|
uint8_t SpaceCadetShift::parenNeeded;
|
|
|
|
uint32_t SpaceCadetShift::startTime;
|
|
|
|
uint32_t SpaceCadetShift::startTime;
|
|
|
|
uint16_t SpaceCadetShift::timeOut = 1000;
|
|
|
|
uint16_t SpaceCadetShift::timeOut = 1000;
|
|
|
|
Key SpaceCadetShift::leftParen, SpaceCadetShift::rightParen;
|
|
|
|
Key SpaceCadetShift::leftParen, SpaceCadetShift::rightParen;
|
|
|
|
|
|
|
|
|
|
|
|
SpaceCadetShift::SpaceCadetShift () {
|
|
|
|
SpaceCadetShift::SpaceCadetShift () {
|
|
|
|
leftParen.raw = Key_9.raw;
|
|
|
|
leftParen.raw = Key_9.raw;
|
|
|
|
rightParen.raw = Key_0.raw;
|
|
|
|
rightParen.raw = Key_0.raw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
SpaceCadetShift::begin () {
|
|
|
|
SpaceCadetShift::begin () {
|
|
|
|
event_handler_hook_use (this->eventHandlerHook);
|
|
|
|
event_handler_hook_use (this->eventHandlerHook);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
SpaceCadetShift::configure (Key left, Key right) {
|
|
|
|
SpaceCadetShift::configure (Key left, Key right) {
|
|
|
|
leftParen = left;
|
|
|
|
leftParen = left;
|
|
|
|
rightParen = right;
|
|
|
|
rightParen = right;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Key
|
|
|
|
Key
|
|
|
|
SpaceCadetShift::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) {
|
|
|
|
SpaceCadetShift::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) {
|
|
|
|
// If nothing happened, bail out fast.
|
|
|
|
// If nothing happened, bail out fast.
|
|
|
|
if (!key_is_pressed (keyState) && !key_was_pressed (keyState)) {
|
|
|
|
if (!key_is_pressed (keyState) && !key_was_pressed (keyState)) {
|
|
|
|
return mappedKey;
|
|
|
|
return mappedKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If a key has been just toggled on...
|
|
|
|
// If a key has been just toggled on...
|
|
|
|
if (key_toggled_on (keyState)) {
|
|
|
|
if (key_toggled_on (keyState)) {
|
|
|
|
if (mappedKey.raw == Key_LeftShift.raw) { // if it is LShift, remember it
|
|
|
|
if (mappedKey.raw == Key_LeftShift.raw) { // if it is LShift, remember it
|
|
|
|
bitWrite (parenNeeded, 0, 1);
|
|
|
|
bitWrite (parenNeeded, 0, 1);
|
|
|
|
startTime = millis ();
|
|
|
|
startTime = millis ();
|
|
|
|
} else if (mappedKey.raw == Key_RightShift.raw) { // if it is RShift, remember it
|
|
|
|
} else if (mappedKey.raw == Key_RightShift.raw) { // if it is RShift, remember it
|
|
|
|
bitWrite (parenNeeded, 1, 1);
|
|
|
|
bitWrite (parenNeeded, 1, 1);
|
|
|
|
startTime = millis ();
|
|
|
|
startTime = millis ();
|
|
|
|
} else { // if it is something else, we do not need a paren at the end.
|
|
|
|
} else { // if it is something else, we do not need a paren at the end.
|
|
|
|
parenNeeded = 0;
|
|
|
|
parenNeeded = 0;
|
|
|
|
startTime = 0;
|
|
|
|
startTime = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// this is all we need to do on keypress, let the next handler do its thing too.
|
|
|
|
// this is all we need to do on keypress, let the next handler do its thing too.
|
|
|
|
return mappedKey;
|
|
|
|
return mappedKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if the state is empty, that means that either the shifts weren't pressed,
|
|
|
|
// if the state is empty, that means that either the shifts weren't pressed,
|
|
|
|
// or we used another key in the interim. in both cases, nothing special to do.
|
|
|
|
// or we used another key in the interim. in both cases, nothing special to do.
|
|
|
|
if (!parenNeeded)
|
|
|
|
if (!parenNeeded)
|
|
|
|
return mappedKey;
|
|
|
|
return mappedKey;
|
|
|
|
|
|
|
|
|
|
|
|
// if we timed out, that means we need to keep pressing shift, but won't
|
|
|
|
// if we timed out, that means we need to keep pressing shift, but won't
|
|
|
|
// need the parens in the end.
|
|
|
|
// need the parens in the end.
|
|
|
|
if ((millis () - startTime) >= timeOut) {
|
|
|
|
if ((millis () - startTime) >= timeOut) {
|
|
|
|
parenNeeded = 0;
|
|
|
|
parenNeeded = 0;
|
|
|
|
return mappedKey;
|
|
|
|
return mappedKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if we have a state, but the key in question is not either of the shifts,
|
|
|
|
// if we have a state, but the key in question is not either of the shifts,
|
|
|
|
// return. This can happen when another key is released, and that should not
|
|
|
|
// return. This can happen when another key is released, and that should not
|
|
|
|
// interrupt us.
|
|
|
|
// interrupt us.
|
|
|
|
if (mappedKey.raw != Key_LeftShift.raw &&
|
|
|
|
if (mappedKey.raw != Key_LeftShift.raw &&
|
|
|
|
mappedKey.raw != Key_RightShift.raw)
|
|
|
|
mappedKey.raw != Key_RightShift.raw)
|
|
|
|
return mappedKey;
|
|
|
|
return mappedKey;
|
|
|
|
|
|
|
|
|
|
|
|
// if a key toggled off (and that must be one of the shifts at this point),
|
|
|
|
// if a key toggled off (and that must be one of the shifts at this point),
|
|
|
|
// send the parens too (if we were interrupted, we bailed out earlier).
|
|
|
|
// send the parens too (if we were interrupted, we bailed out earlier).
|
|
|
|
if (key_toggled_off (keyState)) {
|
|
|
|
if (key_toggled_off (keyState)) {
|
|
|
|
Key paren = leftParen;
|
|
|
|
Key paren = leftParen;
|
|
|
|
if (bitRead (parenNeeded, 1))
|
|
|
|
if (bitRead (parenNeeded, 1))
|
|
|
|
paren = rightParen;
|
|
|
|
paren = rightParen;
|
|
|
|
|
|
|
|
|
|
|
|
handle_keyswitch_event (mappedKey, row, col, IS_PRESSED | INJECTED);
|
|
|
|
handle_keyswitch_event (mappedKey, row, col, IS_PRESSED | INJECTED);
|
|
|
|
handle_keyswitch_event (paren, row, col, IS_PRESSED | INJECTED);
|
|
|
|
handle_keyswitch_event (paren, row, col, IS_PRESSED | INJECTED);
|
|
|
|
Keyboard.sendReport ();
|
|
|
|
Keyboard.sendReport ();
|
|
|
|
|
|
|
|
|
|
|
|
parenNeeded = 0;
|
|
|
|
parenNeeded = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return mappedKey;
|
|
|
|
return mappedKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|