|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
/* -*- mode: c++ -*-
|
|
|
|
|
* Kaleidoscope-SpaceCadet -- Space Cadet Shift
|
|
|
|
|
* Copyright (C) 2016, 2017 Gergely Nagy
|
|
|
|
|
* Kaleidoscope-SpaceCadet -- Space Cadet Shift Extended
|
|
|
|
|
* Copyright (C) 2016, 2017 Gergely Nagy, Ben Gemperline
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
@ -14,9 +14,6 @@
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* Modified by Ben Gemperline to support additional keys and dynamic
|
|
|
|
|
* key mappings.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <Kaleidoscope-SpaceCadet.h>
|
|
|
|
@ -42,16 +39,17 @@ namespace kaleidoscope {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Space Cadet
|
|
|
|
|
uint8_t SpaceCadet::map_size = 0;
|
|
|
|
|
ModifierKeyMap * SpaceCadet::map;
|
|
|
|
|
uint8_t SpaceCadet::map_size_ = 0;
|
|
|
|
|
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[] = {
|
|
|
|
|
{Key_LeftShift,Key_LeftParen,250}
|
|
|
|
|
,{Key_RightShift,Key_RightParen,250}
|
|
|
|
|
//By default, respect the default timeout
|
|
|
|
|
{Key_LeftShift, Key_LeftParen, 0}
|
|
|
|
|
,{Key_RightShift, Key_RightParen, 0}
|
|
|
|
|
//These may be uncommented, added, or set in the main sketch
|
|
|
|
|
/*,{Key_LeftGui,Key_LeftCurlyBracket,250}
|
|
|
|
|
,{Key_RightAlt,Key_RightCurlyBracket,250}
|
|
|
|
@ -60,22 +58,16 @@ namespace kaleidoscope {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//Set the variables to our internal map
|
|
|
|
|
map = internalMap;
|
|
|
|
|
map_size = sizeof(internalMap)/sizeof(internalMap[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Constructor with map and map size
|
|
|
|
|
SpaceCadet::SpaceCadet(ModifierKeyMap * map_, uint8_t map_size_) {
|
|
|
|
|
//Call the initializer
|
|
|
|
|
setMap(map_, map_size_);
|
|
|
|
|
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_){
|
|
|
|
|
void SpaceCadet::setMap(ModifierKeyMap * map, uint8_t map_size){
|
|
|
|
|
//Set the map
|
|
|
|
|
map = map_;
|
|
|
|
|
map_ = map;
|
|
|
|
|
//set the map size to be the length of the array
|
|
|
|
|
map_size = map_size_;
|
|
|
|
|
map_size_ = map_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpaceCadet::begin() {
|
|
|
|
@ -92,18 +84,18 @@ namespace kaleidoscope {
|
|
|
|
|
// If a key has been just toggled on...
|
|
|
|
|
if (keyToggledOn(key_state)) {
|
|
|
|
|
|
|
|
|
|
if(map_size > 0) {
|
|
|
|
|
if(map_size_ > 0) {
|
|
|
|
|
//This will only set one key, and if it isn't in our map it clears everything
|
|
|
|
|
//for the non-pressed key
|
|
|
|
|
for (uint8_t i = 0; i < map_size; ++i) {
|
|
|
|
|
if(mapped_key.raw == map[i].input.raw) {
|
|
|
|
|
for (uint8_t i = 0; i < map_size_; ++i) {
|
|
|
|
|
if(mapped_key.raw == map_[i].input.raw) {
|
|
|
|
|
//The keypress was valid and a match.
|
|
|
|
|
map[i].flagged = true;
|
|
|
|
|
map[i].start_time = millis();
|
|
|
|
|
map_[i].flagged = true;
|
|
|
|
|
map_[i].start_time = millis();
|
|
|
|
|
} else {
|
|
|
|
|
//The keypress wasn't a match.
|
|
|
|
|
map[i].flagged = false;
|
|
|
|
|
map[i].start_time = 0;
|
|
|
|
|
map_[i].flagged = false;
|
|
|
|
|
map_[i].start_time = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -118,15 +110,15 @@ namespace kaleidoscope {
|
|
|
|
|
bool pressed_key_was_valid = false;
|
|
|
|
|
uint8_t index = 0;
|
|
|
|
|
|
|
|
|
|
if(map_size > 0) {
|
|
|
|
|
if(map_size_ > 0) {
|
|
|
|
|
//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 < map_size_; ++i) {
|
|
|
|
|
|
|
|
|
|
if (map[i].flagged) {
|
|
|
|
|
if (map_[i].flagged) {
|
|
|
|
|
valid_key = true;
|
|
|
|
|
index = i;
|
|
|
|
|
}
|
|
|
|
|
if (map[i].input.raw == mapped_key.raw) {
|
|
|
|
|
if (map_[i].input.raw == mapped_key.raw) {
|
|
|
|
|
pressed_key_was_valid = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -138,17 +130,17 @@ namespace kaleidoscope {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//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(current_timeout == 0){
|
|
|
|
|
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
|
|
|
|
|
// key, but we won't need to send the alternative key in the end
|
|
|
|
|
map[index].flagged = false;
|
|
|
|
|
map[index].start_time = 0;
|
|
|
|
|
map_[index].flagged = false;
|
|
|
|
|
map_[index].start_time = 0;
|
|
|
|
|
return mapped_key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -163,8 +155,8 @@ namespace kaleidoscope {
|
|
|
|
|
// 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).
|
|
|
|
|
if (keyToggledOff(key_state)) {
|
|
|
|
|
Key pressed_key = map[index].input;
|
|
|
|
|
Key alternate_key = map[index].output;
|
|
|
|
|
Key pressed_key = map_[index].input;
|
|
|
|
|
Key alternate_key = map_[index].output;
|
|
|
|
|
|
|
|
|
|
//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
|
|
|
|
@ -175,8 +167,8 @@ namespace kaleidoscope {
|
|
|
|
|
hid::sendKeyboardReport();
|
|
|
|
|
|
|
|
|
|
//Unflag the key so we don't try this again.
|
|
|
|
|
map[index].flagged = false;
|
|
|
|
|
map[index].start_time = 0;
|
|
|
|
|
map_[index].flagged = false;
|
|
|
|
|
map_[index].start_time = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return mapped_key;
|
|
|
|
|