From 4ca7664442ea6c238e5048b364af8a32942f4286 Mon Sep 17 00:00:00 2001 From: Ben Gemperline <=> Date: Wed, 23 Aug 2017 22:11:19 -0600 Subject: [PATCH] Updated variable naming to fit style guide and fixed compilation error in example file --- README.md | 16 +++---- examples/SpaceCadet/SpaceCadet.ino | 12 ++--- src/Kaleidoscope/SpaceCadet.cpp | 70 +++++++++++++----------------- src/Kaleidoscope/SpaceCadet.h | 11 ++--- 4 files changed, 47 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 844ddafe..24afbad1 100644 --- a/README.md +++ b/README.md @@ -68,15 +68,15 @@ passing a new keymap into the SpaceCadet object, as shown below: void setup() { Kaleidoscope.use(&SpaceCadet); - //Set the keymap + //Set the keymap with a 250ms timeout per-key static kaleidoscope::ModifierKeyMap spacecadetmap[] = { {Key_LeftShift, Key_LeftParen, 250} ,{Key_RightShift, Key_RightParen, 250} - ,{Key_LeftGui,Key_LeftCurlyBracket,250} - ,{Key_RightAlt,Key_RightCurlyBracket,250} - ,{Key_LeftAlt,Key_RightCurlyBracket,250} - ,{Key_LeftControl,Key_LeftBracket,250} - ,{Key_RightControl,Key_RightBracket,250} + ,{Key_LeftGui, Key_LeftCurlyBracket, 250} + ,{Key_RightAlt, Key_RightCurlyBracket, 250} + ,{Key_LeftAlt, Key_RightCurlyBracket, 250} + ,{Key_LeftControl, Key_LeftBracket, 250} + ,{Key_RightControl, Key_RightBracket, 250} }; //Tell SpaceCadet to use the map 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. [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 diff --git a/examples/SpaceCadet/SpaceCadet.ino b/examples/SpaceCadet/SpaceCadet.ino index 113eaadc..7faace6e 100644 --- a/examples/SpaceCadet/SpaceCadet.ino +++ b/examples/SpaceCadet/SpaceCadet.ino @@ -41,18 +41,18 @@ const Key keymaps[][ROWS][COLS] PROGMEM = { void setup() { //Tell Kaleidoscope to use SpaceCadet - Kaleidoscope.use(&SpaceCadet; + Kaleidoscope.use(&SpaceCadet); //Set the SpaceCadet map //Setting is {KeyThatWasPressed, AlternativeKeyToSend, TimeoutInMS} static kaleidoscope::ModifierKeyMap spacecadetmap[] = { {Key_LeftShift, Key_LeftParen, 250} ,{Key_RightShift, Key_RightParen, 250} - ,{Key_LeftGui,Key_LeftCurlyBracket,250} - ,{Key_RightAlt,Key_RightCurlyBracket,250} - ,{Key_LeftAlt,Key_RightCurlyBracket,250} - ,{Key_LeftControl,Key_LeftBracket,250} - ,{Key_RightControl,Key_RightBracket,250} + ,{Key_LeftGui, Key_LeftCurlyBracket, 250} + ,{Key_RightAlt, Key_RightCurlyBracket, 250} + ,{Key_LeftAlt, Key_RightCurlyBracket, 250} + ,{Key_LeftControl, Key_LeftBracket, 250} + ,{Key_RightControl, Key_RightBracket, 250} }; //Set the map and the number of entries SpaceCadet.setMap(spacecadetmap, sizeof(spacecadetmap)/sizeof(spacecadetmap[0])); diff --git a/src/Kaleidoscope/SpaceCadet.cpp b/src/Kaleidoscope/SpaceCadet.cpp index e1caa680..cc1c8018 100644 --- a/src/Kaleidoscope/SpaceCadet.cpp +++ b/src/Kaleidoscope/SpaceCadet.cpp @@ -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 . - * - * Modified by Ben Gemperline to support additional keys and dynamic - * key mappings. */ #include @@ -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; diff --git a/src/Kaleidoscope/SpaceCadet.h b/src/Kaleidoscope/SpaceCadet.h index 62af27c2..89146f21 100644 --- a/src/Kaleidoscope/SpaceCadet.h +++ b/src/Kaleidoscope/SpaceCadet.h @@ -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 @@ -48,9 +48,6 @@ namespace kaleidoscope { //Empty constructor SpaceCadet(void); - //Constructor with mapping - SpaceCadet(ModifierKeyMap * map, uint8_t map_size); - //Methods void setMap(ModifierKeyMap * map, uint8_t map_size); void begin(void) final; @@ -58,8 +55,8 @@ namespace kaleidoscope { static uint16_t time_out; private: - static uint8_t map_size; - static ModifierKeyMap * map; + static uint8_t map_size_; + static ModifierKeyMap * map_; static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state); }; };