diff --git a/examples/TopsyTurvy/TopsyTurvy.ino b/examples/TopsyTurvy/TopsyTurvy.ino index 5f6bdb17..4b031e62 100644 --- a/examples/TopsyTurvy/TopsyTurvy.ino +++ b/examples/TopsyTurvy/TopsyTurvy.ino @@ -20,39 +20,39 @@ #include const Key keymaps[][ROWS][COLS] PROGMEM = { - [0] = KEYMAP_STACKED - ( - Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, - 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, - - Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, - Key_skip, - - Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip, - Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, - Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, - Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, - - Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, - Key_skip - ), + [0] = KEYMAP_STACKED + ( + Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, + 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, + + Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, + Key_skip, + + Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip, + Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, + Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, + Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, + + Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, + Key_skip + ), }; static const Key topsyTurvyList[] PROGMEM = { - Key_1, Key_2, Key_3, Key_4, Key_5, - Key_6, Key_7, Key_8, Key_9, Key_0, - Key_NoKey + 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); + TopsyTurvy.configure (topsyTurvyList); - Kaleidoscope.setup (); - USE_PLUGINS (&TopsyTurvy); + Kaleidoscope.setup (); + USE_PLUGINS (&TopsyTurvy); } void loop () { - Kaleidoscope.loop (); + Kaleidoscope.loop (); } diff --git a/src/Kaleidoscope/TopsyTurvy.cpp b/src/Kaleidoscope/TopsyTurvy.cpp index 3c85f6b5..88ca5c0c 100644 --- a/src/Kaleidoscope/TopsyTurvy.cpp +++ b/src/Kaleidoscope/TopsyTurvy.cpp @@ -22,73 +22,73 @@ namespace KaleidoscopePlugins { - const Key *TopsyTurvy::topsyTurvyList = NULL; - uint8_t TopsyTurvy::topsyTurvyModState; +const Key *TopsyTurvy::topsyTurvyList = NULL; +uint8_t TopsyTurvy::topsyTurvyModState; - TopsyTurvy::TopsyTurvy (void) { - } +TopsyTurvy::TopsyTurvy (void) { +} - void - TopsyTurvy::begin (void) { +void +TopsyTurvy::begin (void) { event_handler_hook_use (this->eventHandlerHook); - } +} - void - TopsyTurvy::configure (const Key list[]) { +void +TopsyTurvy::configure (const Key list[]) { topsyTurvyList = (const Key *)list; - } +} - Key - TopsyTurvy::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) { +Key +TopsyTurvy::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) { if (keyState & TOPSYTURVY) - return mappedKey; + return mappedKey; if (!topsyTurvyList) - return mappedKey; + return mappedKey; if (mappedKey.raw == Key_LeftShift.raw) - bitWrite (topsyTurvyModState, 0, key_is_pressed (keyState)); + bitWrite (topsyTurvyModState, 0, key_is_pressed (keyState)); if (mappedKey.raw == Key_RightShift.raw) - bitWrite (topsyTurvyModState, 1, key_is_pressed (keyState)); + bitWrite (topsyTurvyModState, 1, key_is_pressed (keyState)); if (!key_is_pressed (keyState) && !key_was_pressed (keyState)) - return mappedKey; + return mappedKey; uint8_t idx = 0; Key newKey; do { - newKey.raw = pgm_read_word (&(topsyTurvyList[idx].raw)); - idx++; + newKey.raw = pgm_read_word (&(topsyTurvyList[idx].raw)); + idx++; } while (newKey.raw != mappedKey.raw && newKey.raw != Key_NoKey.raw); if (newKey.raw == Key_NoKey.raw) - return mappedKey; + return mappedKey; // invert the shift state if (!topsyTurvyModState) { - if (key_is_pressed (keyState)) - Keyboard.press (Key_LeftShift.keyCode); - handle_keyswitch_event (mappedKey, row, col, keyState | TOPSYTURVY); - Keyboard.sendReport (); - if (key_toggled_off (keyState)) - Keyboard.release (Key_LeftShift.keyCode); + if (key_is_pressed (keyState)) + Keyboard.press (Key_LeftShift.keyCode); + handle_keyswitch_event (mappedKey, row, col, keyState | TOPSYTURVY); + Keyboard.sendReport (); + if (key_toggled_off (keyState)) + 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); - Keyboard.sendReport (); - - if (bitRead (topsyTurvyModState, 0)) - Keyboard.press (Key_LeftShift.keyCode); - if (bitRead (topsyTurvyModState, 1)) - Keyboard.press (Key_RightShift.keyCode); + Keyboard.release (Key_LeftShift.keyCode); + Keyboard.release (Key_RightShift.keyCode); + Keyboard.sendReport (); + handle_keyswitch_event (mappedKey, row, col, keyState | TOPSYTURVY); + Keyboard.sendReport (); + + if (bitRead (topsyTurvyModState, 0)) + Keyboard.press (Key_LeftShift.keyCode); + if (bitRead (topsyTurvyModState, 1)) + Keyboard.press (Key_RightShift.keyCode); } return Key_NoKey; - } +} }; diff --git a/src/Kaleidoscope/TopsyTurvy.h b/src/Kaleidoscope/TopsyTurvy.h index 8de71d36..1f17a3b1 100644 --- a/src/Kaleidoscope/TopsyTurvy.h +++ b/src/Kaleidoscope/TopsyTurvy.h @@ -21,7 +21,7 @@ #include namespace KaleidoscopePlugins { - class TopsyTurvy: public KaleidoscopePlugin { +class TopsyTurvy: public KaleidoscopePlugin { public: TopsyTurvy (void); @@ -34,7 +34,7 @@ namespace KaleidoscopePlugins { static uint8_t topsyTurvyModState; static Key eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState); - }; +}; }; extern KaleidoscopePlugins::TopsyTurvy TopsyTurvy;