diff --git a/examples/Syster/Syster.ino b/examples/Syster/Syster.ino index 22665e02..767c31a3 100644 --- a/examples/Syster/Syster.ino +++ b/examples/Syster/Syster.ino @@ -23,52 +23,52 @@ #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, + [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, - SYSTER, + Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, + SYSTER, - 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_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, - SYSTER - ), + Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, + SYSTER + ), }; void systerAction (KaleidoscopePlugins::Syster::action_t action, const char *symbol) { - switch (action) { - case KaleidoscopePlugins::Syster::StartAction: - Unicode.type (0x2328); - break; - case KaleidoscopePlugins::Syster::EndAction: - handle_keyswitch_event (Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED); - Keyboard.sendReport (); - handle_keyswitch_event (Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED); - Keyboard.sendReport (); - break; - case KaleidoscopePlugins::Syster::SymbolAction: - Serial.print ("systerAction: symbol="); - Serial.println (symbol); - if (strcmp (symbol, "coffee") == 0) { - Unicode.type (0x2615); + switch (action) { + case KaleidoscopePlugins::Syster::StartAction: + Unicode.type (0x2328); + break; + case KaleidoscopePlugins::Syster::EndAction: + handle_keyswitch_event (Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED); + Keyboard.sendReport (); + handle_keyswitch_event (Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED); + Keyboard.sendReport (); + break; + case KaleidoscopePlugins::Syster::SymbolAction: + Serial.print ("systerAction: symbol="); + Serial.println (symbol); + if (strcmp (symbol, "coffee") == 0) { + Unicode.type (0x2615); + } + break; } - break; - } } void setup () { - Kaleidoscope.setup (KEYMAP_SIZE); - Kaleidoscope.use (&Unicode, &Syster, NULL); + Kaleidoscope.setup (KEYMAP_SIZE); + Kaleidoscope.use (&Unicode, &Syster, NULL); } void loop () { - Kaleidoscope.loop (); + Kaleidoscope.loop (); } diff --git a/src/Kaleidoscope/Syster.cpp b/src/Kaleidoscope/Syster.cpp index be9f587a..d511fb41 100644 --- a/src/Kaleidoscope/Syster.cpp +++ b/src/Kaleidoscope/Syster.cpp @@ -21,103 +21,103 @@ using namespace KaleidoscopePlugins::Ranges; namespace KaleidoscopePlugins { - // --- state --- - char Syster::symbol[SYSTER_MAX_SYMBOL_LENGTH + 1]; - uint8_t Syster::symbolPos; - bool Syster::isActive; +// --- state --- +char Syster::symbol[SYSTER_MAX_SYMBOL_LENGTH + 1]; +uint8_t Syster::symbolPos; +bool Syster::isActive; - // --- helpers --- +// --- helpers --- #define isSyster(k) (k == SYSTER) - // --- api --- +// --- api --- - Syster::Syster (void) { - } +Syster::Syster (void) { +} - void - Syster::begin (void) { +void +Syster::begin (void) { event_handler_hook_use (this->eventHandlerHook); - } +} - void - Syster::reset (void) { +void +Syster::reset (void) { symbolPos = 0; symbol[0] = 0; isActive = false; - } +} - // --- hooks --- - Key - Syster::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) { +// --- hooks --- +Key +Syster::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) { if (!isActive) { - if (!isSyster (mappedKey)) - return mappedKey; + if (!isSyster (mappedKey)) + return mappedKey; - if (key_toggled_on (keyState)) { - isActive = true; - systerAction (StartAction, NULL); - } - return Key_NoKey; + if (key_toggled_on (keyState)) { + isActive = true; + systerAction (StartAction, NULL); + } + return Key_NoKey; } if (keyState & INJECTED) - return mappedKey; + return mappedKey; if (isSyster (mappedKey)) - return Key_NoKey; + return Key_NoKey; if (mappedKey == Key_Backspace && symbolPos == 0) - return Key_NoKey; + return Key_NoKey; if (key_toggled_off (keyState)) { - if (mappedKey == Key_Spacebar) { - for (uint8_t i = 0; i <= symbolPos; i++) { - handle_keyswitch_event (Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED); - Keyboard.sendReport (); - handle_keyswitch_event (Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED); - Keyboard.sendReport (); - } + if (mappedKey == Key_Spacebar) { + for (uint8_t i = 0; i <= symbolPos; i++) { + handle_keyswitch_event (Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED); + Keyboard.sendReport (); + handle_keyswitch_event (Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED); + Keyboard.sendReport (); + } - systerAction (EndAction, NULL); + systerAction (EndAction, NULL); - symbol[symbolPos] = 0; - systerAction (SymbolAction, symbol); - reset (); + symbol[symbolPos] = 0; + systerAction (SymbolAction, symbol); + reset (); - return Key_NoKey; - } + return Key_NoKey; + } } if (key_toggled_on (keyState)) { - if (mappedKey == Key_Backspace) { - if (symbolPos > 0) - symbolPos--; - } else { - const char c = keyToChar (mappedKey); - if (c) - symbol[symbolPos++] = c; - } + if (mappedKey == Key_Backspace) { + if (symbolPos > 0) + symbolPos--; + } else { + const char c = keyToChar (mappedKey); + if (c) + symbol[symbolPos++] = c; + } } return mappedKey; - } +} }; __attribute__((weak)) const char keyToChar (Key key) { - if (key.flags != 0) - return 0; - - switch (key.keyCode) { - case Key_A.keyCode ... Key_Z.keyCode: - return 'a' + (key.keyCode - Key_A.keyCode); - case Key_1.keyCode ... Key_0.keyCode: - return '1' + (key.keyCode - Key_1.keyCode); - } + if (key.flags != 0) + return 0; + + switch (key.keyCode) { + case Key_A.keyCode ... Key_Z.keyCode: + return 'a' + (key.keyCode - Key_A.keyCode); + case Key_1.keyCode ... Key_0.keyCode: + return '1' + (key.keyCode - Key_1.keyCode); + } - return 0; + return 0; } __attribute__((weak)) diff --git a/src/Kaleidoscope/Syster.h b/src/Kaleidoscope/Syster.h index 98903147..a398d40c 100644 --- a/src/Kaleidoscope/Syster.h +++ b/src/Kaleidoscope/Syster.h @@ -26,12 +26,12 @@ #define SYSTER (Key){ .raw = KaleidoscopePlugins::Ranges::SYSTER } namespace KaleidoscopePlugins { - class Syster : public KaleidoscopePlugin { +class Syster : public KaleidoscopePlugin { public: typedef enum { - StartAction, - EndAction, - SymbolAction + StartAction, + EndAction, + SymbolAction } action_t; Syster (void); @@ -45,7 +45,7 @@ namespace KaleidoscopePlugins { static bool isActive; static Key eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState); - }; +}; }; const char keyToChar (Key key);