diff --git a/README.md b/README.md index 4d857a41..72e02ca4 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ [travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-ShapeShifter.svg?branch=master [travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-ShapeShifter - [st:stable]: https://img.shields.io/badge/stable-✔-black.png?style=flat&colorA=44cc11&colorB=494e52 - [st:broken]: https://img.shields.io/badge/broken-X-black.png?style=flat&colorA=e05d44&colorB=494e52 - [st:experimental]: https://img.shields.io/badge/experimental----black.png?style=flat&colorA=dfb317&colorB=494e52 + [st:stable]: https://img.shields.io/badge/stable-✔-black.svg?style=flat&colorA=44cc11&colorB=494e52 + [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 `ShapeShifter` is a plugin that makes it considerably easier to change what symbol is input when a key is pressed together with `Shift`. If one wants to @@ -28,17 +28,18 @@ configure the provided `ShapeShifter` object to use the dictionary: #include #include -static const KaleidoscopePlugins::ShapeShifter::dictionary_t shapeShiftDictionary[] PROGMEM = { +static const kaleidoscope::ShapeShifter::dictionary_t shape_shift_dictionary[] PROGMEM = { {Key_1, Key_4}, {Key_4, Key_1}, {Key_NoKey, Key_NoKey}, }; -void setup () { - ShapeShifter.configure (shapeShiftDictionary); +void setup() { + USE_PLUGINS(&ShapeShifter); + + Kaleidoscope.setup(); - Kaleidoscope.setup (); - USE_PLUGINS (&ShapeShifter); + ShapeShifter.dictionary = shape_shift_dictionary; } ``` @@ -48,12 +49,13 @@ Key_NoKey}` pair, and **must** reside in `PROGMEM`. ## Plugin methods -The plugin provides the `ShapeShifter` object, with the following methods: +The plugin provides the `ShapeShifter` object, with the following methods and +properties: -### `.configure(dictionary)` +### `.dictionary` -> Tells `ShapeShifter` to use the specified dictionary. The dictionary is an -> array of `KaleidoscopePlugins::ShapeShifter::dictionary_t` elements, which is +> Set this property to the dictionary `ShapeShifter` should use. The dictionary +> is an array of `kaleidoscope::ShapeShifter::dictionary_t` elements, which is > just a very verbose way of saying that its a pair of keys. The first one is > the one to replace, and the other is to replace it with. > diff --git a/examples/ShapeShifter/ShapeShifter.ino b/examples/ShapeShifter/ShapeShifter.ino index 52c96752..bdb60e7c 100644 --- a/examples/ShapeShifter/ShapeShifter.ino +++ b/examples/ShapeShifter/ShapeShifter.ino @@ -19,12 +19,10 @@ #include #include - - const Key keymaps[][ROWS][COLS] PROGMEM = { [0] = KEYMAP_STACKED ( - Key_skip, Key_1, Key_2, Key_3, Key_4, Key_5, Key_skip, + Key_skip, Key_1, Key_2, Key_3, Key_4, Key_5, Key_skip, Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape, @@ -38,24 +36,21 @@ const Key keymaps[][ROWS][COLS] PROGMEM = { Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, - Key_NoKey - ), + Key_NoKey), }; - - - -static const KaleidoscopePlugins::ShapeShifter::dictionary_t shapeShiftDictionary[] PROGMEM = { +static const kaleidoscope::ShapeShifter::dictionary_t shape_shift_dictionary[] PROGMEM = { {Key_1, Key_2}, {Key_2, Key_1}, {Key_NoKey, Key_NoKey}, }; void setup() { - ShapeShifter.configure(shapeShiftDictionary); + USE_PLUGINS(&ShapeShifter); Kaleidoscope.setup(); - USE_PLUGINS(&ShapeShifter); + + ShapeShifter.dictionary = shape_shift_dictionary; } void loop() { diff --git a/src/Kaleidoscope/ShapeShifter.cpp b/src/Kaleidoscope/ShapeShifter.cpp index 3a8ac063..63859c04 100644 --- a/src/Kaleidoscope/ShapeShifter.cpp +++ b/src/Kaleidoscope/ShapeShifter.cpp @@ -18,42 +18,35 @@ #include -namespace KaleidoscopePlugins { +namespace kaleidoscope { const ShapeShifter::dictionary_t *ShapeShifter::dictionary = NULL; -bool ShapeShifter::modActive; +bool ShapeShifter::mod_active_; ShapeShifter::ShapeShifter(void) { } -void -ShapeShifter::begin(void) { - event_handler_hook_use(this->eventHandlerHook); - loop_hook_use(this->loopHook); +void ShapeShifter::begin(void) { + event_handler_hook_use(eventHandlerHook); + loop_hook_use(loopHook); } -void -ShapeShifter::configure(const dictionary_t dictionary_[]) { - dictionary = (const dictionary_t *)dictionary_; -} - -void -ShapeShifter::loopHook(bool postClear) { - if (postClear) +void ShapeShifter::loopHook(bool is_post_clear) { + if (is_post_clear) return; - modActive = Keyboard.isModifierActive(Key_LeftShift.keyCode) || - Keyboard.isModifierActive(Key_RightShift.keyCode); + mod_active_ = Keyboard.isModifierActive(Key_LeftShift.keyCode) || + Keyboard.isModifierActive(Key_RightShift.keyCode); } Key -ShapeShifter::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) { +ShapeShifter::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) { if (!dictionary) - return mappedKey; + return mapped_key; // If Shift is not active, bail out early. - if (!modActive) - return mappedKey; + if (!mod_active_) + return mapped_key; Key orig, repl; @@ -63,12 +56,12 @@ ShapeShifter::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keySta orig.raw = pgm_read_word(&(dictionary[i].original.raw)); i++; } while (orig.raw != Key_NoKey.raw && - orig.raw != mappedKey.raw); + orig.raw != mapped_key.raw); i--; // If not found, bail out. if (orig.raw == Key_NoKey.raw) - return mappedKey; + return mapped_key; repl.raw = pgm_read_word(&(dictionary[i].replacement.raw)); @@ -76,6 +69,6 @@ ShapeShifter::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keySta return repl; } -}; +} -KaleidoscopePlugins::ShapeShifter ShapeShifter; +kaleidoscope::ShapeShifter ShapeShifter; diff --git a/src/Kaleidoscope/ShapeShifter.h b/src/Kaleidoscope/ShapeShifter.h index 214d68e0..0b53d881 100644 --- a/src/Kaleidoscope/ShapeShifter.h +++ b/src/Kaleidoscope/ShapeShifter.h @@ -20,7 +20,8 @@ #include -namespace KaleidoscopePlugins { +namespace kaleidoscope { + class ShapeShifter : public KaleidoscopePlugin { public: typedef struct { @@ -31,15 +32,14 @@ class ShapeShifter : public KaleidoscopePlugin { void begin(void) final; - static void configure(const dictionary_t dictionary[]); - - private: static const dictionary_t *dictionary; - static bool modActive; + private: + static bool mod_active_; - static Key eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState); - static void loopHook(bool postClear); -}; + static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state); + static void loopHook(bool is_post_clear); }; -extern KaleidoscopePlugins::ShapeShifter ShapeShifter; +} + +extern kaleidoscope::ShapeShifter ShapeShifter;