From c3348eb096333a4c15c1fc32848ddd471c1107b6 Mon Sep 17 00:00:00 2001
From: Ben Gemperline <=>
Date: Mon, 21 Aug 2017 20:19:58 -0600
Subject: [PATCH 01/16] Initial commit after changes to support multiple keys
---
src/Kaleidoscope/SpaceCadet.cpp | 250 +++++++++++++++++++++++---------
src/Kaleidoscope/SpaceCadet.h | 49 +++++--
2 files changed, 221 insertions(+), 78 deletions(-)
diff --git a/src/Kaleidoscope/SpaceCadet.cpp b/src/Kaleidoscope/SpaceCadet.cpp
index 7ee88dd1..e5bc8556 100644
--- a/src/Kaleidoscope/SpaceCadet.cpp
+++ b/src/Kaleidoscope/SpaceCadet.cpp
@@ -14,84 +14,202 @@
*
* 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.
*/
#include
#include
+#include
+#include "SpaceCadet.h"
namespace kaleidoscope {
-uint8_t SpaceCadetShift::paren_needed_;
-uint32_t SpaceCadetShift::start_time_;
-uint16_t SpaceCadetShift::time_out = 1000;
-Key SpaceCadetShift::opening_paren = Key_9, SpaceCadetShift::closing_paren = Key_0;
+ //Default constructor
+ ModifierKeyMap::ModifierKeyMap(){
+ }
-SpaceCadetShift::SpaceCadetShift() {
-}
+ //Constructor with input and output, and assume default timeout
+ ModifierKeyMap::ModifierKeyMap(Key input_, Key output_){
+ input = input_;
+ output = output_;
+ }
-void SpaceCadetShift::begin() {
- Kaleidoscope.useEventHandlerHook(eventHandlerHook);
-}
+ //Constructor with all three set
+ ModifierKeyMap::ModifierKeyMap(Key input_, Key output_, uint16_t timeout_) {
+ input = input_;
+ output = output_;
+ timeout = timeout_;
+ }
-Key SpaceCadetShift::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
- // If nothing happened, bail out fast.
- if (!keyIsPressed(key_state) && !keyWasPressed(key_state)) {
- return mapped_key;
- }
-
- // If a key has been just toggled on...
- if (keyToggledOn(key_state)) {
- if (mapped_key.raw == Key_LeftShift.raw) { // if it is LShift, remember it
- bitWrite(paren_needed_, 0, 1);
- start_time_ = millis();
- } else if (mapped_key.raw == Key_RightShift.raw) { // if it is RShift, remember it
- bitWrite(paren_needed_, 1, 1);
- start_time_ = millis();
- } else { // if it is something else, we do not need a paren at the end.
- paren_needed_ = 0;
- start_time_ = 0;
+ //Space Cadet
+ uint8_t SpaceCadet::map_size = 0;
+ ModifierKeyMap * SpaceCadet::map;
+ uint16_t SpaceCadet::time_out = 1000;
+
+ 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}
+ /*,{Key_LeftGui,Key_LeftCurlyBracket,250}
+ ,{Key_RightAlt,Key_RightCurlyBracket,250}
+ ,{Key_LeftControl,Key_LeftBracket,250}
+ ,{Key_RightControl,Key_RightBracket,250}*/
+ };
+
+ map = internalMap;
+ map_size = sizeof(internalMap)/sizeof(internalMap[0]);
+ //setMap(internalMap, sizeof(internalMap));
}
- // this is all we need to do on keypress, let the next handler do its thing too.
- return mapped_key;
- }
-
- // 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.
- if (!paren_needed_)
- return mapped_key;
-
- // if we timed out, that means we need to keep pressing shift, but won't
- // need the parens in the end.
- if ((millis() - start_time_) >= time_out) {
- paren_needed_ = 0;
- return mapped_key;
- }
-
- // 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
- // interrupt us.
- if (mapped_key.raw != Key_LeftShift.raw &&
- mapped_key.raw != Key_RightShift.raw)
- return mapped_key;
-
- // 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).
- if (keyToggledOff(key_state)) {
- Key paren = opening_paren;
- if (bitRead(paren_needed_, 1))
- paren = closing_paren;
-
- handleKeyswitchEvent(mapped_key, row, col, IS_PRESSED | INJECTED);
- handleKeyswitchEvent(paren, row, col, IS_PRESSED | INJECTED);
- hid::sendKeyboardReport();
-
- paren_needed_ = 0;
- }
-
- return mapped_key;
-}
+ SpaceCadet::SpaceCadet(ModifierKeyMap * map_, uint8_t map_size_) {
+ //Call the initializer
+ setMap(map_, map_size_);
+ }
+
+ 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() {
+ Kaleidoscope.useEventHandlerHook(eventHandlerHook);
+ }
+
+ Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
+ //char buffer[50];
+
+ //Serial.print("In eventHandlerHook");
+ // If nothing happened, bail out fast.
+ if (!keyIsPressed(key_state) && !keyWasPressed(key_state)) {
+ return mapped_key;
+ }
+
+ // If a key has been just toggled on...
+ if (keyToggledOn(key_state)) {
+
+ /*
+ sprintf(buffer, "Pressed Key: %u\n", mapped_key.raw );
+ Serial.print(buffer);
+ */
+
+ 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) {
+ map[i].flagged = true;
+ map[i].start_time = millis();
+ //There was a valid keypress
+ /*sprintf(buffer, "Valid Key: %u\n", mapped_key.raw);
+ Serial.print(buffer);*/
+
+ } else {
+ map[i].flagged = false;
+ map[i].start_time = 0;
+ }
+
+ /*
+ sprintf(buffer, "Key: %u\n", map[i].input.raw);
+ Serial.print(buffer);
+ if(map[i].flagged){
+ Serial.print("Flagged\n");
+ } else {
+ Serial.print("Not Flagged\n");
+ }
+ sprintf(buffer, "Start Time: %u\n", map[i].start_time);
+ Serial.print(buffer);
+ */
+ }
+ }
+
+ // this is all we need to do on keypress, let the next handler do its thing too.
+ return mapped_key;
+ }
+
+ // 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.
+ bool valid_key = false;
+ bool pressed_key_was_valid = false;
+ uint8_t index = 0;
+ if(map_size > 0) {
+ //Look to see if any are flagged
+ for (uint8_t i = 0; i < map_size; ++i) {
+
+ if (map[i].flagged) {
+ valid_key = true;
+ index = i;
+ }
+ if (map[i].input.raw == mapped_key.raw) {
+ pressed_key_was_valid = true;
+ }
+ }
+ }
+ if (!valid_key) {
+ return mapped_key;
+ }
+
+ //use the map index to find the local timeout for this key
+ 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 we timed out, that means we need to keep pressing shift, but won't
+ // need the parens in the end.
+ map[index].flagged = false;
+ map[index].start_time = 0;
+ return mapped_key;
+ }
+
+ /*
+ sprintf(buffer, "Check Index: %u\n", index );
+ Serial.print(buffer);
+
+ sprintf(buffer, "Current Timeout: %u\n", current_timeout );
+ Serial.print(buffer);
+
+ sprintf(buffer, "Start Time: %u\n", map[index].start_time );
+ Serial.print(buffer);
+
+ Serial.print("Made it past timeout check\n");
+ */
+
+ // 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
+ // interrupt us.
+
+ if (!pressed_key_was_valid) {
+ return mapped_key;
+ }
+
+ //Serial.print("Made it validity check\n");
+
+
+ // 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).
+ if (keyToggledOff(key_state)) {
+ Key pressed_key = map[index].input;
+ Key alternate_key = map[index].output;
+
+ //Don't necessarily need to send the original key
+ //handleKeyswitchEvent(pressed_key, row, col, WAS_PRESSED | INJECTED);
+ handleKeyswitchEvent(alternate_key, row, col, IS_PRESSED | INJECTED);
+ hid::sendKeyboardReport();
+
+ map[index].flagged = false;
+ map[index].start_time = 0;
+ }
+
+ return mapped_key;
+ }
}
-kaleidoscope::SpaceCadetShift SpaceCadetShift;
+kaleidoscope::SpaceCadet SpaceCadet;
diff --git a/src/Kaleidoscope/SpaceCadet.h b/src/Kaleidoscope/SpaceCadet.h
index 626ef573..62af27c2 100644
--- a/src/Kaleidoscope/SpaceCadet.h
+++ b/src/Kaleidoscope/SpaceCadet.h
@@ -21,22 +21,47 @@
#include
namespace kaleidoscope {
+ //Declarations for the modifier key mapping
+ class ModifierKeyMap {
+ public:
+ //Empty constructor; set the vars separately
+ ModifierKeyMap(void);
+ //Constructor with input and output
+ ModifierKeyMap(Key input_, Key output_);
+ //Constructor with all three set
+ ModifierKeyMap(Key input_, Key output_, uint16_t timeout_);
+ //The key that is pressed
+ Key input;
+ //the key that is sent
+ Key output;
+ //The timeout (default to global timeout)
+ uint16_t timeout = 0;
+ //The flag (set to 0)
+ bool flagged = false;
+ //the start time for this key press
+ uint32_t start_time = 0;
+ };
-class SpaceCadetShift : public KaleidoscopePlugin {
- public:
- SpaceCadetShift(void);
+ //Declaration for the method (implementing KaleidoscopePlugin)
+ class SpaceCadet : public KaleidoscopePlugin {
+ public:
+ //Empty constructor
+ SpaceCadet(void);
- void begin(void) final;
+ //Constructor with mapping
+ SpaceCadet(ModifierKeyMap * map, uint8_t map_size);
- static uint16_t time_out;
- static Key opening_paren, closing_paren;
+ //Methods
+ void setMap(ModifierKeyMap * map, uint8_t map_size);
+ void begin(void) final;
- private:
- static uint8_t paren_needed_;
- static uint32_t start_time_;
+ static uint16_t time_out;
- static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
-};
+ private:
+ static uint8_t map_size;
+ static ModifierKeyMap * map;
+ static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
+ };
};
-extern kaleidoscope::SpaceCadetShift SpaceCadetShift;
+extern kaleidoscope::SpaceCadet SpaceCadet;
From f3969ba614981cdcf44c9f8bd4e18a8a2d1b4b32 Mon Sep 17 00:00:00 2001
From: Ben Gemperline <=>
Date: Mon, 21 Aug 2017 20:51:04 -0600
Subject: [PATCH 02/16] Updated example file with new keymap
---
examples/SpaceCadet/SpaceCadet.ino | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/examples/SpaceCadet/SpaceCadet.ino b/examples/SpaceCadet/SpaceCadet.ino
index 4dd5c4a4..113eaadc 100644
--- a/examples/SpaceCadet/SpaceCadet.ino
+++ b/examples/SpaceCadet/SpaceCadet.ino
@@ -40,7 +40,22 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
};
void setup() {
- Kaleidoscope.use(&SpaceCadetShift);
+ //Tell Kaleidoscope to 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}
+ };
+ //Set the map and the number of entries
+ SpaceCadet.setMap(spacecadetmap, sizeof(spacecadetmap)/sizeof(spacecadetmap[0]));
Kaleidoscope.setup();
}
From fff81795873a1a7e6c9c321846b07ed5d971b006 Mon Sep 17 00:00:00 2001
From: Ben Gemperline <=>
Date: Mon, 21 Aug 2017 21:40:05 -0600
Subject: [PATCH 03/16] Updated documentation and removed debug statements and
unnecessary header files.
---
src/Kaleidoscope/SpaceCadet.cpp | 84 ++++++++++++---------------------
1 file changed, 29 insertions(+), 55 deletions(-)
diff --git a/src/Kaleidoscope/SpaceCadet.cpp b/src/Kaleidoscope/SpaceCadet.cpp
index e5bc8556..e1caa680 100644
--- a/src/Kaleidoscope/SpaceCadet.cpp
+++ b/src/Kaleidoscope/SpaceCadet.cpp
@@ -15,17 +15,16 @@
* 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.
+ * Modified by Ben Gemperline to support additional keys and dynamic
+ * key mappings.
*/
#include
#include
-#include
-#include "SpaceCadet.h"
namespace kaleidoscope {
- //Default constructor
+ //Default, empty constructor
ModifierKeyMap::ModifierKeyMap(){
}
@@ -47,27 +46,31 @@ namespace kaleidoscope {
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}
+ //These may be uncommented, added, or set in the main sketch
/*,{Key_LeftGui,Key_LeftCurlyBracket,250}
,{Key_RightAlt,Key_RightCurlyBracket,250}
,{Key_LeftControl,Key_LeftBracket,250}
,{Key_RightControl,Key_RightBracket,250}*/
};
+ //Set the variables to our internal map
map = internalMap;
map_size = sizeof(internalMap)/sizeof(internalMap[0]);
- //setMap(internalMap, sizeof(internalMap));
}
+ //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 SpaceCadet::setMap(ModifierKeyMap * map_, uint8_t map_size_){
//Set the map
map = map_;
@@ -80,9 +83,7 @@ namespace kaleidoscope {
}
Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
- //char buffer[50];
- //Serial.print("In eventHandlerHook");
// If nothing happened, bail out fast.
if (!keyIsPressed(key_state) && !keyWasPressed(key_state)) {
return mapped_key;
@@ -91,37 +92,19 @@ namespace kaleidoscope {
// If a key has been just toggled on...
if (keyToggledOn(key_state)) {
- /*
- sprintf(buffer, "Pressed Key: %u\n", mapped_key.raw );
- Serial.print(buffer);
- */
-
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
+ //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) {
+ //The keypress was valid and a match.
map[i].flagged = true;
map[i].start_time = millis();
- //There was a valid keypress
- /*sprintf(buffer, "Valid Key: %u\n", mapped_key.raw);
- Serial.print(buffer);*/
-
} else {
+ //The keypress wasn't a match.
map[i].flagged = false;
map[i].start_time = 0;
}
-
- /*
- sprintf(buffer, "Key: %u\n", map[i].input.raw);
- Serial.print(buffer);
- if(map[i].flagged){
- Serial.print("Flagged\n");
- } else {
- Serial.print("Not Flagged\n");
- }
- sprintf(buffer, "Start Time: %u\n", map[i].start_time);
- Serial.print(buffer);
- */
}
}
@@ -134,8 +117,9 @@ namespace kaleidoscope {
bool valid_key = false;
bool pressed_key_was_valid = false;
uint8_t index = 0;
+
if(map_size > 0) {
- //Look to see if any are flagged
+ //Look to see if any keys in our map are flagged
for (uint8_t i = 0; i < map_size; ++i) {
if (map[i].flagged) {
@@ -147,6 +131,8 @@ namespace kaleidoscope {
}
}
}
+
+ //If no valid mapped keys were pressed, simply return the keycode
if (!valid_key) {
return mapped_key;
}
@@ -158,30 +144,15 @@ namespace kaleidoscope {
current_timeout = time_out;
}
-
-
if ((millis() - map[index].start_time) >= current_timeout) {
- // if we timed out, that means we need to keep pressing shift, but won't
- // need the parens in the end.
+ // 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;
return mapped_key;
}
- /*
- sprintf(buffer, "Check Index: %u\n", index );
- Serial.print(buffer);
-
- sprintf(buffer, "Current Timeout: %u\n", current_timeout );
- Serial.print(buffer);
-
- sprintf(buffer, "Start Time: %u\n", map[index].start_time );
- Serial.print(buffer);
-
- Serial.print("Made it past timeout check\n");
- */
-
- // if we have a state, but the key in question is not either of the shifts,
+ // If the key that was pressed isn't one of our mapped keys, just
// return. This can happen when another key is released, and that should not
// interrupt us.
@@ -189,20 +160,21 @@ namespace kaleidoscope {
return mapped_key;
}
- //Serial.print("Made it validity check\n");
-
-
- // 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).
+ // 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;
- //Don't necessarily need to send the original key
- //handleKeyswitchEvent(pressed_key, row, col, WAS_PRESSED | INJECTED);
+ //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
+ //may want to even UNSET the originally pressed key (future
+ //enhanacement?). This might also mean we don't need to return the
+ //key that was pressed, though I haven't confirmed that.
handleKeyswitchEvent(alternate_key, row, col, IS_PRESSED | INJECTED);
hid::sendKeyboardReport();
+ //Unflag the key so we don't try this again.
map[index].flagged = false;
map[index].start_time = 0;
}
@@ -212,4 +184,6 @@ namespace kaleidoscope {
}
+//Note: since this is more generic, it is now simply SpaceCadet, instead of
+//SpaceCadetShift
kaleidoscope::SpaceCadet SpaceCadet;
From 6806fd9720504f4f0e8b0f36f771f92d7ea69607 Mon Sep 17 00:00:00 2001
From: Ben Gemperline <=>
Date: Tue, 22 Aug 2017 22:25:01 -0600
Subject: [PATCH 04/16] Updated readme file
---
README.md | 79 ++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 64 insertions(+), 15 deletions(-)
diff --git a/README.md b/README.md
index 88aa8e22..844ddafe 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@
[st:broken]: https://img.shields.io/badge/broken-X-black.svg?style=flat&colorA=e05d44&colorB=494e52
[st:experimental]: https://img.shields.io/badge/experimental----black.svg?style=flat&colorA=dfb317&colorB=494e52
-[Space Cadet][space-cadet] Shift is a way to make it more convenient to input
+[Space Cadet][space-cadet] is a way to make it more convenient to input
parens - those `(` and `)` things -, symbols that a lot of programming languages
use frequently. If you are working with Lisp, you are using these all the time.
@@ -25,6 +25,15 @@ and it still would act as a `Shift`, without the parens inserted on release:
this is useful when you want to augment some mouse action with `Shift`, to
select text, for example.
+After getting used to the Space Cadet style of typing, you may wish to enable
+this sort of functionality on other keys, as well. Fortunately, the Space Cadet
+plugin is configurable and extensible to support adding symbols to other keys,
+as well. Along with `(` on your left `Shift` key, you with to add other such
+programming mainstays as `{` to your `cmd` key and `[` to your left `Control`
+key (and, of course, the matching bookend symbols on the right). You can do
+whatever you wish to do, so feel free to experiment with different combinations
+and discover what works best for you!
+
[space-cadet]: https://en.wikipedia.org/wiki/Space-cadet_keyboard
## Using the plugin
@@ -37,38 +46,74 @@ enabling the plugin:
#include
void setup() {
- Kaleidoscope.use(&SpaceCadetShift);
+ Kaleidoscope.use(&SpaceCadet);
Kaleidoscope.setup();
}
```
-This assumes a US QWERTY layout on the host computer, and will use the `9` and
-`0` keys for the left and right parens, respectively. To change these keys, use
-the `.opening_paren` and `.closing_paren` properties outlined below.
+This assumes a US QWERTY layout on the host computer, though the plugin sends
+the correct keymap code for each symbol. Because the mapping is entirely
+configurable, though, you may switch out keys at your leisure.
+
+If you wish to enable additional modifier keys (or disable the default behavior
+for the shift and parentheses combinations), configuration is as simple as
+passing a new keymap into the SpaceCadet object, as shown below:
+
+
+```c++
+#include
+#include
-## Plugin methods
+void setup() {
+ Kaleidoscope.use(&SpaceCadet);
+
+ //Set the keymap
+ 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}
+ };
+ //Tell SpaceCadet to use the map
+ SpaceCadet.setMap(spacecadetmap, sizeof(spacecadetmap)/sizeof(spacecadetmap[0]));
-The plugin provides the `SpaceCadetShift` object, with the following methods and
+ Kaleidoscope.setup();
+}
+```
+
+## Plugin methods
+
+The plugin provides the `SpaceCadet` object, with the following methods and
properties:
-### `.opening_paren`
+### `.setMap()`
-> Set this property to the key that - when shifted - will result in an opening paren.
+> Set the key map. Takes two arguments: the key map and the number of mappings
+> in the map array. The key map is an array of `kaleidoscope::ModifierKeyMap`
+> objects, and the size is by default set dynamically by the line
+> `sizeof(spacecadetmap)/sizeof(spacecadetmap[0])`
>
-> Defaults to `Key_9`.
+> Defaults to mapping left `shift` to `(` and right `shift` to `)`.
-### `.closing_paren`
+### `kaleidoscope::ModifierKeyMap`
-> Set this property to the key that - when shifted - will result in a closing paren.
->
-> Defaults to `Key_0`.
+> An object consisting of the key that is pressed, the key that should be sent
+> in its place, and the timeout (in milliseconds) until the key press is
+> considered to be a "held" key press. The third parameter, the timeout, is
+> optional and may be set per-key or left out entirely (or set to `0`) to use
+> the default timeout value.
### `.time_out`
> Set this property to the number of milliseconds to wait before considering a
> held key in isolation as its secondary role. That is, we'd have to hold a
-> `Shift` key this long, by itself, to trigger the `Shift` role in itself.
+> `Shift` key this long, by itself, to trigger the `Shift` role in itself. This
+> timeout setting can be overridden by an individual key in the keymap, but if
+> it is omitted or set to `0` in the key map, the global timeout will be used.
>
> Defaults to 1000.
@@ -78,3 +123,7 @@ 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
From 7808eba436feab79b485dc67f2079febd6f2558d Mon Sep 17 00:00:00 2001
From: Ben Gemperline <=>
Date: Tue, 22 Aug 2017 22:26:18 -0600
Subject: [PATCH 05/16] Added .DS_Store to .gitignore
---
.gitignore | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index be16c9be..f4adf160 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
.#*
*~
/hardware/
-/output/
\ No newline at end of file
+/output/
+.DS_store
From 4ca7664442ea6c238e5048b364af8a32942f4286 Mon Sep 17 00:00:00 2001
From: Ben Gemperline <=>
Date: Wed, 23 Aug 2017 22:11:19 -0600
Subject: [PATCH 06/16] 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);
};
};
From 51f0acbb945739f8c656b35accda2e31a7c80987 Mon Sep 17 00:00:00 2001
From: Ben Gemperline <=>
Date: Wed, 23 Aug 2017 22:44:15 -0600
Subject: [PATCH 07/16] Ran astyle on code
---
examples/SpaceCadet/SpaceCadet.ino | 14 +-
src/Kaleidoscope/SpaceCadet.cpp | 286 ++++++++++++++---------------
src/Kaleidoscope/SpaceCadet.h | 68 +++----
3 files changed, 184 insertions(+), 184 deletions(-)
diff --git a/examples/SpaceCadet/SpaceCadet.ino b/examples/SpaceCadet/SpaceCadet.ino
index 7faace6e..de129903 100644
--- a/examples/SpaceCadet/SpaceCadet.ino
+++ b/examples/SpaceCadet/SpaceCadet.ino
@@ -47,15 +47,15 @@ void setup() {
//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_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}
};
//Set the map and the number of entries
- SpaceCadet.setMap(spacecadetmap, sizeof(spacecadetmap)/sizeof(spacecadetmap[0]));
+ SpaceCadet.setMap(spacecadetmap, sizeof(spacecadetmap) / sizeof(spacecadetmap[0]));
Kaleidoscope.setup();
}
diff --git a/src/Kaleidoscope/SpaceCadet.cpp b/src/Kaleidoscope/SpaceCadet.cpp
index cc1c8018..c8b162da 100644
--- a/src/Kaleidoscope/SpaceCadet.cpp
+++ b/src/Kaleidoscope/SpaceCadet.cpp
@@ -21,158 +21,158 @@
namespace kaleidoscope {
- //Default, empty constructor
- ModifierKeyMap::ModifierKeyMap(){
- }
-
- //Constructor with input and output, and assume default timeout
- ModifierKeyMap::ModifierKeyMap(Key input_, Key output_){
- input = input_;
- output = output_;
- }
-
- //Constructor with all three set
- ModifierKeyMap::ModifierKeyMap(Key input_, Key output_, uint16_t timeout_) {
- input = input_;
- output = output_;
- timeout = timeout_;
- }
-
- //Space Cadet
- 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[] = {
- //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}
- ,{Key_LeftControl,Key_LeftBracket,250}
- ,{Key_RightControl,Key_RightBracket,250}*/
- };
-
- //Set the variables to our internal map
- 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() {
- Kaleidoscope.useEventHandlerHook(eventHandlerHook);
- }
-
- Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
-
- // If nothing happened, bail out fast.
- if (!keyIsPressed(key_state) && !keyWasPressed(key_state)) {
- return mapped_key;
- }
-
- // If a key has been just toggled on...
- 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
- //for the non-pressed key
- 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();
- } else {
- //The keypress wasn't a match.
- map_[i].flagged = false;
- map_[i].start_time = 0;
- }
- }
- }
-
- // this is all we need to do on keypress, let the next handler do its thing too.
- return mapped_key;
- }
-
- // 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.
- bool valid_key = false;
- bool pressed_key_was_valid = false;
- uint8_t index = 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) {
-
- if (map_[i].flagged) {
- valid_key = true;
- index = i;
- }
- if (map_[i].input.raw == mapped_key.raw) {
- pressed_key_was_valid = true;
- }
- }
- }
+//Default, empty constructor
+ModifierKeyMap::ModifierKeyMap() {
+}
- //If no valid mapped keys were pressed, simply return the keycode
- if (!valid_key) {
- return mapped_key;
- }
+//Constructor with input and output, and assume default timeout
+ModifierKeyMap::ModifierKeyMap(Key input_, Key output_) {
+ input = input_;
+ output = output_;
+}
- //use the map index to find the local timeout for this key
- 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;
- }
+//Constructor with all three set
+ModifierKeyMap::ModifierKeyMap(Key input_, Key output_, uint16_t timeout_) {
+ input = input_;
+ output = output_;
+ timeout = 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;
- return mapped_key;
- }
+//Space Cadet
+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[] = {
+ //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}
+ ,{Key_LeftControl,Key_LeftBracket,250}
+ ,{Key_RightControl,Key_RightBracket,250}*/
+ };
+
+ //Set the variables to our internal map
+ map_ = internalMap;
+ map_size_ = sizeof(internalMap) / sizeof(internalMap[0]);
+}
- // If the key that was pressed isn't one of our mapped keys, just
- // return. This can happen when another key is released, and that should not
- // interrupt us.
+//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;
+}
- if (!pressed_key_was_valid) {
- return mapped_key;
- }
+void SpaceCadet::begin() {
+ Kaleidoscope.useEventHandlerHook(eventHandlerHook);
+}
- // 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;
-
- //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
- //may want to even UNSET the originally pressed key (future
- //enhanacement?). This might also mean we don't need to return the
- //key that was pressed, though I haven't confirmed that.
- handleKeyswitchEvent(alternate_key, row, col, IS_PRESSED | INJECTED);
- hid::sendKeyboardReport();
-
- //Unflag the key so we don't try this again.
- map_[index].flagged = false;
- map_[index].start_time = 0;
+Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
+
+ // If nothing happened, bail out fast.
+ if (!keyIsPressed(key_state) && !keyWasPressed(key_state)) {
+ return mapped_key;
+ }
+
+ // If a key has been just toggled on...
+ 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
+ //for the non-pressed key
+ 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();
+ } else {
+ //The keypress wasn't a match.
+ map_[i].flagged = false;
+ map_[i].start_time = 0;
}
+ }
+ }
- return mapped_key;
+ // this is all we need to do on keypress, let the next handler do its thing too.
+ return mapped_key;
+ }
+
+ // 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.
+ bool valid_key = false;
+ bool pressed_key_was_valid = false;
+ uint8_t index = 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) {
+
+ if (map_[i].flagged) {
+ valid_key = true;
+ index = i;
+ }
+ if (map_[i].input.raw == mapped_key.raw) {
+ pressed_key_was_valid = true;
+ }
}
+ }
+
+ //If no valid mapped keys were pressed, simply return the keycode
+ if (!valid_key) {
+ return mapped_key;
+ }
+
+ //use the map index to find the local timeout for this key
+ 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 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;
+ return mapped_key;
+ }
+
+ // If the key that was pressed isn't one of our mapped keys, just
+ // return. This can happen when another key is released, and that should not
+ // interrupt us.
+
+ if (!pressed_key_was_valid) {
+ return mapped_key;
+ }
+
+ // 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;
+
+ //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
+ //may want to even UNSET the originally pressed key (future
+ //enhanacement?). This might also mean we don't need to return the
+ //key that was pressed, though I haven't confirmed that.
+ handleKeyswitchEvent(alternate_key, row, col, IS_PRESSED | INJECTED);
+ hid::sendKeyboardReport();
+
+ //Unflag the key so we don't try this again.
+ 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 89146f21..56c384e7 100644
--- a/src/Kaleidoscope/SpaceCadet.h
+++ b/src/Kaleidoscope/SpaceCadet.h
@@ -21,44 +21,44 @@
#include
namespace kaleidoscope {
- //Declarations for the modifier key mapping
- class ModifierKeyMap {
- public:
- //Empty constructor; set the vars separately
- ModifierKeyMap(void);
- //Constructor with input and output
- ModifierKeyMap(Key input_, Key output_);
- //Constructor with all three set
- ModifierKeyMap(Key input_, Key output_, uint16_t timeout_);
- //The key that is pressed
- Key input;
- //the key that is sent
- Key output;
- //The timeout (default to global timeout)
- uint16_t timeout = 0;
- //The flag (set to 0)
- bool flagged = false;
- //the start time for this key press
- uint32_t start_time = 0;
- };
+//Declarations for the modifier key mapping
+class ModifierKeyMap {
+ public:
+ //Empty constructor; set the vars separately
+ ModifierKeyMap(void);
+ //Constructor with input and output
+ ModifierKeyMap(Key input_, Key output_);
+ //Constructor with all three set
+ ModifierKeyMap(Key input_, Key output_, uint16_t timeout_);
+ //The key that is pressed
+ Key input;
+ //the key that is sent
+ Key output;
+ //The timeout (default to global timeout)
+ uint16_t timeout = 0;
+ //The flag (set to 0)
+ bool flagged = false;
+ //the start time for this key press
+ uint32_t start_time = 0;
+};
- //Declaration for the method (implementing KaleidoscopePlugin)
- class SpaceCadet : public KaleidoscopePlugin {
- public:
- //Empty constructor
- SpaceCadet(void);
+//Declaration for the method (implementing KaleidoscopePlugin)
+class SpaceCadet : public KaleidoscopePlugin {
+ public:
+ //Empty constructor
+ SpaceCadet(void);
- //Methods
- void setMap(ModifierKeyMap * map, uint8_t map_size);
- void begin(void) final;
+ //Methods
+ void setMap(ModifierKeyMap * map, uint8_t map_size);
+ void begin(void) final;
- static uint16_t time_out;
+ static uint16_t time_out;
- private:
- static uint8_t map_size_;
- static ModifierKeyMap * map_;
- static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
- };
+ private:
+ static uint8_t map_size_;
+ static ModifierKeyMap * map_;
+ static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
+};
};
extern kaleidoscope::SpaceCadet SpaceCadet;
From 3d19d9544ef935e723cf03e4587f1bdba7490c7b Mon Sep 17 00:00:00 2001
From: Ben Gemperline <=>
Date: Wed, 23 Aug 2017 22:51:14 -0600
Subject: [PATCH 08/16] Removed variable that was set but not used in
SpaceCadet.cpp:158
---
src/Kaleidoscope/SpaceCadet.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/Kaleidoscope/SpaceCadet.cpp b/src/Kaleidoscope/SpaceCadet.cpp
index c8b162da..76cd90c1 100644
--- a/src/Kaleidoscope/SpaceCadet.cpp
+++ b/src/Kaleidoscope/SpaceCadet.cpp
@@ -155,7 +155,6 @@ 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),
// 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;
//Since we are sending the actual key (no need for shift, etc),
From 6b948dcb4656ef2b46d66acdaad9f2189372f307 Mon Sep 17 00:00:00 2001
From: Ben Gemperline <=>
Date: Mon, 4 Sep 2017 18:24:30 -0600
Subject: [PATCH 09/16] Updated ambiguous paragraph on additional mappings
---
README.md | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 24afbad1..51c53fec 100644
--- a/README.md
+++ b/README.md
@@ -28,11 +28,11 @@ select text, for example.
After getting used to the Space Cadet style of typing, you may wish to enable
this sort of functionality on other keys, as well. Fortunately, the Space Cadet
plugin is configurable and extensible to support adding symbols to other keys,
-as well. Along with `(` on your left `Shift` key, you with to add other such
-programming mainstays as `{` to your `cmd` key and `[` to your left `Control`
-key (and, of course, the matching bookend symbols on the right). You can do
-whatever you wish to do, so feel free to experiment with different combinations
-and discover what works best for you!
+as well. Along with `(` on your left `Shift` key and `)` on your right `Shift` key,
+you may wish to add other programming mainstays such as `{` to your left-side `cmd` key,
+`}` to your right-side `alt` key, `[` to your left `Control` key, and `]` to your right
+`Control` key. You can map the keys in whatever way you may wish to do, so feel free to
+experiment with different combinations and discover what works best for you!
[space-cadet]: https://en.wikipedia.org/wiki/Space-cadet_keyboard
From 0597bb2a1d31abd9b64af985d0cf542f59165b55 Mon Sep 17 00:00:00 2001
From: Ben Gemperline <=>
Date: Mon, 4 Sep 2017 19:47:03 -0600
Subject: [PATCH 10/16] Added macro to the header file and rearranged
definitions.
---
src/Kaleidoscope/SpaceCadet.h | 56 ++++++++++++++++++-----------------
1 file changed, 29 insertions(+), 27 deletions(-)
diff --git a/src/Kaleidoscope/SpaceCadet.h b/src/Kaleidoscope/SpaceCadet.h
index 56c384e7..f9a5b027 100644
--- a/src/Kaleidoscope/SpaceCadet.h
+++ b/src/Kaleidoscope/SpaceCadet.h
@@ -20,43 +20,45 @@
#include
-namespace kaleidoscope {
-//Declarations for the modifier key mapping
-class ModifierKeyMap {
- public:
- //Empty constructor; set the vars separately
- ModifierKeyMap(void);
- //Constructor with input and output
- ModifierKeyMap(Key input_, Key output_);
- //Constructor with all three set
- ModifierKeyMap(Key input_, Key output_, uint16_t timeout_);
- //The key that is pressed
- Key input;
- //the key that is sent
- Key output;
- //The timeout (default to global timeout)
- uint16_t timeout = 0;
- //The flag (set to 0)
- bool flagged = false;
- //the start time for this key press
- uint32_t start_time = 0;
-};
+#ifndef SPACECADET_MAP_END
+#define SPACECADET_MAP_END {Key_NoKey, Key_NoKey, 0}
+#endif
+namespace kaleidoscope {
//Declaration for the method (implementing KaleidoscopePlugin)
class SpaceCadet : public KaleidoscopePlugin {
public:
//Empty constructor
- SpaceCadet(void);
+ SpaceCadet(void) {}
//Methods
- void setMap(ModifierKeyMap * map, uint8_t map_size);
void begin(void) final;
- static uint16_t time_out;
-
+ //Publically accessible variables
+ static uint16_t time_out; // The global timeout in milliseconds
+ static KeyBinding * map; // The map of key bindings
+
+ //Declarations for the modifier key mapping
+ class KeyBinding {
+ public:
+ //Empty constructor; set the vars separately
+ KeyBinding(void) {}
+ //Constructor with input and output
+ KeyBinding(Key input_, Key output_);
+ //Constructor with all three set
+ KeyBinding(Key input_, Key output_, uint16_t timeout_);
+ //The key that is pressed
+ Key input;
+ //the key that is sent
+ Key output;
+ //The timeout (default to global timeout)
+ uint16_t timeout = 0;
+ //The flag (set to 0)
+ bool flagged = false;
+ //the start time for this key press
+ uint32_t start_time = 0;
+ };
private:
- static uint8_t map_size_;
- static ModifierKeyMap * map_;
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
};
};
From 9655f2254c83a6da5f5188cdfcef2b4614bf112d Mon Sep 17 00:00:00 2001
From: Ben Gemperline <=>
Date: Mon, 4 Sep 2017 20:04:26 -0600
Subject: [PATCH 11/16] First try at converting to get rid of the map_size
variable
---
src/Kaleidoscope/SpaceCadet.cpp | 124 +++++++++++++++-----------------
1 file changed, 58 insertions(+), 66 deletions(-)
diff --git a/src/Kaleidoscope/SpaceCadet.cpp b/src/Kaleidoscope/SpaceCadet.cpp
index 76cd90c1..9cf77a29 100644
--- a/src/Kaleidoscope/SpaceCadet.cpp
+++ b/src/Kaleidoscope/SpaceCadet.cpp
@@ -21,55 +21,34 @@
namespace kaleidoscope {
-//Default, empty constructor
-ModifierKeyMap::ModifierKeyMap() {
-}
//Constructor with input and output, and assume default timeout
-ModifierKeyMap::ModifierKeyMap(Key input_, Key output_) {
+SpaceCadet::KeyBinding::KeyBinding(Key input_, Key output_) {
input = input_;
output = output_;
}
//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_;
output = output_;
timeout = timeout_;
}
//Space Cadet
-uint8_t SpaceCadet::map_size_ = 0;
-ModifierKeyMap * SpaceCadet::map_;
+KeyBinding * SpaceCadet::map = {
+ //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}
+ ,{Key_LeftControl,Key_LeftBracket,250}
+ ,{Key_RightControl,Key_RightBracket,250}*/
+ , SPACECADET_MAP_END
+};
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
- {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}
- ,{Key_LeftControl,Key_LeftBracket,250}
- ,{Key_RightControl,Key_RightBracket,250}*/
- };
-
- //Set the variables to our internal map
- 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() {
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
}
@@ -83,20 +62,27 @@ Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key
// If a key has been just toggled on...
if (keyToggledOn(key_state)) {
+
+ //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) {
+ //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_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) {
- //The keypress was valid and a match.
- 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;
- }
+ if (mapped_key.raw == map[i].input.raw) {
+ //The keypress was valid and a match.
+ 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;
}
}
@@ -110,37 +96,45 @@ Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key
bool pressed_key_was_valid = false;
uint8_t index = 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) {
+ //Look to see if any keys in our map are flagged
+ for (uint8_t i = 0 ;; ++i) {
- if (map_[i].flagged) {
- valid_key = true;
- index = i;
- }
- if (map_[i].input.raw == mapped_key.raw) {
- pressed_key_was_valid = true;
- }
+ //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) {
+ valid_key = true;
+ index = i;
+ }
+ if (map[i].input.raw == mapped_key.raw) {
+ pressed_key_was_valid = true;
}
}
+
//If no valid mapped keys were pressed, simply return the keycode
if (!valid_key) {
return mapped_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 (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;
}
@@ -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),
// send the alternative key instead (if we were interrupted, we bailed out earlier).
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),
//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();
//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;
@@ -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;
From 90c1f7cc1379cfd57f552e9399299e9e45f2c1fa Mon Sep 17 00:00:00 2001
From: Ben Gemperline <=>
Date: Mon, 4 Sep 2017 20:05:47 -0600
Subject: [PATCH 12/16] Updated spacing in the comments
---
src/Kaleidoscope/SpaceCadet.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/Kaleidoscope/SpaceCadet.cpp b/src/Kaleidoscope/SpaceCadet.cpp
index 9cf77a29..d6945a94 100644
--- a/src/Kaleidoscope/SpaceCadet.cpp
+++ b/src/Kaleidoscope/SpaceCadet.cpp
@@ -41,10 +41,10 @@ KeyBinding * SpaceCadet::map = {
{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}
- ,{Key_LeftControl,Key_LeftBracket,250}
- ,{Key_RightControl,Key_RightBracket,250}*/
+ /*,{Key_LeftGui,Key_LeftCurlyBracket, 250}
+ ,{Key_RightAlt,Key_RightCurlyBracket, 250}
+ ,{Key_LeftControl,Key_LeftBracket, 250}
+ ,{Key_RightControl,Key_RightBracket, 250}*/
, SPACECADET_MAP_END
};
uint16_t SpaceCadet::time_out = 1000;
From 1a73d22da7025ea898d90288913090019ae6a1cb Mon Sep 17 00:00:00 2001
From: Ben Gemperline <=>
Date: Mon, 4 Sep 2017 23:09:54 -0600
Subject: [PATCH 13/16] Updated sources to use newer method and remove map_size
variable requirement
---
src/Kaleidoscope/SpaceCadet.cpp | 30 ++++++++++++++++++------------
src/Kaleidoscope/SpaceCadet.h | 26 ++++++++++++++------------
2 files changed, 32 insertions(+), 24 deletions(-)
diff --git a/src/Kaleidoscope/SpaceCadet.cpp b/src/Kaleidoscope/SpaceCadet.cpp
index d6945a94..dcb246f9 100644
--- a/src/Kaleidoscope/SpaceCadet.cpp
+++ b/src/Kaleidoscope/SpaceCadet.cpp
@@ -21,7 +21,6 @@
namespace kaleidoscope {
-
//Constructor with input and output, and assume default timeout
SpaceCadet::KeyBinding::KeyBinding(Key input_, Key output_) {
input = input_;
@@ -36,19 +35,26 @@ SpaceCadet::KeyBinding::KeyBinding(Key input_, Key output_, uint16_t timeout_) {
}
//Space Cadet
-KeyBinding * SpaceCadet::map = {
- //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}
- ,{Key_LeftControl,Key_LeftBracket, 250}
- ,{Key_RightControl,Key_RightBracket, 250}*/
- , SPACECADET_MAP_END
-};
+SpaceCadet::KeyBinding * SpaceCadet::map;
uint16_t SpaceCadet::time_out = 1000;
+//Empty Constructor
+SpaceCadet::SpaceCadet() {
+ SpaceCadet::KeyBinding initialmap[] = {
+ //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}
+ ,{Key_LeftControl,Key_LeftBracket, 250}
+ ,{Key_RightControl,Key_RightBracket, 250}*/
+ , SPACECADET_MAP_END
+ };
+
+ map = initialmap;
+}
+
void SpaceCadet::begin() {
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
}
diff --git a/src/Kaleidoscope/SpaceCadet.h b/src/Kaleidoscope/SpaceCadet.h
index f9a5b027..5d11a3c1 100644
--- a/src/Kaleidoscope/SpaceCadet.h
+++ b/src/Kaleidoscope/SpaceCadet.h
@@ -21,24 +21,15 @@
#include
#ifndef SPACECADET_MAP_END
-#define SPACECADET_MAP_END {Key_NoKey, Key_NoKey, 0}
+#define SPACECADET_MAP_END (kaleidoscope::SpaceCadet::KeyBinding) { Key_NoKey, Key_NoKey, 0 }
#endif
namespace kaleidoscope {
//Declaration for the method (implementing KaleidoscopePlugin)
class SpaceCadet : public KaleidoscopePlugin {
public:
- //Empty constructor
- SpaceCadet(void) {}
-
- //Methods
- void begin(void) final;
-
- //Publically accessible variables
- static uint16_t time_out; // The global timeout in milliseconds
- static KeyBinding * map; // The map of key bindings
-
- //Declarations for the modifier key mapping
+ //Internal Class
+ //Declarations for the modifier key mapping
class KeyBinding {
public:
//Empty constructor; set the vars separately
@@ -58,6 +49,17 @@ class SpaceCadet : public KaleidoscopePlugin {
//the start time for this key press
uint32_t start_time = 0;
};
+
+ //Empty constructor
+ SpaceCadet(void);
+
+ //Methods
+ void begin(void) final;
+
+ //Publically accessible variables
+ static uint16_t time_out; // The global timeout in milliseconds
+ static SpaceCadet::KeyBinding * map; // The map of key bindings
+
private:
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
};
From 5d4d7820aef7b4555b0779fb2b68e5f305bdca63 Mon Sep 17 00:00:00 2001
From: Ben Gemperline <=>
Date: Wed, 6 Sep 2017 10:54:33 -0600
Subject: [PATCH 14/16] astyle
---
src/Kaleidoscope/SpaceCadet.cpp | 31 ++++++++++++++++---------------
src/Kaleidoscope/SpaceCadet.h | 4 ++--
2 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/src/Kaleidoscope/SpaceCadet.cpp b/src/Kaleidoscope/SpaceCadet.cpp
index dcb246f9..4e5e7615 100644
--- a/src/Kaleidoscope/SpaceCadet.cpp
+++ b/src/Kaleidoscope/SpaceCadet.cpp
@@ -68,18 +68,19 @@ Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key
// If a key has been just toggled on...
if (keyToggledOn(key_state)) {
-
+
//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) {
- //Check for ending sentinal and exit
- if(
+ //Exit condition is if we reach the sentinal
+ for (
+ uint8_t i = 0 ;
+ !(
map[i].input.raw == Key_NoKey.raw
&& map[i].output.raw == Key_NoKey.raw
&& map[i].timeout == 0
- ) {
- break;
- }
+ ) ;
+ ++i
+ ) {
if (mapped_key.raw == map[i].input.raw) {
//The keypress was valid and a match.
@@ -102,17 +103,17 @@ Key SpaceCadet::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key
bool pressed_key_was_valid = false;
uint8_t index = 0;
- //Look to see if any keys in our map are flagged
- for (uint8_t i = 0 ;; ++i) {
-
- //Check for ending sentinal and exit
- if(
+ //Look to see if any keys in our map are flagged.
+ //Exit condition is if we reach the sentinal
+ for (
+ uint8_t i = 0 ;
+ !(
map[i].input.raw == Key_NoKey.raw
&& map[i].output.raw == Key_NoKey.raw
&& map[i].timeout == 0
- ) {
- break;
- }
+ ) ;
+ ++i
+ ) {
if (map[i].flagged) {
valid_key = true;
diff --git a/src/Kaleidoscope/SpaceCadet.h b/src/Kaleidoscope/SpaceCadet.h
index 5d11a3c1..6fa9d1cf 100644
--- a/src/Kaleidoscope/SpaceCadet.h
+++ b/src/Kaleidoscope/SpaceCadet.h
@@ -29,7 +29,7 @@ namespace kaleidoscope {
class SpaceCadet : public KaleidoscopePlugin {
public:
//Internal Class
- //Declarations for the modifier key mapping
+ //Declarations for the modifier key mapping
class KeyBinding {
public:
//Empty constructor; set the vars separately
@@ -58,7 +58,7 @@ class SpaceCadet : public KaleidoscopePlugin {
//Publically accessible variables
static uint16_t time_out; // The global timeout in milliseconds
- static SpaceCadet::KeyBinding * map; // The map of key bindings
+ static SpaceCadet::KeyBinding * map; // The map of key bindings
private:
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
From a2feb2f780dcafae83f68e05c789f4d93e3477cd Mon Sep 17 00:00:00 2001
From: Ben Gemperline <=>
Date: Wed, 6 Sep 2017 11:18:10 -0600
Subject: [PATCH 15/16] Updated examples and documentation
---
README.md | 42 ++++++++++++++++--------------
examples/SpaceCadet/SpaceCadet.ino | 8 +++---
2 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/README.md b/README.md
index 51c53fec..4a090b34 100644
--- a/README.md
+++ b/README.md
@@ -27,9 +27,9 @@ select text, for example.
After getting used to the Space Cadet style of typing, you may wish to enable
this sort of functionality on other keys, as well. Fortunately, the Space Cadet
-plugin is configurable and extensible to support adding symbols to other keys,
-as well. Along with `(` on your left `Shift` key and `)` on your right `Shift` key,
-you may wish to add other programming mainstays such as `{` to your left-side `cmd` key,
+plugin is configurable and extensible to support adding symbols to other keys.
+Along with `(` on your left `Shift` key and `)` on your right `Shift` key,
+you may wish to add other such programming mainstays as `{` to your left-side `cmd` key,
`}` to your right-side `alt` key, `[` to your left `Control` key, and `]` to your right
`Control` key. You can map the keys in whatever way you may wish to do, so feel free to
experiment with different combinations and discover what works best for you!
@@ -69,17 +69,20 @@ void setup() {
Kaleidoscope.use(&SpaceCadet);
//Set the keymap with a 250ms timeout per-key
- static kaleidoscope::ModifierKeyMap spacecadetmap[] = {
+ //Setting is {KeyThatWasPressed, AlternativeKeyToSend, TimeoutInMS}
+ //Note: must end with the SPACECADET_MAP_END delimiter
+ static kaleidoscope::SpaceCadet::KeyBinding 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_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}
+ , SPACECADET_MAP_END
};
- //Tell SpaceCadet to use the map
- SpaceCadet.setMap(spacecadetmap, sizeof(spacecadetmap)/sizeof(spacecadetmap[0]));
+ //Set the map.
+ SpaceCadet.map = spacecadetmap;
Kaleidoscope.setup();
}
@@ -90,16 +93,17 @@ void setup() {
The plugin provides the `SpaceCadet` object, with the following methods and
properties:
-### `.setMap()`
+### `.map`
-> Set the key map. Takes two arguments: the key map and the number of mappings
-> in the map array. The key map is an array of `kaleidoscope::ModifierKeyMap`
-> objects, and the size is by default set dynamically by the line
-> `sizeof(spacecadetmap)/sizeof(spacecadetmap[0])`
+> Set the key map. This takes an array of `kaleidoscope::SpaceCadet::KeyBinding`
+> objects with the special `SPACECADET_MAP_END` sentinal to mark the end of the map.
+> Each KeyBinding object takes, in order, the key that was pressed, the key that
+> should be sent instead, and an optional per-key timeout override
>
-> Defaults to mapping left `shift` to `(` and right `shift` to `)`.
+> If not explicitly set, defaults to mapping left `shift` to `(` and right `shift`
+> to `)`.
-### `kaleidoscope::ModifierKeyMap`
+### `kaleidoscope::SpaceCadet::KeyBinding`
> An object consisting of the key that is pressed, the key that should be sent
> in its place, and the timeout (in milliseconds) until the key press is
diff --git a/examples/SpaceCadet/SpaceCadet.ino b/examples/SpaceCadet/SpaceCadet.ino
index de129903..b584666c 100644
--- a/examples/SpaceCadet/SpaceCadet.ino
+++ b/examples/SpaceCadet/SpaceCadet.ino
@@ -45,7 +45,8 @@ void setup() {
//Set the SpaceCadet map
//Setting is {KeyThatWasPressed, AlternativeKeyToSend, TimeoutInMS}
- static kaleidoscope::ModifierKeyMap spacecadetmap[] = {
+ //Note: must end with the SPACECADET_MAP_END delimiter
+ static kaleidoscope::SpaceCadet::KeyBinding spacecadetmap[] = {
{Key_LeftShift, Key_LeftParen, 250}
, {Key_RightShift, Key_RightParen, 250}
, {Key_LeftGui, Key_LeftCurlyBracket, 250}
@@ -53,9 +54,10 @@ void setup() {
, {Key_LeftAlt, Key_RightCurlyBracket, 250}
, {Key_LeftControl, Key_LeftBracket, 250}
, {Key_RightControl, Key_RightBracket, 250}
+ , SPACECADET_MAP_END
};
- //Set the map and the number of entries
- SpaceCadet.setMap(spacecadetmap, sizeof(spacecadetmap) / sizeof(spacecadetmap[0]));
+ //Set the map.
+ SpaceCadet.map = spacecadetmap;
Kaleidoscope.setup();
}
From f5cb8760ddc18baf75397a058ded7886170c0155 Mon Sep 17 00:00:00 2001
From: Ben Gemperline <=>
Date: Wed, 6 Sep 2017 11:21:48 -0600
Subject: [PATCH 16/16] formatting in README
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 4a090b34..d4b38aed 100644
--- a/README.md
+++ b/README.md
@@ -27,7 +27,7 @@ select text, for example.
After getting used to the Space Cadet style of typing, you may wish to enable
this sort of functionality on other keys, as well. Fortunately, the Space Cadet
-plugin is configurable and extensible to support adding symbols to other keys.
+plugin is configurable and extensible to support adding symbols to other keys.
Along with `(` on your left `Shift` key and `)` on your right `Shift` key,
you may wish to add other such programming mainstays as `{` to your left-side `cmd` key,
`}` to your right-side `alt` key, `[` to your left `Control` key, and `]` to your right