diff options
author | Jesse Vincent <jesse@keyboard.io> | 2017-10-02 19:34:57 -0700 |
---|---|---|
committer | Jesse Vincent <jesse@keyboard.io> | 2017-10-02 19:34:57 -0700 |
commit | ac0a2c5ab8f7c0fd6cfda87accce5040c75d11e9 (patch) | |
tree | 1fcb36da5fb3d3f89901b27d82f48e0ed97b5345 | |
parent | 2f0beee0dbc92123d35b2135a1761fa1ec3fe4b2 (diff) | |
download | Model01-Firmware-ac0a2c5ab8f7c0fd6cfda87accce5040c75d11e9.tar.gz Model01-Firmware-ac0a2c5ab8f7c0fd6cfda87accce5040c75d11e9.zip |
Refactor macro code to remove hand-coded numbers and make code a bit more readable
-rw-r--r-- | Model01-Firmware.ino | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/Model01-Firmware.ino b/Model01-Firmware.ino index 4b32f42..e099647 100644 --- a/Model01-Firmware.ino +++ b/Model01-Firmware.ino @@ -23,8 +23,11 @@ #include "Kaleidoscope-LED-AlphaSquare.h" #include "Kaleidoscope-Model01-TestMode.h" -#define MACRO_VERSION_INFO 1 -#define MACRO_ANY 2 + +enum { MACRO_VERSION_INFO, + MACRO_ANY + }; + #define NUMPAD_KEYMAP_ID 2 @@ -93,19 +96,34 @@ static kaleidoscope::LEDSolidColor solidBlue(0, 70, 130); static kaleidoscope::LEDSolidColor solidIndigo(0, 0, 170); static kaleidoscope::LEDSolidColor solidViolet(130, 0, 120); + +static void versionInfoMacro(uint8_t keyState) { + if (keyToggledOn(keyState)) { + Macros.type(PSTR("Keyboardio Model 01 - Kaleidoscope ")); + Macros.type(PSTR(BUILD_INFORMATION)); + } + +} + +static void anyKeyMacro(uint8_t keyState) { + static Key lastKey; + if (keyToggledOn(keyState)) + lastKey.keyCode = Key_A.keyCode + (uint8_t)(millis() % 36); + + if (keyIsPressed(keyState)) + kaleidoscope::hid::pressKey(lastKey); +} + + const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { - if (macroIndex == MACRO_VERSION_INFO) { - if (keyToggledOn(keyState)) { - Macros.type(PSTR("Keyboardio Model 01 - Kaleidoscope ")); - Macros.type(PSTR(BUILD_INFORMATION)); - } - } else if (macroIndex == MACRO_ANY) { - static Key lastKey; - if (keyToggledOn(keyState)) - lastKey.keyCode = Key_A.keyCode + (uint8_t)(millis() % 36); - - if (keyIsPressed(keyState)) - kaleidoscope::hid::pressKey(lastKey); + switch (macroIndex) { + case MACRO_VERSION_INFO: + versionInfoMacro(keyState); + break; + + case MACRO_ANY: + anyKeyMacro(keyState); + break; } return MACRO_NONE; } |