Updated variable naming to fit style guide and fixed compilation error in example file

pull/389/head
Ben Gemperline 7 years ago
parent 7808eba436
commit 4ca7664442

@ -68,15 +68,15 @@ passing a new keymap into the SpaceCadet object, as shown below:
void setup() { void setup() {
Kaleidoscope.use(&SpaceCadet); Kaleidoscope.use(&SpaceCadet);
//Set the keymap //Set the keymap with a 250ms timeout per-key
static kaleidoscope::ModifierKeyMap spacecadetmap[] = { static kaleidoscope::ModifierKeyMap spacecadetmap[] = {
{Key_LeftShift, Key_LeftParen, 250} {Key_LeftShift, Key_LeftParen, 250}
,{Key_RightShift, Key_RightParen, 250} ,{Key_RightShift, Key_RightParen, 250}
,{Key_LeftGui,Key_LeftCurlyBracket,250} ,{Key_LeftGui, Key_LeftCurlyBracket, 250}
,{Key_RightAlt,Key_RightCurlyBracket,250} ,{Key_RightAlt, Key_RightCurlyBracket, 250}
,{Key_LeftAlt,Key_RightCurlyBracket,250} ,{Key_LeftAlt, Key_RightCurlyBracket, 250}
,{Key_LeftControl,Key_LeftBracket,250} ,{Key_LeftControl, Key_LeftBracket, 250}
,{Key_RightControl,Key_RightBracket,250} ,{Key_RightControl, Key_RightBracket, 250}
}; };
//Tell SpaceCadet to use the map //Tell SpaceCadet to use the map
SpaceCadet.setMap(spacecadetmap, sizeof(spacecadetmap)/sizeof(spacecadetmap[0])); SpaceCadet.setMap(spacecadetmap, sizeof(spacecadetmap)/sizeof(spacecadetmap[0]));
@ -123,7 +123,3 @@ Starting from the [example][plugin:example] is the recommended way of getting
started with the plugin. started with the plugin.
[plugin:example]: https://github.com/keyboardio/Kaleidoscope-SpaceCadet/blob/master/examples/SpaceCadet/SpaceCadet.ino [plugin:example]: https://github.com/keyboardio/Kaleidoscope-SpaceCadet/blob/master/examples/SpaceCadet/SpaceCadet.ino
or
[plugin:example]: https://github.com/advisoray/Kaleidoscope-SpaceCadet/blob/master/examples/SpaceCadet/SpaceCadet.ino

@ -41,18 +41,18 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
void setup() { void setup() {
//Tell Kaleidoscope to use SpaceCadet //Tell Kaleidoscope to use SpaceCadet
Kaleidoscope.use(&SpaceCadet; Kaleidoscope.use(&SpaceCadet);
//Set the SpaceCadet map //Set the SpaceCadet map
//Setting is {KeyThatWasPressed, AlternativeKeyToSend, TimeoutInMS} //Setting is {KeyThatWasPressed, AlternativeKeyToSend, TimeoutInMS}
static kaleidoscope::ModifierKeyMap spacecadetmap[] = { static kaleidoscope::ModifierKeyMap spacecadetmap[] = {
{Key_LeftShift, Key_LeftParen, 250} {Key_LeftShift, Key_LeftParen, 250}
,{Key_RightShift, Key_RightParen, 250} ,{Key_RightShift, Key_RightParen, 250}
,{Key_LeftGui,Key_LeftCurlyBracket,250} ,{Key_LeftGui, Key_LeftCurlyBracket, 250}
,{Key_RightAlt,Key_RightCurlyBracket,250} ,{Key_RightAlt, Key_RightCurlyBracket, 250}
,{Key_LeftAlt,Key_RightCurlyBracket,250} ,{Key_LeftAlt, Key_RightCurlyBracket, 250}
,{Key_LeftControl,Key_LeftBracket,250} ,{Key_LeftControl, Key_LeftBracket, 250}
,{Key_RightControl,Key_RightBracket,250} ,{Key_RightControl, Key_RightBracket, 250}
}; };
//Set the map and the number of entries //Set the map and the number of entries
SpaceCadet.setMap(spacecadetmap, sizeof(spacecadetmap)/sizeof(spacecadetmap[0])); SpaceCadet.setMap(spacecadetmap, sizeof(spacecadetmap)/sizeof(spacecadetmap[0]));

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-SpaceCadet -- Space Cadet Shift * Kaleidoscope-SpaceCadet -- Space Cadet Shift Extended
* Copyright (C) 2016, 2017 Gergely Nagy * Copyright (C) 2016, 2017 Gergely Nagy, Ben Gemperline
* *
* This program is free software: you can redistribute it and/or modify * 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 * 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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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> #include <Kaleidoscope-SpaceCadet.h>
@ -42,16 +39,17 @@ namespace kaleidoscope {
} }
//Space Cadet //Space Cadet
uint8_t SpaceCadet::map_size = 0; uint8_t SpaceCadet::map_size_ = 0;
ModifierKeyMap * SpaceCadet::map; ModifierKeyMap * SpaceCadet::map_;
uint16_t SpaceCadet::time_out = 1000; uint16_t SpaceCadet::time_out = 1000;
//Empty constructor //Empty constructor
SpaceCadet::SpaceCadet() { SpaceCadet::SpaceCadet() {
//By default, we make one with left shift sending left paren, and right shift sending right paren //By default, we make one with left shift sending left paren, and right shift sending right paren
static ModifierKeyMap internalMap[] = { static ModifierKeyMap internalMap[] = {
{Key_LeftShift,Key_LeftParen,250} //By default, respect the default timeout
,{Key_RightShift,Key_RightParen,250} {Key_LeftShift, Key_LeftParen, 0}
,{Key_RightShift, Key_RightParen, 0}
//These may be uncommented, added, or set in the main sketch //These may be uncommented, added, or set in the main sketch
/*,{Key_LeftGui,Key_LeftCurlyBracket,250} /*,{Key_LeftGui,Key_LeftCurlyBracket,250}
,{Key_RightAlt,Key_RightCurlyBracket,250} ,{Key_RightAlt,Key_RightCurlyBracket,250}
@ -60,22 +58,16 @@ namespace kaleidoscope {
}; };
//Set the variables to our internal map //Set the variables to our internal map
map = internalMap; map_ = internalMap;
map_size = sizeof(internalMap)/sizeof(internalMap[0]); 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_);
} }
//Void function to reset the modifier map if desired. //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 //Set the map
map = map_; map_ = map;
//set the map size to be the length of the array //set the map size to be the length of the array
map_size = map_size_; map_size_ = map_size;
} }
void SpaceCadet::begin() { void SpaceCadet::begin() {
@ -92,18 +84,18 @@ namespace kaleidoscope {
// 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) { 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 < map_size_; ++i) {
if(mapped_key.raw == map[i].input.raw) { 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;
} }
} }
} }
@ -118,15 +110,15 @@ namespace kaleidoscope {
bool pressed_key_was_valid = false; bool pressed_key_was_valid = false;
uint8_t index = 0; uint8_t index = 0;
if(map_size > 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 < map_size_; ++i) {
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;
} }
} }
@ -138,17 +130,17 @@ namespace kaleidoscope {
} }
//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;
} }
@ -163,8 +155,8 @@ namespace kaleidoscope {
// 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 pressed_key = map[index].input; Key pressed_key = map_[index].input;
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
@ -175,8 +167,8 @@ namespace kaleidoscope {
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;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-SpaceCadet -- Space Cadet Shift * Kaleidoscope-SpaceCadet -- Space Cadet Shift Extended
* Copyright (C) 2016, 2017 Gergely Nagy * Copyright (C) 2016, 2017 Gergely Nagy, Ben Gemperline
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -48,9 +48,6 @@ namespace kaleidoscope {
//Empty constructor //Empty constructor
SpaceCadet(void); SpaceCadet(void);
//Constructor with mapping
SpaceCadet(ModifierKeyMap * map, uint8_t map_size);
//Methods //Methods
void setMap(ModifierKeyMap * map, uint8_t map_size); void setMap(ModifierKeyMap * map, uint8_t map_size);
void begin(void) final; void begin(void) final;
@ -58,8 +55,8 @@ namespace kaleidoscope {
static uint16_t time_out; static uint16_t time_out;
private: private:
static uint8_t map_size; static uint8_t map_size_;
static ModifierKeyMap * map; static ModifierKeyMap * map_;
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state); static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
}; };
}; };

Loading…
Cancel
Save