From ac0a2c5ab8f7c0fd6cfda87accce5040c75d11e9 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 2 Oct 2017 19:34:57 -0700 Subject: Refactor macro code to remove hand-coded numbers and make code a bit more readable --- Model01-Firmware.ino | 46 ++++++++++++++++++++++++++++++++-------------- 1 file 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; } -- cgit v1.2.3