From e5a8a77a4aee3b5654dd0d135eced36e61016800 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Mon, 5 Jun 2017 12:26:38 +0200 Subject: [PATCH] Kaleidoscope Style Guide conformance Signed-off-by: Gergely Nagy --- README.md | 22 ++++++----- examples/TopsyTurvy/TopsyTurvy.ino | 7 ++-- src/Kaleidoscope/TopsyTurvy.cpp | 63 +++++++++++++----------------- src/Kaleidoscope/TopsyTurvy.h | 16 ++++---- 4 files changed, 52 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 957e3365..f95bdcad 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ [travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-TopsyTurvy.svg?branch=master [travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-TopsyTurvy - [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 `TopsyTurvy` is a plugin that inverts the behaviour of the `Shift` key for some selected keys. That is, if configured so, it will input `!` when pressing the @@ -23,17 +23,18 @@ the provided `TopsyTurvy` object to use the dictionary: #include #include -static const Key topsyTurvyList[] PROGMEM = { +static const Key topsy_turvy_list[] PROGMEM = { Key_1, Key_2, Key_3, Key_4, Key_5, Key_6, Key_7, Key_8, Key_9, Key_0, Key_NoKey }; void setup () { - TopsyTurvy.configure (topsyTurvyList); - - Kaleidoscope.setup (); USE_PLUGINS (&TopsyTurvy); + + Kaleidoscope.setup (); + + TopsyTurvy.key_list = topsy_turvy_list; } ``` @@ -42,11 +43,12 @@ in `PROGMEM`. ## Plugin methods -The plugin provides the `TopsyTurvy` object, with the following methods: +The plugin provides the `TopsyTurvy` object, with the following property: -### `.configure(list)` +### `.key_list` -> Tells `TopsyTurvy` to use the specified list of keys. +> Set this property to the list of `Key`s `TopsyTurvy` should invert the `Shift` +> behaviour for. ## Further reading diff --git a/examples/TopsyTurvy/TopsyTurvy.ino b/examples/TopsyTurvy/TopsyTurvy.ino index 24b378b6..4828d57e 100644 --- a/examples/TopsyTurvy/TopsyTurvy.ino +++ b/examples/TopsyTurvy/TopsyTurvy.ino @@ -39,17 +39,18 @@ const Key keymaps[][ROWS][COLS] PROGMEM = { Key_skip), }; -static const Key topsyTurvyList[] PROGMEM = { +static const Key topsy_turvy_list[] PROGMEM = { Key_1, Key_2, Key_3, Key_4, Key_5, Key_6, Key_7, Key_8, Key_9, Key_0, Key_NoKey }; void setup() { - TopsyTurvy.configure(topsyTurvyList); + USE_PLUGINS(&TopsyTurvy); Kaleidoscope.setup(); - USE_PLUGINS(&TopsyTurvy); + + TopsyTurvy.key_list = topsy_turvy_list; } void loop() { diff --git a/src/Kaleidoscope/TopsyTurvy.cpp b/src/Kaleidoscope/TopsyTurvy.cpp index bd7f7dd0..54ddfdab 100644 --- a/src/Kaleidoscope/TopsyTurvy.cpp +++ b/src/Kaleidoscope/TopsyTurvy.cpp @@ -20,76 +20,69 @@ #define TOPSYTURVY 0b01000000 -namespace KaleidoscopePlugins { +namespace kaleidoscope { -const Key *TopsyTurvy::topsyTurvyList = NULL; -uint8_t TopsyTurvy::topsyTurvyModState; +const Key *TopsyTurvy::key_list = NULL; +uint8_t TopsyTurvy::mod_state_; TopsyTurvy::TopsyTurvy(void) { } -void -TopsyTurvy::begin(void) { - event_handler_hook_use(this->eventHandlerHook); +void TopsyTurvy::begin(void) { + event_handler_hook_use(eventHandlerHook); } -void -TopsyTurvy::configure(const Key list[]) { - topsyTurvyList = (const Key *)list; -} - -Key -TopsyTurvy::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) { - if (keyState & TOPSYTURVY) - return mappedKey; +Key TopsyTurvy::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) { + if (key_state & TOPSYTURVY) + return mapped_key; - if (!topsyTurvyList) - return mappedKey; + if (!key_list) + return mapped_key; - if (mappedKey.raw == Key_LeftShift.raw) - bitWrite(topsyTurvyModState, 0, key_is_pressed(keyState)); - if (mappedKey.raw == Key_RightShift.raw) - bitWrite(topsyTurvyModState, 1, key_is_pressed(keyState)); + if (mapped_key.raw == Key_LeftShift.raw) + bitWrite(mod_state_, 0, key_is_pressed(key_state)); + if (mapped_key.raw == Key_RightShift.raw) + bitWrite(mod_state_, 1, key_is_pressed(key_state)); - if (!key_is_pressed(keyState) && !key_was_pressed(keyState)) - return mappedKey; + if (!key_is_pressed(key_state) && !key_was_pressed(key_state)) + return mapped_key; uint8_t idx = 0; Key newKey; do { - newKey.raw = pgm_read_word(&(topsyTurvyList[idx].raw)); + newKey.raw = pgm_read_word(&(key_list[idx].raw)); idx++; - } while (newKey.raw != mappedKey.raw && newKey.raw != Key_NoKey.raw); + } while (newKey.raw != mapped_key.raw && newKey.raw != Key_NoKey.raw); if (newKey.raw == Key_NoKey.raw) - return mappedKey; + return mapped_key; // invert the shift state - if (!topsyTurvyModState) { - if (key_is_pressed(keyState)) + if (!mod_state_) { + if (key_is_pressed(key_state)) Keyboard.press(Key_LeftShift.keyCode); - handle_keyswitch_event(mappedKey, row, col, keyState | TOPSYTURVY); + handle_keyswitch_event(mapped_key, row, col, key_state | TOPSYTURVY); Keyboard.sendReport(); - if (key_toggled_off(keyState)) + if (key_toggled_off(key_state)) Keyboard.release(Key_LeftShift.keyCode); } else { Keyboard.release(Key_LeftShift.keyCode); Keyboard.release(Key_RightShift.keyCode); Keyboard.sendReport(); - handle_keyswitch_event(mappedKey, row, col, keyState | TOPSYTURVY); + handle_keyswitch_event(mapped_key, row, col, key_state | TOPSYTURVY); Keyboard.sendReport(); - if (bitRead(topsyTurvyModState, 0)) + if (bitRead(mod_state_, 0)) Keyboard.press(Key_LeftShift.keyCode); - if (bitRead(topsyTurvyModState, 1)) + if (bitRead(mod_state_, 1)) Keyboard.press(Key_RightShift.keyCode); } return Key_NoKey; } -} // namespace KaleidoscopePlugins +} -KaleidoscopePlugins::TopsyTurvy TopsyTurvy; +kaleidoscope::TopsyTurvy TopsyTurvy; diff --git a/src/Kaleidoscope/TopsyTurvy.h b/src/Kaleidoscope/TopsyTurvy.h index 46baca0c..92db2288 100644 --- a/src/Kaleidoscope/TopsyTurvy.h +++ b/src/Kaleidoscope/TopsyTurvy.h @@ -20,21 +20,21 @@ #include -namespace KaleidoscopePlugins { +namespace kaleidoscope { + class TopsyTurvy: public KaleidoscopePlugin { public: TopsyTurvy(void); void begin(void) final; - static void configure(const Key topsyTurvyList[]); - + static const Key *key_list; private: - static const Key *topsyTurvyList; - static uint8_t topsyTurvyModState; + static uint8_t mod_state_; - static Key eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState); + static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state); }; -} // namespace KaleidoscopePlugins -extern KaleidoscopePlugins::TopsyTurvy TopsyTurvy; +} + +extern kaleidoscope::TopsyTurvy TopsyTurvy;