diff --git a/src/Kaleidoscope-Macros.cpp b/src/Kaleidoscope-Macros.cpp index 069e300f..6680c30f 100644 --- a/src/Kaleidoscope-Macros.cpp +++ b/src/Kaleidoscope-Macros.cpp @@ -2,94 +2,94 @@ __attribute__((weak)) const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { - return MACRO_NONE; + return MACRO_NONE; } byte Macros_::row, Macros_::col; -static void readKeyCodeAndPlay (const macro_t *macro_p, uint8_t flags, uint8_t keyStates) { - Key key; - key.flags = flags; - key.keyCode = pgm_read_byte(macro_p++); - - if (keyStates & IS_PRESSED) { - handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED); - Keyboard.sendReport(); - } - if (keyStates & WAS_PRESSED) { - handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED); - Keyboard.sendReport(); - } +static void readKeyCodeAndPlay(const macro_t *macro_p, uint8_t flags, uint8_t keyStates) { + Key key; + key.flags = flags; + key.keyCode = pgm_read_byte(macro_p++); + + if (keyStates & IS_PRESSED) { + handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED); + Keyboard.sendReport(); + } + if (keyStates & WAS_PRESSED) { + handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED); + Keyboard.sendReport(); + } } void Macros_::play(const macro_t *macro_p) { - macro_t macro = END; - uint8_t interval = 0; - uint8_t flags; - - if (!macro_p) - return; - - while (true) { - switch (macro = pgm_read_byte(macro_p++)) { - case MACRO_ACTION_STEP_INTERVAL: - interval = pgm_read_byte(macro_p++); - break; - case MACRO_ACTION_STEP_WAIT: { - uint8_t wait = pgm_read_byte(macro_p++); - delay(wait); - break; - } - case MACRO_ACTION_STEP_KEYDOWN: - flags = pgm_read_byte(macro_p++); - readKeyCodeAndPlay (macro_p++, flags, IS_PRESSED); - break; - case MACRO_ACTION_STEP_KEYUP: - flags = pgm_read_byte(macro_p++); - readKeyCodeAndPlay (macro_p++, flags, WAS_PRESSED); - break; - case MACRO_ACTION_STEP_TAP: - flags = pgm_read_byte(macro_p++); - readKeyCodeAndPlay (macro_p++, flags, IS_PRESSED | WAS_PRESSED); - break; - - case MACRO_ACTION_STEP_KEYCODEDOWN: - readKeyCodeAndPlay (macro_p++, 0, IS_PRESSED); - break; - case MACRO_ACTION_STEP_KEYCODEUP: - readKeyCodeAndPlay (macro_p++, 0, WAS_PRESSED); - break; - case MACRO_ACTION_STEP_TAPCODE: - readKeyCodeAndPlay (macro_p++, 0, IS_PRESSED | WAS_PRESSED); - break; - - case END: - default: - return; - } - - delay(interval); + macro_t macro = END; + uint8_t interval = 0; + uint8_t flags; + + if (!macro_p) + return; + + while (true) { + switch (macro = pgm_read_byte(macro_p++)) { + case MACRO_ACTION_STEP_INTERVAL: + interval = pgm_read_byte(macro_p++); + break; + case MACRO_ACTION_STEP_WAIT: { + uint8_t wait = pgm_read_byte(macro_p++); + delay(wait); + break; } + case MACRO_ACTION_STEP_KEYDOWN: + flags = pgm_read_byte(macro_p++); + readKeyCodeAndPlay(macro_p++, flags, IS_PRESSED); + break; + case MACRO_ACTION_STEP_KEYUP: + flags = pgm_read_byte(macro_p++); + readKeyCodeAndPlay(macro_p++, flags, WAS_PRESSED); + break; + case MACRO_ACTION_STEP_TAP: + flags = pgm_read_byte(macro_p++); + readKeyCodeAndPlay(macro_p++, flags, IS_PRESSED | WAS_PRESSED); + break; + + case MACRO_ACTION_STEP_KEYCODEDOWN: + readKeyCodeAndPlay(macro_p++, 0, IS_PRESSED); + break; + case MACRO_ACTION_STEP_KEYCODEUP: + readKeyCodeAndPlay(macro_p++, 0, WAS_PRESSED); + break; + case MACRO_ACTION_STEP_TAPCODE: + readKeyCodeAndPlay(macro_p++, 0, IS_PRESSED | WAS_PRESSED); + break; + + case END: + default: + return; + } + + delay(interval); + } } static Key handleMacroEvent(Key mappedKey, byte row, byte col, uint8_t keyState) { - if (mappedKey.flags != (SYNTHETIC | IS_MACRO)) - return mappedKey; + if (mappedKey.flags != (SYNTHETIC | IS_MACRO)) + return mappedKey; - Macros_::row = row; - Macros_::col = col; - const macro_t *m = macroAction(mappedKey.keyCode, keyState); + Macros_::row = row; + Macros_::col = col; + const macro_t *m = macroAction(mappedKey.keyCode, keyState); - Macros.play(m); - return Key_NoKey; + Macros.play(m); + return Key_NoKey; } -Macros_::Macros_ (void) { +Macros_::Macros_(void) { } void -Macros_::begin (void) { - event_handler_hook_use (handleMacroEvent); +Macros_::begin(void) { + event_handler_hook_use(handleMacroEvent); } Macros_ Macros; diff --git a/src/Kaleidoscope-Macros.h b/src/Kaleidoscope-Macros.h index 0354d077..d37befd7 100644 --- a/src/Kaleidoscope-Macros.h +++ b/src/Kaleidoscope-Macros.h @@ -8,14 +8,14 @@ const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState); class Macros_ : public KaleidoscopePlugin { - public: - Macros_(void); + public: + Macros_(void); - virtual void begin(void) final; + virtual void begin(void) final; - void play(const macro_t *macro_p); + void play(const macro_t *macro_p); - static byte row, col; + static byte row, col; }; extern Macros_ Macros; diff --git a/src/MacroSteps.h b/src/MacroSteps.h index 7b92f526..be21676f 100644 --- a/src/MacroSteps.h +++ b/src/MacroSteps.h @@ -1,18 +1,18 @@ #pragma once typedef enum { - MACRO_ACTION_END, + MACRO_ACTION_END, - MACRO_ACTION_STEP_INTERVAL, - MACRO_ACTION_STEP_WAIT, + MACRO_ACTION_STEP_INTERVAL, + MACRO_ACTION_STEP_WAIT, - MACRO_ACTION_STEP_KEYDOWN, - MACRO_ACTION_STEP_KEYUP, - MACRO_ACTION_STEP_TAP, + MACRO_ACTION_STEP_KEYDOWN, + MACRO_ACTION_STEP_KEYUP, + MACRO_ACTION_STEP_TAP, - MACRO_ACTION_STEP_KEYCODEDOWN, - MACRO_ACTION_STEP_KEYCODEUP, - MACRO_ACTION_STEP_TAPCODE, + MACRO_ACTION_STEP_KEYCODEDOWN, + MACRO_ACTION_STEP_KEYCODEUP, + MACRO_ACTION_STEP_TAPCODE, } MacroActionStepType; typedef uint8_t macro_t;