From fe35cfad76078ac5bd76a003e43b7e925cc1e90d Mon Sep 17 00:00:00 2001 From: dakkar Date: Sun, 10 Feb 2019 18:02:41 +0000 Subject: split everything into their own files --- Model01-Firmware.ino | 94 ++-------------------------------------------------- color-themes.h | 3 ++ combos.h | 19 +++++++++++ macros.h | 44 ++++++++++++++++++++++++ power-management.h | 24 ++++++++++++++ 5 files changed, 93 insertions(+), 91 deletions(-) create mode 100644 combos.h create mode 100644 macros.h create mode 100644 power-management.h diff --git a/Model01-Firmware.ino b/Model01-Firmware.ino index c77e319..24dc649 100644 --- a/Model01-Firmware.ino +++ b/Model01-Firmware.ino @@ -1,105 +1,17 @@ // -*- mode: c++ -*- -#ifndef BUILD_INFORMATION -#define BUILD_INFORMATION "locally built" -#endif - #include "Kaleidoscope.h" +#include "macros.h" -/* macros */ -#include "kaleidoscope/plugin/Macros.h" - -enum { MACRO_VERSION_INFO, - MACRO_ANY - }; -#include "kaleidoscope/plugin/HostPowerManagement.h" - -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; - bool toggledOn = false; - if (keyToggledOn(keyState)) { - lastKey.keyCode = Key_A.keyCode + (uint8_t)(millis() % 36); - toggledOn = true; - } - - if (keyIsPressed(keyState)) - kaleidoscope::hid::pressKey(lastKey, toggledOn); -} - -const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { - switch (macroIndex) { - - case MACRO_VERSION_INFO: - versionInfoMacro(keyState); - break; - - case MACRO_ANY: - anyKeyMacro(keyState); - break; - } - return MACRO_NONE; -} - -/* power management */ -#include "kaleidoscope/plugin/LEDControl.h" - -void toggleLedsOnSuspendResume(kaleidoscope::plugin::HostPowerManagement::Event event) { - switch (event) { - case kaleidoscope::plugin::HostPowerManagement::Suspend: - LEDControl.set_all_leds_to({0, 0, 0}); - LEDControl.syncLeds(); - LEDControl.paused = true; - break; - case kaleidoscope::plugin::HostPowerManagement::Resume: - LEDControl.paused = false; - LEDControl.refreshAll(); - break; - case kaleidoscope::plugin::HostPowerManagement::Sleep: - break; - } -} - -void hostPowerManagementEventHandler(kaleidoscope::plugin::HostPowerManagement::Event event) { - toggleLedsOnSuspendResume(event); -} - -/* combos */ -#include "kaleidoscope/plugin/MagicCombo.h" -#include "kaleidoscope/plugin/USB-Quirks.h" +#include "power-management.h" -enum { - // Toggle between Boot (6-key rollover; for BIOSes and early boot) and NKRO - // mode. - COMBO_TOGGLE_NKRO_MODE -}; - -static void toggleKeyboardProtocol(uint8_t combo_index) { - USBQuirks.toggleKeyboardProtocol(); -} - -USE_MAGIC_COMBOS({.action = toggleKeyboardProtocol, - // Left Fn + Esc + Shift - .keys = { R3C6, R2C6, R3C7 } - }); - -/* keymaps */ +#include "combos.h" #include "keymap-wrapper.h" -/* LED & colors */ #include "color-themes.h" -static DakkarColor DakkarColorDark(color_keymaps,dark_colors); -static DakkarColor DakkarColorBright(color_keymaps,bright_colors); - /* plugins */ #include "kaleidoscope/plugin/EEPROM-Settings.h" #include "kaleidoscope/plugin/FocusSerial.h" diff --git a/color-themes.h b/color-themes.h index 267c064..c78d26f 100644 --- a/color-themes.h +++ b/color-themes.h @@ -48,3 +48,6 @@ static constexpr DakkarColor::colorSrc bright_colors[COLOR_COUNT] = [Num] = D_C(100,0,0), [NumBreathe] = D_F(num_breathe), }; + +static DakkarColor DakkarColorDark(color_keymaps,dark_colors); +static DakkarColor DakkarColorBright(color_keymaps,bright_colors); diff --git a/combos.h b/combos.h new file mode 100644 index 0000000..5979cef --- /dev/null +++ b/combos.h @@ -0,0 +1,19 @@ +#pragma once + +#include "kaleidoscope/plugin/MagicCombo.h" +#include "kaleidoscope/plugin/USB-Quirks.h" + +enum { + // Toggle between Boot (6-key rollover; for BIOSes and early boot) and NKRO + // mode. + COMBO_TOGGLE_NKRO_MODE +}; + +static void toggleKeyboardProtocol(uint8_t combo_index) { + USBQuirks.toggleKeyboardProtocol(); +} + +USE_MAGIC_COMBOS({.action = toggleKeyboardProtocol, + // Left Fn + Esc + Shift + .keys = { R3C6, R2C6, R3C7 } + }); diff --git a/macros.h b/macros.h new file mode 100644 index 0000000..5c97d64 --- /dev/null +++ b/macros.h @@ -0,0 +1,44 @@ +#pragma once + +#include "kaleidoscope/plugin/Macros.h" + +enum { MACRO_VERSION_INFO, + MACRO_ANY + }; + +#ifndef BUILD_INFORMATION +#define BUILD_INFORMATION "locally built" +#endif + +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; + bool toggledOn = false; + if (keyToggledOn(keyState)) { + lastKey.keyCode = Key_A.keyCode + (uint8_t)(millis() % 36); + toggledOn = true; + } + + if (keyIsPressed(keyState)) + kaleidoscope::hid::pressKey(lastKey, toggledOn); +} + +const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { + switch (macroIndex) { + + case MACRO_VERSION_INFO: + versionInfoMacro(keyState); + break; + + case MACRO_ANY: + anyKeyMacro(keyState); + break; + } + return MACRO_NONE; +} diff --git a/power-management.h b/power-management.h new file mode 100644 index 0000000..3fcbd70 --- /dev/null +++ b/power-management.h @@ -0,0 +1,24 @@ +#pragma once + +#include "kaleidoscope/plugin/HostPowerManagement.h" +#include "kaleidoscope/plugin/LEDControl.h" + +void toggleLedsOnSuspendResume(kaleidoscope::plugin::HostPowerManagement::Event event) { + switch (event) { + case kaleidoscope::plugin::HostPowerManagement::Suspend: + LEDControl.set_all_leds_to({0, 0, 0}); + LEDControl.syncLeds(); + LEDControl.paused = true; + break; + case kaleidoscope::plugin::HostPowerManagement::Resume: + LEDControl.paused = false; + LEDControl.refreshAll(); + break; + case kaleidoscope::plugin::HostPowerManagement::Sleep: + break; + } +} + +void hostPowerManagementEventHandler(kaleidoscope::plugin::HostPowerManagement::Event event) { + toggleLedsOnSuspendResume(event); +} -- cgit v1.2.3