|
|
@ -21,32 +21,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
namespace kaleidoscope {
|
|
|
|
namespace kaleidoscope {
|
|
|
|
|
|
|
|
|
|
|
|
//Default, empty constructor
|
|
|
|
|
|
|
|
ModifierKeyMap::ModifierKeyMap() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Constructor with input and output, and assume default timeout
|
|
|
|
//Constructor with input and output, and assume default timeout
|
|
|
|
ModifierKeyMap::ModifierKeyMap(Key input_, Key output_) {
|
|
|
|
SpaceCadet::KeyBinding::KeyBinding(Key input_, Key output_) {
|
|
|
|
input = input_;
|
|
|
|
input = input_;
|
|
|
|
output = output_;
|
|
|
|
output = output_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Constructor with all three set
|
|
|
|
//Constructor with all three set
|
|
|
|
ModifierKeyMap::ModifierKeyMap(Key input_, Key output_, uint16_t timeout_) {
|
|
|
|
SpaceCadet::KeyBinding::KeyBinding(Key input_, Key output_, uint16_t timeout_) {
|
|
|
|
input = input_;
|
|
|
|
input = input_;
|
|
|
|
output = output_;
|
|
|
|
output = output_;
|
|
|
|
timeout = timeout_;
|
|
|
|
timeout = timeout_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Space Cadet
|
|
|
|
//Space Cadet
|
|
|
|
uint8_t SpaceCadet::map_size_ = 0;
|
|
|
|
KeyBinding * SpaceCadet::map = {
|
|
|
|
ModifierKeyMap * SpaceCadet::map_;
|
|
|
|
|
|
|
|
uint16_t SpaceCadet::time_out = 1000;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Empty constructor
|
|
|
|
|
|
|
|
SpaceCadet::SpaceCadet() {
|
|
|
|
|
|
|
|
//By default, we make one with left shift sending left paren, and right shift sending right paren
|
|
|
|
|
|
|
|
static ModifierKeyMap internalMap[] = {
|
|
|
|
|
|
|
|
//By default, respect the default timeout
|
|
|
|
//By default, respect the default timeout
|
|
|
|
{Key_LeftShift, Key_LeftParen, 0}
|
|
|
|
{Key_LeftShift, Key_LeftParen, 0}
|
|
|
|
, {Key_RightShift, Key_RightParen, 0}
|
|
|
|
, {Key_RightShift, Key_RightParen, 0}
|
|
|
@ -55,20 +45,9 @@ SpaceCadet::SpaceCadet() {
|
|
|
|
,{Key_RightAlt,Key_RightCurlyBracket,250}
|
|
|
|
,{Key_RightAlt,Key_RightCurlyBracket,250}
|
|
|
|
,{Key_LeftControl,Key_LeftBracket,250}
|
|
|
|
,{Key_LeftControl,Key_LeftBracket,250}
|
|
|
|
,{Key_RightControl,Key_RightBracket,250}*/
|
|
|
|
,{Key_RightControl,Key_RightBracket,250}*/
|
|
|
|
};
|
|
|
|
, SPACECADET_MAP_END
|
|
|
|
|
|
|
|
};
|
|
|
|
//Set the variables to our internal map
|
|
|
|
uint16_t SpaceCadet::time_out = 1000;
|
|
|
|
map_ = internalMap;
|
|
|
|
|
|
|
|
map_size_ = sizeof(internalMap) / sizeof(internalMap[0]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Void function to reset the modifier map if desired.
|
|
|
|
|
|
|
|
void SpaceCadet::setMap(ModifierKeyMap * map, uint8_t map_size) {
|
|
|
|
|
|
|
|
//Set the map
|
|
|
|
|
|
|
|
map_ = map;
|
|
|
|
|
|
|
|
//set the map size to be the length of the array
|
|
|
|
|
|
|
|
map_size_ = map_size;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SpaceCadet::begin() {
|
|
|
|
void SpaceCadet::begin() {
|
|
|
|
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
|
|
|
|
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
|
|
|
@ -84,19 +63,26 @@ Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key
|
|
|
|
// If a key has been just toggled on...
|
|
|
|
// If a key has been just toggled on...
|
|
|
|
if (keyToggledOn(key_state)) {
|
|
|
|
if (keyToggledOn(key_state)) {
|
|
|
|
|
|
|
|
|
|
|
|
if (map_size_ > 0) {
|
|
|
|
|
|
|
|
//This will only set one key, and if it isn't in our map it clears everything
|
|
|
|
//This will only set one key, and if it isn't in our map it clears everything
|
|
|
|
//for the non-pressed key
|
|
|
|
//for the non-pressed key
|
|
|
|
for (uint8_t i = 0; i < map_size_; ++i) {
|
|
|
|
for (uint8_t i = 0 ;; ++i) {
|
|
|
|
if (mapped_key.raw == map_[i].input.raw) {
|
|
|
|
//Check for ending sentinal and exit
|
|
|
|
|
|
|
|
if(
|
|
|
|
|
|
|
|
map[i].input.raw == Key_NoKey.raw
|
|
|
|
|
|
|
|
&& map[i].output.raw == Key_NoKey.raw
|
|
|
|
|
|
|
|
&& map[i].timeout == 0
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mapped_key.raw == map[i].input.raw) {
|
|
|
|
//The keypress was valid and a match.
|
|
|
|
//The keypress was valid and a match.
|
|
|
|
map_[i].flagged = true;
|
|
|
|
map[i].flagged = true;
|
|
|
|
map_[i].start_time = millis();
|
|
|
|
map[i].start_time = millis();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
//The keypress wasn't a match.
|
|
|
|
//The keypress wasn't a match.
|
|
|
|
map_[i].flagged = false;
|
|
|
|
map[i].flagged = false;
|
|
|
|
map_[i].start_time = 0;
|
|
|
|
map[i].start_time = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -110,19 +96,27 @@ Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key
|
|
|
|
bool pressed_key_was_valid = false;
|
|
|
|
bool pressed_key_was_valid = false;
|
|
|
|
uint8_t index = 0;
|
|
|
|
uint8_t index = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (map_size_ > 0) {
|
|
|
|
|
|
|
|
//Look to see if any keys in our map are flagged
|
|
|
|
//Look to see if any keys in our map are flagged
|
|
|
|
for (uint8_t i = 0; i < map_size_; ++i) {
|
|
|
|
for (uint8_t i = 0 ;; ++i) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Check for ending sentinal and exit
|
|
|
|
|
|
|
|
if(
|
|
|
|
|
|
|
|
map[i].input.raw == Key_NoKey.raw
|
|
|
|
|
|
|
|
&& map[i].output.raw == Key_NoKey.raw
|
|
|
|
|
|
|
|
&& map[i].timeout == 0
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (map_[i].flagged) {
|
|
|
|
if (map[i].flagged) {
|
|
|
|
valid_key = true;
|
|
|
|
valid_key = true;
|
|
|
|
index = i;
|
|
|
|
index = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (map_[i].input.raw == mapped_key.raw) {
|
|
|
|
if (map[i].input.raw == mapped_key.raw) {
|
|
|
|
pressed_key_was_valid = true;
|
|
|
|
pressed_key_was_valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//If no valid mapped keys were pressed, simply return the keycode
|
|
|
|
//If no valid mapped keys were pressed, simply return the keycode
|
|
|
|
if (!valid_key) {
|
|
|
|
if (!valid_key) {
|
|
|
@ -130,17 +124,17 @@ Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//use the map index to find the local timeout for this key
|
|
|
|
//use the map index to find the local timeout for this key
|
|
|
|
uint16_t current_timeout = map_[index].timeout;
|
|
|
|
uint16_t current_timeout = map[index].timeout;
|
|
|
|
//If that isn't set, use the global timeout setting.
|
|
|
|
//If that isn't set, use the global timeout setting.
|
|
|
|
if (current_timeout == 0) {
|
|
|
|
if (current_timeout == 0) {
|
|
|
|
current_timeout = time_out;
|
|
|
|
current_timeout = time_out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((millis() - map_[index].start_time) >= current_timeout) {
|
|
|
|
if ((millis() - map[index].start_time) >= current_timeout) {
|
|
|
|
// if we timed out, that means we need to keep pressing the mapped
|
|
|
|
// if we timed out, that means we need to keep pressing the mapped
|
|
|
|
// key, but we won't need to send the alternative key in the end
|
|
|
|
// key, but we won't need to send the alternative key in the end
|
|
|
|
map_[index].flagged = false;
|
|
|
|
map[index].flagged = false;
|
|
|
|
map_[index].start_time = 0;
|
|
|
|
map[index].start_time = 0;
|
|
|
|
return mapped_key;
|
|
|
|
return mapped_key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -155,7 +149,7 @@ Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key
|
|
|
|
// if a key toggled off (and that must be one of the mapped keys at this point),
|
|
|
|
// if a key toggled off (and that must be one of the mapped keys at this point),
|
|
|
|
// send the alternative key instead (if we were interrupted, we bailed out earlier).
|
|
|
|
// send the alternative key instead (if we were interrupted, we bailed out earlier).
|
|
|
|
if (keyToggledOff(key_state)) {
|
|
|
|
if (keyToggledOff(key_state)) {
|
|
|
|
Key alternate_key = map_[index].output;
|
|
|
|
Key alternate_key = map[index].output;
|
|
|
|
|
|
|
|
|
|
|
|
//Since we are sending the actual key (no need for shift, etc),
|
|
|
|
//Since we are sending the actual key (no need for shift, etc),
|
|
|
|
//only need to send that key and not the original key. In fact, we
|
|
|
|
//only need to send that key and not the original key. In fact, we
|
|
|
@ -166,8 +160,8 @@ Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key
|
|
|
|
hid::sendKeyboardReport();
|
|
|
|
hid::sendKeyboardReport();
|
|
|
|
|
|
|
|
|
|
|
|
//Unflag the key so we don't try this again.
|
|
|
|
//Unflag the key so we don't try this again.
|
|
|
|
map_[index].flagged = false;
|
|
|
|
map[index].flagged = false;
|
|
|
|
map_[index].start_time = 0;
|
|
|
|
map[index].start_time = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return mapped_key;
|
|
|
|
return mapped_key;
|
|
|
@ -175,6 +169,4 @@ Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Note: since this is more generic, it is now simply SpaceCadet, instead of
|
|
|
|
|
|
|
|
//SpaceCadetShift
|
|
|
|
|
|
|
|
kaleidoscope::SpaceCadet SpaceCadet;
|
|
|
|
kaleidoscope::SpaceCadet SpaceCadet;
|
|
|
|