diff --git a/examples/Cycle/Cycle.ino b/examples/Cycle/Cycle.ino index b31fb593..49a206b9 100644 --- a/examples/Cycle/Cycle.ino +++ b/examples/Cycle/Cycle.ino @@ -20,43 +20,43 @@ #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_Cycle, - - 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_Cycle), + [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_Cycle, + + 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_Cycle), }; void cycleAction(Key previous_key, uint8_t cycle_count) { - if (previous_key.raw == Key_E.raw) { - if (cycle_count == 1) { - Cycle.replace(Key_F); - } else if (cycle_count == 2) { - Cycle.replace(Key_G); - } - } - if (previous_key.raw == Key_A.raw) { - cycleThrough(Key_A, Key_B, Key_C, Key_D); + if (previous_key.raw == Key_E.raw) { + if (cycle_count == 1) { + Cycle.replace(Key_F); + } else if (cycle_count == 2) { + Cycle.replace(Key_G); } + } + if (previous_key.raw == Key_A.raw) { + cycleThrough(Key_A, Key_B, Key_C, Key_D); + } } void setup() { - USE_PLUGINS(&Cycle); + USE_PLUGINS(&Cycle); - Kaleidoscope.setup(); + Kaleidoscope.setup(); } void loop() { - Kaleidoscope.loop(); + Kaleidoscope.loop(); } diff --git a/src/Kaleidoscope/Cycle.cpp b/src/Kaleidoscope/Cycle.cpp index be1adf1d..c1deff39 100644 --- a/src/Kaleidoscope/Cycle.cpp +++ b/src/Kaleidoscope/Cycle.cpp @@ -34,55 +34,55 @@ Cycle::Cycle(void) { } void Cycle::begin(void) { - event_handler_hook_use(eventHandlerHook); + event_handler_hook_use(eventHandlerHook); } void Cycle::replace(Key key) { - 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(); - - handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED); - Keyboard.sendReport(); - handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED); - Keyboard.sendReport(); + 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(); + + handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED); + Keyboard.sendReport(); + handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED); + Keyboard.sendReport(); } void Cycle::replace(uint8_t cycle_size, const Key cycle_steps[]) { - uint8_t idx = cycle_count_ % cycle_size; - Key key; + uint8_t idx = cycle_count_ % cycle_size; + Key key; - key.raw = pgm_read_word(cycle_steps + idx); - replace(key); + key.raw = pgm_read_word(cycle_steps + idx); + replace(key); } // --- hooks --- Key Cycle::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) { - if (key_state & INJECTED) - return mapped_key; - - if (!key_is_pressed(key_state) && !key_was_pressed(key_state)) { - if (isCycle(mapped_key)) - return Key_NoKey; - return mapped_key; - } - - if (!isCycle(mapped_key)) { - if (key_toggled_on(key_state)) { - last_non_cycle_key_.raw = mapped_key.raw; - cycle_count_ = 0; - } - return mapped_key; + if (key_state & INJECTED) + return mapped_key; + + if (!key_is_pressed(key_state) && !key_was_pressed(key_state)) { + if (isCycle(mapped_key)) + return Key_NoKey; + return mapped_key; + } + + if (!isCycle(mapped_key)) { + if (key_toggled_on(key_state)) { + last_non_cycle_key_.raw = mapped_key.raw; + cycle_count_ = 0; } + return mapped_key; + } - if (!key_toggled_off(key_state)) - return Key_NoKey; - - ++cycle_count_; - cycleAction(last_non_cycle_key_, cycle_count_); + if (!key_toggled_off(key_state)) return Key_NoKey; + + ++cycle_count_; + cycleAction(last_non_cycle_key_, cycle_count_); + return Key_NoKey; } }; diff --git a/src/Kaleidoscope/Cycle.h b/src/Kaleidoscope/Cycle.h index ece5deb5..2ed4632f 100644 --- a/src/Kaleidoscope/Cycle.h +++ b/src/Kaleidoscope/Cycle.h @@ -30,19 +30,19 @@ namespace kaleidoscope { class Cycle : public KaleidoscopePlugin { - public: - Cycle(void); + public: + Cycle(void); - void begin(void) final; + void begin(void) final; - static void replace(Key key); - static void replace(uint8_t cycle_size, const Key cycle_steps[]); + static void replace(Key key); + static void replace(uint8_t cycle_size, const Key cycle_steps[]); - private: - static Key last_non_cycle_key_; - static uint8_t cycle_count_; + private: + static Key last_non_cycle_key_; + static uint8_t cycle_count_; - static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state); + static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state); }; };