From 1d7008d96faa07fe544215df602f581ab99bb58f Mon Sep 17 00:00:00 2001 From: Florian Fleissner Date: Tue, 3 Dec 2019 15:41:04 +0100 Subject: [PATCH] Extracted and renamed class Kaleidoscope->Runtime This was done to enable separate inclusion of the central runtime class without having to include the central header kaleidoscope/Kaleidoscope.h which used to pull in a lot of stuff that is not required in many compilation units. The new class `Runtime_` lives in namespace kaleidoscope its singleton instance is `kaleidoscope::Runtime`. It is now only available internally in library Kaleidoscope but not from the sketch. The original class name `Kaleidoscope_` in global scope has been deprecated. The original instance name `Kaleidoscope` in global scope has been preserved to be used by end users in their sketches. Signed-off-by: Florian Fleissner --- UPGRADING.md | 4 + src/Kaleidoscope.h | 104 +++++++++++++++- src/kaleidoscope/Hardware.h | 2 +- src/kaleidoscope/MatrixAddr.h | 2 +- .../{Kaleidoscope.cpp => Runtime.cpp} | 18 +-- .../{Kaleidoscope.h => Runtime.h} | 112 ++---------------- src/kaleidoscope/bitfields.cpp | 2 +- src/kaleidoscope/bitfields.h | 1 + src/kaleidoscope/device/dygma/Raise.cpp | 14 +-- src/kaleidoscope/device/dygma/raise/Focus.cpp | 34 +++--- src/kaleidoscope/device/dygma/raise/Focus.h | 2 +- .../device/dygma/raise/SideFlash.h | 11 +- src/kaleidoscope/device/ez/ErgoDox.cpp | 3 +- src/kaleidoscope/device/kbdfans/KBD4x.cpp | 5 +- src/kaleidoscope/device/keyboardio/Imago.cpp | 7 +- .../device/keyboardio/Model01.cpp | 5 +- src/kaleidoscope/device/olkb/Planck.cpp | 3 +- .../device/softhruf/Splitography.cpp | 3 +- .../device/technomancy/Atreus.cpp | 3 +- .../device/technomancy/Atreus2.cpp | 3 +- src/kaleidoscope/device/virtual/Virtual.cpp | 6 +- .../driver/bootloader/avr/FLIP.cpp | 2 +- src/kaleidoscope/driver/keyscanner/ATmega.h | 2 +- .../driver/keyscanner/Base_Impl.h | 33 ++++++ src/kaleidoscope/hooks.cpp | 4 +- src/kaleidoscope/hooks.h | 4 +- src/kaleidoscope/key_defs_keymaps.h | 2 + src/kaleidoscope/key_events.cpp | 13 +- src/kaleidoscope/key_events.h | 15 +-- src/kaleidoscope/keymaps.h | 2 + src/kaleidoscope/layers.cpp | 10 +- src/kaleidoscope/plugin/Colormap.cpp | 3 +- src/kaleidoscope/plugin/Cycle.cpp | 4 +- src/kaleidoscope/plugin/Cycle.h | 2 +- src/kaleidoscope/plugin/CycleTimeReport.cpp | 6 +- src/kaleidoscope/plugin/CycleTimeReport.h | 2 +- src/kaleidoscope/plugin/DynamicMacros.cpp | 36 +++--- src/kaleidoscope/plugin/DynamicMacros.h | 2 +- .../plugin/EEPROM-Keymap-Programmer.cpp | 8 +- .../plugin/EEPROM-Keymap-Programmer.h | 2 +- src/kaleidoscope/plugin/EEPROM-Keymap.cpp | 17 +-- src/kaleidoscope/plugin/EEPROM-Keymap.h | 2 +- src/kaleidoscope/plugin/EEPROM-Settings.cpp | 21 ++-- src/kaleidoscope/plugin/EEPROM-Settings.h | 2 +- src/kaleidoscope/plugin/Escape-OneShot.cpp | 5 +- src/kaleidoscope/plugin/Escape-OneShot.h | 2 +- src/kaleidoscope/plugin/FingerPainter.cpp | 13 +- src/kaleidoscope/plugin/FirmwareDump.h | 2 +- src/kaleidoscope/plugin/FocusSerial.cpp | 24 ++-- src/kaleidoscope/plugin/FocusSerial.h | 26 ++-- src/kaleidoscope/plugin/GeminiPR.cpp | 3 +- src/kaleidoscope/plugin/GeminiPR.h | 2 +- .../plugin/GhostInTheFirmware.cpp | 11 +- src/kaleidoscope/plugin/GhostInTheFirmware.h | 2 +- src/kaleidoscope/plugin/HardwareTestMode.cpp | 29 ++--- src/kaleidoscope/plugin/HardwareTestMode.h | 2 +- src/kaleidoscope/plugin/Heatmap.cpp | 15 +-- src/kaleidoscope/plugin/Heatmap.h | 4 +- src/kaleidoscope/plugin/HostOS-Focus.h | 2 +- src/kaleidoscope/plugin/HostOS.cpp | 6 +- src/kaleidoscope/plugin/HostOS.h | 2 +- .../plugin/HostPowerManagement.cpp | 2 +- src/kaleidoscope/plugin/HostPowerManagement.h | 2 +- src/kaleidoscope/plugin/IdleLEDs.cpp | 10 +- src/kaleidoscope/plugin/IdleLEDs.h | 2 +- .../plugin/LED-ActiveLayerColor.cpp | 3 +- .../plugin/LED-ActiveModColor.cpp | 3 +- src/kaleidoscope/plugin/LED-ActiveModColor.h | 2 +- src/kaleidoscope/plugin/LED-AlphaSquare.cpp | 8 +- src/kaleidoscope/plugin/LED-AlphaSquare.h | 2 +- .../plugin/LED-AlphaSquare/Effect.cpp | 21 ++-- .../plugin/LED-AlphaSquare/Effect.h | 2 +- src/kaleidoscope/plugin/LED-Palette-Theme.cpp | 40 +++---- src/kaleidoscope/plugin/LED-Palette-Theme.h | 2 +- src/kaleidoscope/plugin/LED-Stalker.cpp | 9 +- src/kaleidoscope/plugin/LED-Stalker.h | 4 +- src/kaleidoscope/plugin/LED-Wavepool.cpp | 7 +- src/kaleidoscope/plugin/LED-Wavepool.h | 4 +- src/kaleidoscope/plugin/LEDControl.cpp | 23 ++-- src/kaleidoscope/plugin/LEDControl.h | 9 +- .../plugin/LEDControl/LEDUtils.cpp | 5 +- src/kaleidoscope/plugin/LEDControl/LEDUtils.h | 2 +- .../plugin/LEDEffect-BootAnimation.cpp | 5 +- .../plugin/LEDEffect-BootAnimation.h | 2 +- .../plugin/LEDEffect-BootGreeting.cpp | 5 +- src/kaleidoscope/plugin/LEDEffect-Breathe.cpp | 4 +- src/kaleidoscope/plugin/LEDEffect-Chase.cpp | 12 +- src/kaleidoscope/plugin/LEDEffect-Chase.h | 2 +- src/kaleidoscope/plugin/LEDEffect-Rainbow.cpp | 14 +-- src/kaleidoscope/plugin/LEDMode.h | 2 +- src/kaleidoscope/plugin/Leader.cpp | 9 +- src/kaleidoscope/plugin/Leader.h | 2 +- src/kaleidoscope/plugin/Macros.cpp | 2 + src/kaleidoscope/plugin/Macros.h | 6 +- src/kaleidoscope/plugin/MagicCombo.cpp | 8 +- src/kaleidoscope/plugin/MagicCombo.h | 2 +- src/kaleidoscope/plugin/Model01-TestMode.h | 2 +- src/kaleidoscope/plugin/MouseKeys.cpp | 22 ++-- src/kaleidoscope/plugin/MouseKeys.h | 2 +- src/kaleidoscope/plugin/NumPad.cpp | 1 + src/kaleidoscope/plugin/OneShot.cpp | 10 +- src/kaleidoscope/plugin/OneShot.h | 4 +- src/kaleidoscope/plugin/PersistentLEDMode.cpp | 8 +- src/kaleidoscope/plugin/PersistentLEDMode.h | 2 +- src/kaleidoscope/plugin/Qukeys.cpp | 7 +- src/kaleidoscope/plugin/Qukeys.h | 2 +- .../plugin/Qukeys/KeyAddrEventQueue.h | 5 +- src/kaleidoscope/plugin/Redial.cpp | 1 + src/kaleidoscope/plugin/Redial.h | 2 +- src/kaleidoscope/plugin/ShapeShifter.h | 2 +- src/kaleidoscope/plugin/SpaceCadet.cpp | 6 +- src/kaleidoscope/plugin/SpaceCadet.h | 2 +- src/kaleidoscope/plugin/Syster.cpp | 2 + src/kaleidoscope/plugin/Syster.h | 2 +- src/kaleidoscope/plugin/TapDance.cpp | 11 +- src/kaleidoscope/plugin/TapDance.h | 2 +- src/kaleidoscope/plugin/TopsyTurvy.cpp | 1 + src/kaleidoscope/plugin/TopsyTurvy.h | 2 +- src/kaleidoscope/plugin/TriColor.cpp | 1 + src/kaleidoscope/plugin/TriColor.h | 2 +- src/kaleidoscope/plugin/Turbo.cpp | 13 +- src/kaleidoscope/plugin/Turbo.h | 2 +- src/kaleidoscope/plugin/TypingBreaks.cpp | 27 +++-- src/kaleidoscope/plugin/TypingBreaks.h | 2 +- src/kaleidoscope/plugin/USB-Quirks.cpp | 4 +- src/kaleidoscope/plugin/USB-Quirks.h | 2 +- src/kaleidoscope/plugin/Unicode.h | 2 +- src/kaleidoscope/plugin/WinKeyToggle.cpp | 2 +- src/kaleidoscope/plugin/WinKeyToggle.h | 2 +- src/kaleidoscope_internal/deprecations.h | 8 ++ src/kaleidoscope_internal/device.cpp | 2 +- src/kaleidoscope_internal/device.h | 2 + 132 files changed, 610 insertions(+), 484 deletions(-) rename src/kaleidoscope/{Kaleidoscope.cpp => Runtime.cpp} (85%) rename src/kaleidoscope/{Kaleidoscope.h => Runtime.h} (53%) create mode 100644 src/kaleidoscope/driver/keyscanner/Base_Impl.h diff --git a/UPGRADING.md b/UPGRADING.md index c62f2940..d26aa354 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -488,6 +488,10 @@ Older versions of the plugin required one to set up `Key_Redial` manually, and l ## Deprecated APIs and their replacements +### Class/global instance Kaleidoscope_/Kaleidoscope renamed to kaleidoscope::Runtime_/kaleidoscope::Runtime + +After renaming, some of the original symbols have been deprecated. The deprecated symbols in `kaleidoscope/Runtime.h` are scheduled for removal on **2019-03-10**. + ### Transition to linear indexing Row/col based indexing was replaced by linear indexing throughout the whole firmware. A compatibility layer of functions was introduced that allows diff --git a/src/Kaleidoscope.h b/src/Kaleidoscope.h index be7e344f..321ce65e 100644 --- a/src/Kaleidoscope.h +++ b/src/Kaleidoscope.h @@ -16,4 +16,106 @@ #pragma once -#include "kaleidoscope/Kaleidoscope.h" +#include + +//end of add your includes here +#ifdef __cplusplus +extern "C" { +#endif +void loop(); +void setup(); +#ifdef __cplusplus +} // extern "C" +#endif + +//add your function definitions for the project KeyboardIO here + +#define TS(X) //Serial.print(micros() );Serial.print("\t");Serial.println(X); + +#include +#include +#include + +#include "kaleidoscope/device/device.h" +#include "kaleidoscope/device/key_indexes.h" +#include "kaleidoscope_internal/device.h" +#include "kaleidoscope_internal/deprecations.h" + +static constexpr DEPRECATED(KEYBOARDHARDWARE) kaleidoscope::Device &KeyboardHardware = kaleidoscope_internal::device; + +#ifdef PER_KEY_DATA_STACKED +#define KEYMAP_STACKED(...) { PER_KEY_DATA_STACKED(XXX, __VA_ARGS__) } +#endif + +#ifdef PER_KEY_DATA +#define KEYMAP(...) { PER_KEY_DATA(XXX, __VA_ARGS__) } +#endif + +static constexpr DEPRECATED(ROWS) uint8_t ROWS = kaleidoscope_internal::device.matrix_rows; +static constexpr DEPRECATED(COLS) uint8_t COLS = kaleidoscope_internal::device.matrix_columns; +static constexpr DEPRECATED(LED_COUNT) uint8_t LED_COUNT = kaleidoscope_internal::device.led_count; + +#include "kaleidoscope/KeyAddr.h" +#include "kaleidoscope/key_events.h" +#include "kaleidoscope/hid.h" +#include "kaleidoscope/layers.h" +#include "kaleidoscope_internal/sketch_exploration/sketch_exploration.h" +#include "kaleidoscope/macro_map.h" +#include "kaleidoscope_internal/event_dispatch.h" +#include "kaleidoscope_internal/LEDModeManager.h" +#include "kaleidoscope/macro_helpers.h" +#include "kaleidoscope/plugin.h" +#include "kaleidoscope/Runtime.h" + +#define HOOK_MAX 64 + +#ifndef VERSION +#define VERSION "locally-built" +#endif + +/** Kaleidoscope API (major) version. + * + * The API is guaranteed to be backwards compatible for the entire duration of a + * major version. However, breaking changes may come, and result in a major + * version bump. To help migration, the `KALEIDOSCOPE_API_VERSION` macro can be + * used to check the major version provided by the Kaleidoscope we are compiling + * against. This can be used to error out with a helpful message, or change how + * the API is used - it is entirely up to the plugin or sketch author. The point + * of this macro is to let them easily check the version. + */ +#define KALEIDOSCOPE_API_VERSION 2 + +/** Required Kaleidoscope major version. + * + * For the sake of convenience, defining `KALEIDOSCOPE_REQUIRED_API_VERSION` + * before including `Kaleidoscope.h` itself will result in comparing its value + * to `KALEIDOSCOPE_API_VERSION`. If they differ, a helpful error message is + * printed. + * + * Done so that a new API version would result in a helpful error message, + * instead of cryptic compile errors. + */ +#if defined(KALEIDOSCOPE_REQUIRED_API_VERSION) && (KALEIDOSCOPE_REQUIRED_API_VERSION != KALEIDOSCOPE_API_VERSION) +#define xstr(a) str(a) +#define str(a) #a +static_assert(KALEIDOSCOPE_REQUIRED_API_VERSION == KALEIDOSCOPE_API_VERSION, + "Kaleidoscope API version mismatch! We have version " xstr(KALEIDOSCOPE_API_VERSION) + " available, but version " xstr(KALEIDOSCOPE_REQUIRED_API_VERSION) " is required."); +#endif + +// Use this function macro to register plugins with Kaleidoscope's +// hooking system. The macro accepts a list of plugin instances that +// must have been instantiated at global scope. +// +#define KALEIDOSCOPE_INIT_PLUGINS(...) _KALEIDOSCOPE_INIT_PLUGINS(__VA_ARGS__) + +// For compatibility reasons we export class Runtime_ as Kaleidoscope_ +// in global namespace. +// +DEPRECATED(GLOBAL_TYPENAME_KALEIDOSCOPE) +typedef kaleidoscope::Runtime_ Kaleidoscope_; + +// For compatibility/usability reasons we enable the global variable +// Kaleidoscope in global namespace. +// +extern kaleidoscope::Runtime_ &Kaleidoscope; diff --git a/src/kaleidoscope/Hardware.h b/src/kaleidoscope/Hardware.h index 8f231c47..522e414b 100644 --- a/src/kaleidoscope/Hardware.h +++ b/src/kaleidoscope/Hardware.h @@ -246,7 +246,7 @@ class Hardware { * * Because different hardware has different ways to accomplish this, the * hardware plugin must provide these functions. Kaleidoscope will wrap them, - * so user code does not have to deal with `Kaleidoscope.device()`. + * so user code does not have to deal with `Runtime.device()`. * @{ */ /** diff --git a/src/kaleidoscope/MatrixAddr.h b/src/kaleidoscope/MatrixAddr.h index ae2b7c1c..f8012c35 100644 --- a/src/kaleidoscope/MatrixAddr.h +++ b/src/kaleidoscope/MatrixAddr.h @@ -211,7 +211,7 @@ class MatrixAddr { // cause ambiguous symbol lookup when used in the regular firmware. // // To use them also for the regular firmware they would need to be -// disambiguated by moving them to the Kaleidoscope.h header and replacing +// disambiguated by moving them to the Runtime.h header and replacing // them with non-template versions that operate on the actual typedefed // KeyAddr and KeyAddr. diff --git a/src/kaleidoscope/Kaleidoscope.cpp b/src/kaleidoscope/Runtime.cpp similarity index 85% rename from src/kaleidoscope/Kaleidoscope.cpp rename to src/kaleidoscope/Runtime.cpp index 2ce2dfca..44f09c94 100644 --- a/src/kaleidoscope/Kaleidoscope.cpp +++ b/src/kaleidoscope/Runtime.cpp @@ -14,18 +14,20 @@ * this program. If not, see . */ -#include "kaleidoscope/Kaleidoscope.h" -#include +#include "kaleidoscope/Runtime.h" +#include "kaleidoscope/hid.h" +#include "kaleidoscope/layers.h" +#include "kaleidoscope/keyswitch_state.h" namespace kaleidoscope { -uint32_t Kaleidoscope_::millis_at_cycle_start_; +uint32_t Runtime_::millis_at_cycle_start_; -Kaleidoscope_::Kaleidoscope_(void) { +Runtime_::Runtime_(void) { } void -Kaleidoscope_::setup(void) { +Runtime_::setup(void) { // We are explicitly initializing the Serial port as early as possible to // (temporarily, hopefully) work around an issue on OSX. If we initialize // Serial too late, no matter what we do, we'll end up reading garbage from @@ -53,7 +55,7 @@ Kaleidoscope_::setup(void) { } void -Kaleidoscope_::loop(void) { +Runtime_::loop(void) { millis_at_cycle_start_ = millis(); kaleidoscope::Hooks::beforeEachCycle(); @@ -68,6 +70,8 @@ Kaleidoscope_::loop(void) { kaleidoscope::Hooks::afterEachCycle(); } -Kaleidoscope_ Kaleidoscope; +Runtime_ Runtime; } // namespace kaleidoscope + +kaleidoscope::Runtime_ &Kaleidoscope = kaleidoscope::Runtime; diff --git a/src/kaleidoscope/Kaleidoscope.h b/src/kaleidoscope/Runtime.h similarity index 53% rename from src/kaleidoscope/Kaleidoscope.h rename to src/kaleidoscope/Runtime.h index 9b7dbe53..da07dcc1 100644 --- a/src/kaleidoscope/Kaleidoscope.h +++ b/src/kaleidoscope/Runtime.h @@ -16,97 +16,15 @@ #pragma once -#include - -//end of add your includes here -#ifdef __cplusplus -extern "C" { -#endif -void loop(); -void setup(); -#ifdef __cplusplus -} // extern "C" -#endif - -//add your function definitions for the project KeyboardIO here - -#define TS(X) //Serial.print(micros() );Serial.print("\t");Serial.println(X); - -#include -#include -#include - -#include "kaleidoscope/device/device.h" -#include "kaleidoscope/device/key_indexes.h" #include "kaleidoscope_internal/device.h" -#include "kaleidoscope_internal/deprecations.h" - -static constexpr DEPRECATED(KEYBOARDHARDWARE) kaleidoscope::Device &KeyboardHardware = kaleidoscope_internal::device; - -#ifdef PER_KEY_DATA_STACKED -#define KEYMAP_STACKED(...) { PER_KEY_DATA_STACKED(XXX, __VA_ARGS__) } -#endif - -#ifdef PER_KEY_DATA -#define KEYMAP(...) { PER_KEY_DATA(XXX, __VA_ARGS__) } -#endif - -static constexpr DEPRECATED(ROWS) uint8_t ROWS = kaleidoscope_internal::device.matrix_rows; -static constexpr DEPRECATED(COLS) uint8_t COLS = kaleidoscope_internal::device.matrix_columns; -static constexpr DEPRECATED(LED_COUNT) uint8_t LED_COUNT = kaleidoscope_internal::device.led_count; - -#include "kaleidoscope/KeyAddr.h" -#include "kaleidoscope/key_events.h" -#include "kaleidoscope/hid.h" -#include "kaleidoscope/layers.h" -#include "kaleidoscope_internal/sketch_exploration/sketch_exploration.h" -#include "kaleidoscope/macro_map.h" -#include "kaleidoscope_internal/event_dispatch.h" -#include "kaleidoscope_internal/LEDModeManager.h" -#include "kaleidoscope/macro_helpers.h" -#include "kaleidoscope/plugin.h" - -#define HOOK_MAX 64 - -#ifndef VERSION -#define VERSION "locally-built" -#endif - -/** Kaleidoscope API (major) version. - * - * The API is guaranteed to be backwards compatible for the entire duration of a - * major version. However, breaking changes may come, and result in a major - * version bump. To help migration, the `KALEIDOSCOPE_API_VERSION` macro can be - * used to check the major version provided by the Kaleidoscope we are compiling - * against. This can be used to error out with a helpful message, or change how - * the API is used - it is entirely up to the plugin or sketch author. The point - * of this macro is to let them easily check the version. - */ -#define KALEIDOSCOPE_API_VERSION 2 - -/** Required Kaleidoscope major version. - * - * For the sake of convenience, defining `KALEIDOSCOPE_REQUIRED_API_VERSION` - * before including `Kaleidoscope.h` itself will result in comparing its value - * to `KALEIDOSCOPE_API_VERSION`. If they differ, a helpful error message is - * printed. - * - * Done so that a new API version would result in a helpful error message, - * instead of cryptic compile errors. - */ -#if defined(KALEIDOSCOPE_REQUIRED_API_VERSION) && (KALEIDOSCOPE_REQUIRED_API_VERSION != KALEIDOSCOPE_API_VERSION) -#define xstr(a) str(a) -#define str(a) #a -static_assert(KALEIDOSCOPE_REQUIRED_API_VERSION == KALEIDOSCOPE_API_VERSION, - "Kaleidoscope API version mismatch! We have version " xstr(KALEIDOSCOPE_API_VERSION) - " available, but version " xstr(KALEIDOSCOPE_REQUIRED_API_VERSION) " is required."); -#endif +#include "kaleidoscope/event_handler_result.h" +#include "kaleidoscope/hooks.h" namespace kaleidoscope { -class Kaleidoscope_ { +class Runtime_ { public: - Kaleidoscope_(void); + Runtime_(void); void setup(void); void loop(void); @@ -121,7 +39,7 @@ class Kaleidoscope_ { * * These two functions wrap the hardware plugin's similarly named functions. * We wrap them, because we'd like plugins and user-code not having to use - * `Kaleidoscope.device()` directly. + * `Runtime.device()` directly. * * The methods themselves implement detaching from / attaching to the host, * without rebooting the device, and remaining powered in between. @@ -176,7 +94,7 @@ class Kaleidoscope_ { * occurs, given a start time and a timeout. It takes two parameters: * * - start_time: A timestamp when the timer started, which should be set by - * calling `Kaleidoscope.millisAtCycleStart()`. It can be any integer + * calling `Runtime.millisAtCycleStart()`. It can be any integer * type. * * - ttl: The timeout value or interval to check (ttl = "time to live"). The @@ -210,22 +128,6 @@ class Kaleidoscope_ { static uint32_t millis_at_cycle_start_; }; -extern kaleidoscope::Kaleidoscope_ Kaleidoscope; +extern kaleidoscope::Runtime_ Runtime; } // namespace kaleidoscope - -// For compatibility reasons we enable class Kaleidoscope_ also to be available -// in global namespace. -// -typedef kaleidoscope::Kaleidoscope_ Kaleidoscope_; - -// For compatibility reasons we enable the global variable Kaleidoscope -// in global namespace. -// -using kaleidoscope::Kaleidoscope; - -// Use this function macro to register plugins with Kaleidoscope's -// hooking system. The macro accepts a list of plugin instances that -// must have been instantiated at global scope. -// -#define KALEIDOSCOPE_INIT_PLUGINS(...) _KALEIDOSCOPE_INIT_PLUGINS(__VA_ARGS__) diff --git a/src/kaleidoscope/bitfields.cpp b/src/kaleidoscope/bitfields.cpp index d9eeb642..959f672f 100644 --- a/src/kaleidoscope/bitfields.cpp +++ b/src/kaleidoscope/bitfields.cpp @@ -14,7 +14,7 @@ * this program. If not, see . */ -#include "Kaleidoscope.h" +#include #include "bitfields.h" diff --git a/src/kaleidoscope/bitfields.h b/src/kaleidoscope/bitfields.h index 36855536..3a59c854 100644 --- a/src/kaleidoscope/bitfields.h +++ b/src/kaleidoscope/bitfields.h @@ -17,6 +17,7 @@ #pragma once #include +#include namespace kaleidoscope { namespace bitfields { diff --git a/src/kaleidoscope/device/dygma/Raise.cpp b/src/kaleidoscope/device/dygma/Raise.cpp index 45f134b7..656853bc 100644 --- a/src/kaleidoscope/device/dygma/Raise.cpp +++ b/src/kaleidoscope/device/dygma/Raise.cpp @@ -18,7 +18,7 @@ #ifdef ARDUINO_SAMD_RAISE -#include +#include "kaleidoscope/Runtime.h" #include #include #include @@ -85,20 +85,20 @@ void RaiseHands::setup() { // If keyscan is max, assume that EEPROM is uninitialized, and store the // defaults. uint16_t interval; - Kaleidoscope.storage().get(settings_base_, interval); + Runtime.storage().get(settings_base_, interval); if (interval == 0xffff) { - Kaleidoscope.storage().put(settings_base_, keyscan_interval_); - Kaleidoscope.storage().commit(); + Runtime.storage().put(settings_base_, keyscan_interval_); + Runtime.storage().commit(); } - Kaleidoscope.storage().get(settings_base_, keyscan_interval_); + Runtime.storage().get(settings_base_, keyscan_interval_); } void RaiseHands::keyscanInterval(uint16_t interval) { leftHand.setKeyscanInterval(interval); rightHand.setKeyscanInterval(interval); keyscan_interval_ = interval; - Kaleidoscope.storage().put(settings_base_, keyscan_interval_); - Kaleidoscope.storage().commit(); + Runtime.storage().put(settings_base_, keyscan_interval_); + Runtime.storage().commit(); } void RaiseHands::initializeSides() { diff --git a/src/kaleidoscope/device/dygma/raise/Focus.cpp b/src/kaleidoscope/device/dygma/raise/Focus.cpp index 137ac9d3..5e09b320 100644 --- a/src/kaleidoscope/device/dygma/raise/Focus.cpp +++ b/src/kaleidoscope/device/dygma/raise/Focus.cpp @@ -18,7 +18,7 @@ #ifdef ARDUINO_SAMD_RAISE -#include +#include "kaleidoscope/Runtime.h" #include #include "kaleidoscope/device/dygma/raise/Focus.h" @@ -50,72 +50,72 @@ EventHandlerResult Focus::onFocusEvent(const char *command) { if (strcmp_P(command + 9, PSTR("side_power")) == 0) if (::Focus.isEOL()) { - ::Focus.send(Kaleidoscope.device().side.getPower()); + ::Focus.send(Runtime.device().side.getPower()); return EventHandlerResult::EVENT_CONSUMED; } else { uint8_t power; ::Focus.read(power); - Kaleidoscope.device().side.setPower(power); + Runtime.device().side.setPower(power); return EventHandlerResult::EVENT_CONSUMED; } if (strcmp_P(command + 9, PSTR("side_ver")) == 0) { ::Focus.send("left:"); - ::Focus.send(Kaleidoscope.device().side.leftVersion()); + ::Focus.send(Runtime.device().side.leftVersion()); ::Focus.send("\nright:"); - ::Focus.send(Kaleidoscope.device().side.rightVersion()); + ::Focus.send(Runtime.device().side.rightVersion()); return EventHandlerResult::EVENT_CONSUMED; } if (strcmp_P(command + 9, PSTR("crc_errors")) == 0) { ::Focus.send("left:"); - ::Focus.send(Kaleidoscope.device().side.leftCRCErrors()); + ::Focus.send(Runtime.device().side.leftCRCErrors()); ::Focus.send("\nright:"); - ::Focus.send(Kaleidoscope.device().side.rightCRCErrors()); + ::Focus.send(Runtime.device().side.rightCRCErrors()); return EventHandlerResult::EVENT_CONSUMED; } if (strcmp_P(command + 9, PSTR("sled_ver")) == 0) { ::Focus.send("left:"); - ::Focus.send(Kaleidoscope.device().side.leftSLEDVersion()); + ::Focus.send(Runtime.device().side.leftSLEDVersion()); ::Focus.send("\nright:"); - ::Focus.send(Kaleidoscope.device().side.rightSLEDVersion()); + ::Focus.send(Runtime.device().side.rightSLEDVersion()); return EventHandlerResult::EVENT_CONSUMED; } if (strcmp_P(command + 9, PSTR("sled_current")) == 0) if (::Focus.isEOL()) { ::Focus.send("left:"); - ::Focus.send(Kaleidoscope.device().side.leftSLEDCurrent()); + ::Focus.send(Runtime.device().side.leftSLEDCurrent()); ::Focus.send("\nright:"); - ::Focus.send(Kaleidoscope.device().side.rightSLEDCurrent()); + ::Focus.send(Runtime.device().side.rightSLEDCurrent()); return EventHandlerResult::EVENT_CONSUMED; } else { uint8_t current; ::Focus.read(current); - Kaleidoscope.device().side.setSLEDCurrent(current); + Runtime.device().side.setSLEDCurrent(current); return EventHandlerResult::EVENT_CONSUMED; } if (strcmp_P(command + 9, PSTR("layout")) == 0) { - static const auto ANSI = Kaleidoscope.device().settings.Layout::ANSI; - ::Focus.send(Kaleidoscope.device().settings.layout() == ANSI ? "ANSI" : "ISO"); + static const auto ANSI = Runtime.device().settings.Layout::ANSI; + ::Focus.send(Runtime.device().settings.layout() == ANSI ? "ANSI" : "ISO"); return EventHandlerResult::EVENT_CONSUMED; } if (strcmp_P(command + 9, PSTR("joint")) == 0) { - ::Focus.send(Kaleidoscope.device().settings.joint()); + ::Focus.send(Runtime.device().settings.joint()); return EventHandlerResult::EVENT_CONSUMED; } if (strcmp_P(command + 9, PSTR("keyscan")) == 0) { if (::Focus.isEOL()) { - ::Focus.send(Kaleidoscope.device().settings.keyscanInterval()); + ::Focus.send(Runtime.device().settings.keyscanInterval()); return EventHandlerResult::EVENT_CONSUMED; } else { uint8_t keyscan; ::Focus.read(keyscan); - Kaleidoscope.device().settings.keyscanInterval(keyscan); + Runtime.device().settings.keyscanInterval(keyscan); return EventHandlerResult::EVENT_CONSUMED; } } diff --git a/src/kaleidoscope/device/dygma/raise/Focus.h b/src/kaleidoscope/device/dygma/raise/Focus.h index 9601147e..1cf6b069 100644 --- a/src/kaleidoscope/device/dygma/raise/Focus.h +++ b/src/kaleidoscope/device/dygma/raise/Focus.h @@ -20,7 +20,7 @@ #ifdef ARDUINO_SAMD_RAISE -#include +#include "kaleidoscope/plugin.h" namespace kaleidoscope { namespace device { diff --git a/src/kaleidoscope/device/dygma/raise/SideFlash.h b/src/kaleidoscope/device/dygma/raise/SideFlash.h index f5b74b03..eec49437 100644 --- a/src/kaleidoscope/device/dygma/raise/SideFlash.h +++ b/src/kaleidoscope/device/dygma/raise/SideFlash.h @@ -20,7 +20,8 @@ #ifdef ARDUINO_SAMD_RAISE -#include +#include "kaleidoscope/Runtime.h" +#include "kaleidoscope/plugin.h" namespace kaleidoscope { namespace device { @@ -39,9 +40,9 @@ class SideFlash : public kaleidoscope::Plugin { if (strncmp_P(command, PSTR("hardware."), 9) != 0) return EventHandlerResult::OK; - auto sideFlasher = Kaleidoscope.device().sideFlasher(); - uint8_t left_boot_address = Kaleidoscope.device().side.left_boot_address; - uint8_t right_boot_address = Kaleidoscope.device().side.right_boot_address; + auto sideFlasher = Runtime.device().sideFlasher(); + uint8_t left_boot_address = Runtime.device().side.left_boot_address; + uint8_t right_boot_address = Runtime.device().side.right_boot_address; enum { FLASH, VERIFY @@ -65,7 +66,7 @@ class SideFlash : public kaleidoscope::Plugin { } bool result; - Kaleidoscope.device().side.prepareForFlash(); + Runtime.device().side.prepareForFlash(); if (sub_command == FLASH) result = sideFlasher.flash(address, firmware); else diff --git a/src/kaleidoscope/device/ez/ErgoDox.cpp b/src/kaleidoscope/device/ez/ErgoDox.cpp index 38dd0f1b..b8a0daa0 100644 --- a/src/kaleidoscope/device/ez/ErgoDox.cpp +++ b/src/kaleidoscope/device/ez/ErgoDox.cpp @@ -27,10 +27,11 @@ #ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifdef ARDUINO_AVR_ERGODOX -#include +#include "kaleidoscope/Runtime.h" #include #include #include "kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.h" +#include "kaleidoscope/key_events.h" namespace kaleidoscope { namespace device { diff --git a/src/kaleidoscope/device/kbdfans/KBD4x.cpp b/src/kaleidoscope/device/kbdfans/KBD4x.cpp index 788100cb..cda2f0ba 100644 --- a/src/kaleidoscope/device/kbdfans/KBD4x.cpp +++ b/src/kaleidoscope/device/kbdfans/KBD4x.cpp @@ -18,7 +18,10 @@ #ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifdef ARDUINO_AVR_KBD4X -#include +#include "kaleidoscope/key_events.h" +#include "kaleidoscope/driver/keyscanner/ATmega.h" +#include "kaleidoscope/driver/keyscanner/Base_Impl.h" +#include "kaleidoscope/Runtime.h" namespace kaleidoscope { namespace device { diff --git a/src/kaleidoscope/device/keyboardio/Imago.cpp b/src/kaleidoscope/device/keyboardio/Imago.cpp index d840ba39..8721016f 100644 --- a/src/kaleidoscope/device/keyboardio/Imago.cpp +++ b/src/kaleidoscope/device/keyboardio/Imago.cpp @@ -17,7 +17,8 @@ #ifdef ARDUINO_AVR_KEYBOARDIO_IMAGO -#include +#include "kaleidoscope/Runtime.h" +#include "kaleidoscope/driver/keyscanner/Base_Impl.h" extern "C" { #include "twi.h" @@ -81,7 +82,7 @@ void ImagoLEDDriver::selectRegister(uint8_t page) { } void ImagoLEDDriver::setCrgbAt(uint8_t i, cRGB crgb) { - if (!Kaleidoscope.device().LEDs().isValid(i)) + if (!Runtime.device().LEDs().isValid(i)) return; cRGB oldColor = getCrgbAt(i); @@ -91,7 +92,7 @@ void ImagoLEDDriver::setCrgbAt(uint8_t i, cRGB crgb) { } cRGB ImagoLEDDriver::getCrgbAt(uint8_t i) { - if (!Kaleidoscope.device().LEDs().isValid(i)) + if (!Runtime.device().LEDs().isValid(i)) return {0, 0, 0}; return led_data[i]; diff --git a/src/kaleidoscope/device/keyboardio/Model01.cpp b/src/kaleidoscope/device/keyboardio/Model01.cpp index ae6ecb62..45ea4906 100644 --- a/src/kaleidoscope/device/keyboardio/Model01.cpp +++ b/src/kaleidoscope/device/keyboardio/Model01.cpp @@ -17,7 +17,10 @@ #ifdef ARDUINO_AVR_MODEL01 -#include +#include "Arduino.h" // for PROGMEM +#include "kaleidoscope/device/keyboardio/Model01.h" // for Model01LEDDriver... +#include "kaleidoscope/key_events.h" +#include "kaleidoscope/driver/keyscanner/Base_Impl.h" #ifndef KALEIDOSCOPE_VIRTUAL_BUILD #include diff --git a/src/kaleidoscope/device/olkb/Planck.cpp b/src/kaleidoscope/device/olkb/Planck.cpp index 889a255f..46781c1b 100644 --- a/src/kaleidoscope/device/olkb/Planck.cpp +++ b/src/kaleidoscope/device/olkb/Planck.cpp @@ -18,7 +18,8 @@ #ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifdef ARDUINO_AVR_PLANCK -#include +#include "kaleidoscope/Runtime.h" +#include "kaleidoscope/driver/keyscanner/Base_Impl.h" namespace kaleidoscope { namespace device { diff --git a/src/kaleidoscope/device/softhruf/Splitography.cpp b/src/kaleidoscope/device/softhruf/Splitography.cpp index cf7f55a2..3fd693c4 100644 --- a/src/kaleidoscope/device/softhruf/Splitography.cpp +++ b/src/kaleidoscope/device/softhruf/Splitography.cpp @@ -25,7 +25,8 @@ #ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifdef ARDUINO_AVR_SPLITOGRAPHY -#include +#include "kaleidoscope/Runtime.h" +#include "kaleidoscope/driver/keyscanner/Base_Impl.h" namespace kaleidoscope { namespace device { diff --git a/src/kaleidoscope/device/technomancy/Atreus.cpp b/src/kaleidoscope/device/technomancy/Atreus.cpp index 23a9cc51..42a30a62 100644 --- a/src/kaleidoscope/device/technomancy/Atreus.cpp +++ b/src/kaleidoscope/device/technomancy/Atreus.cpp @@ -27,7 +27,8 @@ #ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifdef ARDUINO_AVR_ATREUS -#include +#include "kaleidoscope/Runtime.h" +#include "kaleidoscope/driver/keyscanner/Base_Impl.h" namespace kaleidoscope { namespace device { diff --git a/src/kaleidoscope/device/technomancy/Atreus2.cpp b/src/kaleidoscope/device/technomancy/Atreus2.cpp index 5b8475d7..2a4423f2 100644 --- a/src/kaleidoscope/device/technomancy/Atreus2.cpp +++ b/src/kaleidoscope/device/technomancy/Atreus2.cpp @@ -19,7 +19,8 @@ #ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifdef ARDUINO_AVR_ATREUS2 -#include +#include "kaleidoscope/Runtime.h" +#include "kaleidoscope/driver/keyscanner/Base_Impl.h" namespace kaleidoscope { namespace device { diff --git a/src/kaleidoscope/device/virtual/Virtual.cpp b/src/kaleidoscope/device/virtual/Virtual.cpp index 73535575..7b5e4896 100644 --- a/src/kaleidoscope/device/virtual/Virtual.cpp +++ b/src/kaleidoscope/device/virtual/Virtual.cpp @@ -22,7 +22,10 @@ #include "kaleidoscope/device/virtual/Logging.h" #include "kaleidoscope/keyswitch_state.h" -#include "Kaleidoscope.h" +#include "kaleidoscope/MatrixAddr.h" +#include "kaleidoscope/key_defs.h" +#include "kaleidoscope/key_events.h" + #include "HIDReportObserver.h" #include "virtual_io.h" @@ -30,7 +33,6 @@ #include #include -#include // FIXME: This relates to virtual/cores/arduino/EEPROM.h. // EEPROM static data must be defined here as only diff --git a/src/kaleidoscope/driver/bootloader/avr/FLIP.cpp b/src/kaleidoscope/driver/bootloader/avr/FLIP.cpp index fcb86068..32c24d9c 100644 --- a/src/kaleidoscope/driver/bootloader/avr/FLIP.cpp +++ b/src/kaleidoscope/driver/bootloader/avr/FLIP.cpp @@ -16,7 +16,7 @@ */ #ifndef KALEIDOSCOPE_VIRTUAL_BUILD -#include +#include "kaleidoscope/Runtime.h" #ifdef KALEIDOSCOPE_BOOTLOADER_FLIP_WORKAROUND #include "kaleidoscope/driver/bootloader/avr/FLIP.h" diff --git a/src/kaleidoscope/driver/keyscanner/ATmega.h b/src/kaleidoscope/driver/keyscanner/ATmega.h index 8db7eaf8..84d07fe8 100644 --- a/src/kaleidoscope/driver/keyscanner/ATmega.h +++ b/src/kaleidoscope/driver/keyscanner/ATmega.h @@ -57,7 +57,7 @@ uint8_t kaleidoscope::Device::KeyScanner::debounce_matrix_[kaleidoscope::Device::KeyScannerProps::matrix_rows][kaleidoscope::Device::KeyScannerProps::matrix_columns] = {}; \ \ ISR(TIMER1_OVF_vect) { \ - Kaleidoscope.device().readMatrix(); \ + Runtime.device().readMatrix(); \ } namespace kaleidoscope { diff --git a/src/kaleidoscope/driver/keyscanner/Base_Impl.h b/src/kaleidoscope/driver/keyscanner/Base_Impl.h new file mode 100644 index 00000000..e2f17c23 --- /dev/null +++ b/src/kaleidoscope/driver/keyscanner/Base_Impl.h @@ -0,0 +1,33 @@ +/* -*- mode: c++ -*- + * kaleidoscope::driver::keyscanner::base -- Keyscanner base class + * Copyright (C) 2019 Keyboard.io, Inc + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#pragma once + +#include "kaleidoscope/driver/keyscanner/Base.h" +#include "kaleidoscope/device/device.h" + +namespace kaleidoscope { +namespace driver { +namespace keyscanner { + +template<> +void Base::handleKeyswitchEvent(Key mappedKey, kaleidoscope::Device::Props::KeyScannerProps::KeyAddr key_addr, uint8_t keyState) { + ::handleKeyswitchEvent(mappedKey, key_addr, keyState); +} +} // namespace keyscanner +} // namespace driver +} // namespace kaleidoscope diff --git a/src/kaleidoscope/hooks.cpp b/src/kaleidoscope/hooks.cpp index 929aa8e8..cd9525bf 100644 --- a/src/kaleidoscope/hooks.cpp +++ b/src/kaleidoscope/hooks.cpp @@ -14,7 +14,9 @@ * this program. If not, see . */ -#include "Kaleidoscope.h" +#include "kaleidoscope/event_handler_result.h" +#include "kaleidoscope/event_handlers.h" +#include "kaleidoscope/macro_helpers.h" #include "kaleidoscope/hooks.h" namespace kaleidoscope { diff --git a/src/kaleidoscope/hooks.h b/src/kaleidoscope/hooks.h index 5ea358c1..04de8eaa 100644 --- a/src/kaleidoscope/hooks.h +++ b/src/kaleidoscope/hooks.h @@ -59,9 +59,9 @@ class Hooks { // The following friend declarations restrict access to // the hook routing system. - // Kaleidoscope_ calls Hooks::onSetup, Hooks::beforeReportingState + // Runtime_ calls Hooks::onSetup, Hooks::beforeReportingState // and Hooks::afterEachCycle. - friend class Kaleidoscope_; + friend class Runtime_; friend class ::kaleidoscope::Layer_; friend class ::kaleidoscope::plugin::LEDControl; friend void ::kaleidoscope::sketch_exploration::pluginsExploreSketch(); diff --git a/src/kaleidoscope/key_defs_keymaps.h b/src/kaleidoscope/key_defs_keymaps.h index 8842674e..aa341e15 100644 --- a/src/kaleidoscope/key_defs_keymaps.h +++ b/src/kaleidoscope/key_defs_keymaps.h @@ -16,6 +16,8 @@ #pragma once +#include + #include "kaleidoscope_internal/deprecations.h" static const uint8_t LAYER_SHIFT_OFFSET = 42; diff --git a/src/kaleidoscope/key_events.cpp b/src/kaleidoscope/key_events.cpp index 94feafca..0b974b78 100644 --- a/src/kaleidoscope/key_events.cpp +++ b/src/kaleidoscope/key_events.cpp @@ -14,9 +14,11 @@ * this program. If not, see . */ -#include "kaleidoscope/Kaleidoscope.h" +#include "kaleidoscope/Runtime.h" #include "kaleidoscope/hooks.h" -#include "kaleidoscope/plugin.h" +#include "kaleidoscope/keyswitch_state.h" +#include "kaleidoscope/hid.h" +#include "kaleidoscope/layers.h" static bool handleSyntheticKeyswitchEvent(Key mappedKey, uint8_t keyState) { if (mappedKey.getFlags() & RESERVED) @@ -60,6 +62,9 @@ static bool handleKeyswitchEventDefault(Key mappedKey, KeyAddr key_addr, uint8_t } void handleKeyswitchEvent(Key mappedKey, KeyAddr key_addr, uint8_t keyState) { + + using kaleidoscope::Runtime; + /* These first steps are only done for keypresses that have a valid key_addr. * In particular, doing them for keypresses with out-of-bounds key_addr * would cause out-of-bounds array accesses in Layer.lookup(), @@ -96,9 +101,9 @@ void handleKeyswitchEvent(Key mappedKey, KeyAddr key_addr, uint8_t keyState) { * See layers.cpp for an example that masks keys, and the reason why it does * so. */ - if (Kaleidoscope.device().isKeyMasked(key_addr)) { + if (Runtime.device().isKeyMasked(key_addr)) { if (keyToggledOff(keyState)) { - Kaleidoscope.device().unMaskKey(key_addr); + Runtime.device().unMaskKey(key_addr); } else { return; } diff --git a/src/kaleidoscope/key_events.h b/src/kaleidoscope/key_events.h index 6de6becd..d1acdc40 100644 --- a/src/kaleidoscope/key_events.h +++ b/src/kaleidoscope/key_events.h @@ -17,9 +17,11 @@ #pragma once #include +#include "kaleidoscope/driver/keyscanner/Base.h" #include "kaleidoscope/device/device.h" #include "kaleidoscope/key_defs.h" #include "kaleidoscope/keyswitch_state.h" +#include "kaleidoscope/KeyAddr.h" // Code can use this macro on injected key events to signal that @@ -76,16 +78,3 @@ void handleKeyswitchEvent(Key mappedKey, kaleidoscope::Device::Props::KeyScanner DEPRECATED(ROW_COL_FUNC) inline void handleKeyswitchEvent(Key mappedKey, byte row, byte col, uint8_t keyState) { handleKeyswitchEvent(mappedKey, KeyAddr(row, col), keyState); } - -namespace kaleidoscope { -namespace driver { -namespace keyscanner { - -template<> -inline -void Base::handleKeyswitchEvent(Key mappedKey, kaleidoscope::Device::Props::KeyScannerProps::KeyAddr key_addr, uint8_t keyState) { - ::handleKeyswitchEvent(mappedKey, key_addr, keyState); -} -} // namespace keyscanner -} // namespace driver -} // namespace kaleidoscope diff --git a/src/kaleidoscope/keymaps.h b/src/kaleidoscope/keymaps.h index 3bc2f772..09fdf5c6 100644 --- a/src/kaleidoscope/keymaps.h +++ b/src/kaleidoscope/keymaps.h @@ -17,6 +17,8 @@ #pragma once #include "kaleidoscope/key_defs.h" +#include "kaleidoscope/KeyAddr.h" +#include "kaleidoscope_internal/device.h" extern const Key keymaps_linear[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns]; diff --git a/src/kaleidoscope/layers.cpp b/src/kaleidoscope/layers.cpp index 8cc702e9..a9e0e153 100644 --- a/src/kaleidoscope/layers.cpp +++ b/src/kaleidoscope/layers.cpp @@ -14,7 +14,9 @@ * this program. If not, see . */ -#include "kaleidoscope/Kaleidoscope.h" +#include "kaleidoscope/Runtime.h" +#include "kaleidoscope/layers.h" +#include "kaleidoscope/keyswitch_state.h" // The maximum number of layers allowed. `layer_state_`, which stores // the on/off status of the layers in a bitfield has only 32 bits, and @@ -38,8 +40,8 @@ extern constexpr Key keymaps_linear[][kaleidoscope_internal::device.matrix_rows namespace kaleidoscope { uint32_t Layer_::layer_state_; uint8_t Layer_::top_active_layer_; -Key Layer_::live_composite_keymap_[Kaleidoscope.device().numKeys()]; -uint8_t Layer_::active_layers_[Kaleidoscope.device().numKeys()]; +Key Layer_::live_composite_keymap_[Runtime.device().numKeys()]; +uint8_t Layer_::active_layers_[Runtime.device().numKeys()]; Layer_::GetKeyFunction Layer_::getKey = &Layer_::getKeyFromPROGMEM; void Layer_::handleKeymapKeyswitchEvent(Key keymapEntry, uint8_t keyState) { @@ -111,7 +113,7 @@ void Layer_::updateLiveCompositeKeymap(KeyAddr key_addr) { } void Layer_::updateActiveLayers(void) { - memset(active_layers_, 0, Kaleidoscope.device().numKeys()); + memset(active_layers_, 0, Runtime.device().numKeys()); for (auto key_addr : KeyAddr::all()) { int8_t layer = top_active_layer_; diff --git a/src/kaleidoscope/plugin/Colormap.cpp b/src/kaleidoscope/plugin/Colormap.cpp index d24707d8..b3e87ab3 100644 --- a/src/kaleidoscope/plugin/Colormap.cpp +++ b/src/kaleidoscope/plugin/Colormap.cpp @@ -19,6 +19,7 @@ #include #include #include +#include "kaleidoscope/layers.h" namespace kaleidoscope { namespace plugin { @@ -36,7 +37,7 @@ void ColormapEffect::max_layers(uint8_t max_) { } void ColormapEffect::TransientLEDMode::onActivate(void) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return; parent_->top_layer_ = Layer.top(); diff --git a/src/kaleidoscope/plugin/Cycle.cpp b/src/kaleidoscope/plugin/Cycle.cpp index ff4189e4..21110302 100644 --- a/src/kaleidoscope/plugin/Cycle.cpp +++ b/src/kaleidoscope/plugin/Cycle.cpp @@ -15,9 +15,11 @@ * this program. If not, see . */ -#include +#include "kaleidoscope/Runtime.h" #include #include "kaleidoscope/hid.h" +#include "kaleidoscope/keyswitch_state.h" +#include "kaleidoscope/key_events.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/Cycle.h b/src/kaleidoscope/plugin/Cycle.h index e467d99c..cffe720f 100644 --- a/src/kaleidoscope/plugin/Cycle.h +++ b/src/kaleidoscope/plugin/Cycle.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include #define Key_Cycle Key(kaleidoscope::ranges::CYCLE) diff --git a/src/kaleidoscope/plugin/CycleTimeReport.cpp b/src/kaleidoscope/plugin/CycleTimeReport.cpp index 00d6f981..e826aa39 100644 --- a/src/kaleidoscope/plugin/CycleTimeReport.cpp +++ b/src/kaleidoscope/plugin/CycleTimeReport.cpp @@ -25,7 +25,7 @@ uint32_t CycleTimeReport::loop_start_time_; uint32_t CycleTimeReport::average_loop_time; EventHandlerResult CycleTimeReport::onSetup() { - last_report_time_ = Kaleidoscope.millisAtCycleStart(); + last_report_time_ = Runtime.millisAtCycleStart(); return EventHandlerResult::OK; } @@ -42,11 +42,11 @@ EventHandlerResult CycleTimeReport::afterEachCycle() { else average_loop_time = loop_time; - if (Kaleidoscope.hasTimeExpired(last_report_time_, uint16_t(1000))) { + if (Runtime.hasTimeExpired(last_report_time_, uint16_t(1000))) { cycleTimeReport(); average_loop_time = 0; - last_report_time_ = Kaleidoscope.millisAtCycleStart(); + last_report_time_ = Runtime.millisAtCycleStart(); } return EventHandlerResult::OK; diff --git a/src/kaleidoscope/plugin/CycleTimeReport.h b/src/kaleidoscope/plugin/CycleTimeReport.h index 23005310..7610d39b 100644 --- a/src/kaleidoscope/plugin/CycleTimeReport.h +++ b/src/kaleidoscope/plugin/CycleTimeReport.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/DynamicMacros.cpp b/src/kaleidoscope/plugin/DynamicMacros.cpp index 424145aa..80e65daa 100644 --- a/src/kaleidoscope/plugin/DynamicMacros.cpp +++ b/src/kaleidoscope/plugin/DynamicMacros.cpp @@ -17,6 +17,8 @@ #include "Kaleidoscope-DynamicMacros.h" #include "kaleidoscope/hid.h" #include "Kaleidoscope-FocusSerial.h" +#include "kaleidoscope/keyswitch_state.h" +#include "kaleidoscope/key_events.h" using namespace kaleidoscope::ranges; @@ -47,7 +49,7 @@ static void playKeyCode(Key key, uint8_t keyStates, bool explicit_report) { } static void readKeyCodeAndPlay(uint16_t pos, uint8_t flags, uint8_t keyStates, bool explicit_report) { - Key key(Kaleidoscope.storage().read(pos++), // key_code + Key key(Runtime.storage().read(pos++), // key_code flags); playKeyCode(key, keyStates, explicit_report); @@ -62,7 +64,7 @@ void DynamicMacros::updateDynamicMacroCache(void) { map_[0] = 0; while (pos < storage_base_ + storage_size_) { - macro = Kaleidoscope.storage().read(pos++); + macro = Runtime.storage().read(pos++); switch (macro) { case MACRO_ACTION_STEP_EXPLICIT_REPORT: case MACRO_ACTION_STEP_IMPLICIT_REPORT: @@ -90,8 +92,8 @@ void DynamicMacros::updateDynamicMacroCache(void) { previous_macro_ended = false; uint8_t keyCode, flags; do { - flags = Kaleidoscope.storage().read(pos++); - keyCode = Kaleidoscope.storage().read(pos++); + flags = Runtime.storage().read(pos++); + keyCode = Runtime.storage().read(pos++); } while (!(flags == 0 && keyCode == 0)); break; } @@ -100,7 +102,7 @@ void DynamicMacros::updateDynamicMacroCache(void) { previous_macro_ended = false; uint8_t keyCode, flags; do { - keyCode = Kaleidoscope.storage().read(pos++); + keyCode = Runtime.storage().read(pos++); } while (keyCode != 0); break; } @@ -127,7 +129,7 @@ void DynamicMacros::play(uint8_t macro_id) { pos = storage_base_ + map_[macro_id]; while (true) { - switch (macro = Kaleidoscope.storage().read(pos++)) { + switch (macro = Runtime.storage().read(pos++)) { case MACRO_ACTION_STEP_EXPLICIT_REPORT: explicit_report = true; break; @@ -139,23 +141,23 @@ void DynamicMacros::play(uint8_t macro_id) { kaleidoscope::hid::sendMouseReport(); break; case MACRO_ACTION_STEP_INTERVAL: - interval = Kaleidoscope.storage().read(pos++); + interval = Runtime.storage().read(pos++); break; case MACRO_ACTION_STEP_WAIT: { - uint8_t wait = Kaleidoscope.storage().read(pos++); + uint8_t wait = Runtime.storage().read(pos++); delay(wait); break; } case MACRO_ACTION_STEP_KEYDOWN: - flags = Kaleidoscope.storage().read(pos++); + flags = Runtime.storage().read(pos++); readKeyCodeAndPlay(pos++, flags, IS_PRESSED, explicit_report); break; case MACRO_ACTION_STEP_KEYUP: - flags = Kaleidoscope.storage().read(pos++); + flags = Runtime.storage().read(pos++); readKeyCodeAndPlay(pos++, flags, WAS_PRESSED, explicit_report); break; case MACRO_ACTION_STEP_TAP: - flags = Kaleidoscope.storage().read(pos++); + flags = Runtime.storage().read(pos++); readKeyCodeAndPlay(pos++, flags, IS_PRESSED | WAS_PRESSED, false); break; @@ -172,8 +174,8 @@ void DynamicMacros::play(uint8_t macro_id) { case MACRO_ACTION_STEP_TAP_SEQUENCE: { uint8_t keyCode; do { - flags = Kaleidoscope.storage().read(pos++); - keyCode = Kaleidoscope.storage().read(pos++); + flags = Runtime.storage().read(pos++); + keyCode = Runtime.storage().read(pos++); playKeyCode(Key(keyCode, flags), IS_PRESSED | WAS_PRESSED, false); delay(interval); } while (!(flags == 0 && keyCode == 0)); @@ -182,7 +184,7 @@ void DynamicMacros::play(uint8_t macro_id) { case MACRO_ACTION_STEP_TAP_CODE_SEQUENCE: { uint8_t keyCode; do { - keyCode = Kaleidoscope.storage().read(pos++); + keyCode = Runtime.storage().read(pos++); playKeyCode(Key(keyCode, 0), IS_PRESSED | WAS_PRESSED, false); delay(interval); } while (keyCode != 0); @@ -220,7 +222,7 @@ EventHandlerResult DynamicMacros::onFocusEvent(const char *command) { if (::Focus.isEOL()) { for (uint16_t i = 0; i < storage_size_; i++) { uint8_t b; - b = Kaleidoscope.storage().read(storage_base_ + i); + b = Runtime.storage().read(storage_base_ + i); ::Focus.send(b); } } else { @@ -230,9 +232,9 @@ EventHandlerResult DynamicMacros::onFocusEvent(const char *command) { uint8_t b; ::Focus.read(b); - Kaleidoscope.storage().update(storage_base_ + pos++, b); + Runtime.storage().update(storage_base_ + pos++, b); } - Kaleidoscope.storage().commit(); + Runtime.storage().commit(); updateDynamicMacroCache(); } } diff --git a/src/kaleidoscope/plugin/DynamicMacros.h b/src/kaleidoscope/plugin/DynamicMacros.h index 17ab19ad..3e1b56ef 100644 --- a/src/kaleidoscope/plugin/DynamicMacros.h +++ b/src/kaleidoscope/plugin/DynamicMacros.h @@ -16,7 +16,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include #include diff --git a/src/kaleidoscope/plugin/EEPROM-Keymap-Programmer.cpp b/src/kaleidoscope/plugin/EEPROM-Keymap-Programmer.cpp index 32a9c2d1..3749a239 100644 --- a/src/kaleidoscope/plugin/EEPROM-Keymap-Programmer.cpp +++ b/src/kaleidoscope/plugin/EEPROM-Keymap-Programmer.cpp @@ -17,6 +17,8 @@ #include #include +#include "kaleidoscope/keyswitch_state.h" +#include "kaleidoscope/layers.h" namespace kaleidoscope { namespace plugin { @@ -39,7 +41,7 @@ void EEPROMKeymapProgrammer::nextState(void) { case WAIT_FOR_CODE: case WAIT_FOR_SOURCE_KEY: ::EEPROMKeymap.updateKey(update_position_, new_key_); - Kaleidoscope.storage().commit(); + Runtime.storage().commit(); cancel(); break; } @@ -57,10 +59,10 @@ EventHandlerResult EEPROMKeymapProgrammer::onKeyswitchEvent(Key &mapped_key, Key if (state_ == WAIT_FOR_KEY) { if (keyToggledOn(key_state)) { - update_position_ = Layer.top() * Kaleidoscope.device().numKeys() + key_addr.toInt(); + update_position_ = Layer.top() * Runtime.device().numKeys() + key_addr.toInt(); } if (keyToggledOff(key_state)) { - if ((uint16_t)(Layer.top() * Kaleidoscope.device().numKeys() + key_addr.toInt()) == update_position_) + if ((uint16_t)(Layer.top() * Runtime.device().numKeys() + key_addr.toInt()) == update_position_) nextState(); } return EventHandlerResult::EVENT_CONSUMED; diff --git a/src/kaleidoscope/plugin/EEPROM-Keymap-Programmer.h b/src/kaleidoscope/plugin/EEPROM-Keymap-Programmer.h index dd45b148..79823164 100644 --- a/src/kaleidoscope/plugin/EEPROM-Keymap-Programmer.h +++ b/src/kaleidoscope/plugin/EEPROM-Keymap-Programmer.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include namespace kaleidoscope { diff --git a/src/kaleidoscope/plugin/EEPROM-Keymap.cpp b/src/kaleidoscope/plugin/EEPROM-Keymap.cpp index 790e9828..e55a3f33 100644 --- a/src/kaleidoscope/plugin/EEPROM-Keymap.cpp +++ b/src/kaleidoscope/plugin/EEPROM-Keymap.cpp @@ -18,6 +18,7 @@ #include #include #include +#include "kaleidoscope/layers.h" namespace kaleidoscope { namespace plugin { @@ -44,17 +45,17 @@ void EEPROMKeymap::setup(uint8_t max) { void EEPROMKeymap::max_layers(uint8_t max) { max_layers_ = max; - keymap_base_ = ::EEPROMSettings.requestSlice(max_layers_ * Kaleidoscope.device().numKeys() * 2); + keymap_base_ = ::EEPROMSettings.requestSlice(max_layers_ * Runtime.device().numKeys() * 2); } Key EEPROMKeymap::getKey(uint8_t layer, KeyAddr key_addr) { if (layer >= max_layers_) return Key_NoKey; - uint16_t pos = ((layer * Kaleidoscope.device().numKeys()) + key_addr.toInt()) * 2; + uint16_t pos = ((layer * Runtime.device().numKeys()) + key_addr.toInt()) * 2; - return Key(Kaleidoscope.storage().read(keymap_base_ + pos + 1), // key_code - Kaleidoscope.storage().read(keymap_base_ + pos)); // flags + return Key(Runtime.storage().read(keymap_base_ + pos + 1), // key_code + Runtime.storage().read(keymap_base_ + pos)); // flags } Key EEPROMKeymap::getKeyExtended(uint8_t layer, KeyAddr key_addr) { @@ -73,8 +74,8 @@ uint16_t EEPROMKeymap::keymap_base(void) { } void EEPROMKeymap::updateKey(uint16_t base_pos, Key key) { - Kaleidoscope.storage().update(keymap_base_ + base_pos * 2, key.getFlags()); - Kaleidoscope.storage().update(keymap_base_ + base_pos * 2 + 1, key.getKeyCode()); + Runtime.storage().update(keymap_base_ + base_pos * 2, key.getFlags()); + Runtime.storage().update(keymap_base_ + base_pos * 2 + 1, key.getKeyCode()); } void EEPROMKeymap::dumpKeymap(uint8_t layers, Key(*getkey)(uint8_t, KeyAddr)) { @@ -146,14 +147,14 @@ EventHandlerResult EEPROMKeymap::onFocusEvent(const char *command) { } else { uint16_t i = 0; - while (!::Focus.isEOL() && (i < (uint16_t)Kaleidoscope.device().numKeys() * max_layers_)) { + while (!::Focus.isEOL() && (i < (uint16_t)Runtime.device().numKeys() * max_layers_)) { Key k; ::Focus.read(k); updateKey(i, k); i++; } - Kaleidoscope.storage().commit(); + Runtime.storage().commit(); } return EventHandlerResult::EVENT_CONSUMED; diff --git a/src/kaleidoscope/plugin/EEPROM-Keymap.h b/src/kaleidoscope/plugin/EEPROM-Keymap.h index af7d4398..ac7e4c40 100644 --- a/src/kaleidoscope/plugin/EEPROM-Keymap.h +++ b/src/kaleidoscope/plugin/EEPROM-Keymap.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include #define _DEPRECATED_MESSAGE_EEPROM_KEYMAP_SETUP_MODE \ diff --git a/src/kaleidoscope/plugin/EEPROM-Settings.cpp b/src/kaleidoscope/plugin/EEPROM-Settings.cpp index 2789e4cc..1f4d86c8 100644 --- a/src/kaleidoscope/plugin/EEPROM-Settings.cpp +++ b/src/kaleidoscope/plugin/EEPROM-Settings.cpp @@ -18,6 +18,7 @@ #include #include #include "kaleidoscope/plugin/EEPROM-Settings/crc.h" +#include "kaleidoscope/layers.h" namespace kaleidoscope { namespace plugin { @@ -28,7 +29,7 @@ bool EEPROMSettings::sealed_; uint16_t EEPROMSettings::next_start_ = sizeof(EEPROMSettings::settings); EventHandlerResult EEPROMSettings::onSetup() { - Kaleidoscope.storage().get(0, settings_); + Runtime.storage().get(0, settings_); /* If the version is undefined, set up sensible defaults. */ if (settings_.version == VERSION_UNDEFINED) { @@ -49,8 +50,8 @@ EventHandlerResult EEPROMSettings::onSetup() { * not able to catch all writes yet. For the sake of consistency, if we * encounter a firmware with no version defined, we'll set sensible * defaults. */ - Kaleidoscope.storage().put(0, settings_); - Kaleidoscope.storage().commit(); + Runtime.storage().put(0, settings_); + Runtime.storage().commit(); } return EventHandlerResult::OK; } @@ -147,8 +148,8 @@ uint16_t EEPROMSettings::used(void) { } void EEPROMSettings::update(void) { - Kaleidoscope.storage().put(0, settings_); - Kaleidoscope.storage().commit(); + Runtime.storage().put(0, settings_); + Runtime.storage().commit(); is_valid_ = true; } @@ -222,22 +223,22 @@ EventHandlerResult FocusEEPROMCommand::onFocusEvent(const char *command) { switch (sub_command) { case CONTENTS: { if (::Focus.isEOL()) { - for (uint16_t i = 0; i < Kaleidoscope.storage().length(); i++) { - uint8_t d = Kaleidoscope.storage().read(i); + for (uint16_t i = 0; i < Runtime.storage().length(); i++) { + uint8_t d = Runtime.storage().read(i); ::Focus.send(d); } } else { - for (uint16_t i = 0; i < Kaleidoscope.storage().length() && !::Focus.isEOL(); i++) { + for (uint16_t i = 0; i < Runtime.storage().length() && !::Focus.isEOL(); i++) { uint8_t d; ::Focus.read(d); - Kaleidoscope.storage().update(i, d); + Runtime.storage().update(i, d); } } break; } case FREE: - ::Focus.send(Kaleidoscope.storage().length() - ::EEPROMSettings.used()); + ::Focus.send(Runtime.storage().length() - ::EEPROMSettings.used()); break; } diff --git a/src/kaleidoscope/plugin/EEPROM-Settings.h b/src/kaleidoscope/plugin/EEPROM-Settings.h index baaf91b8..566dfe79 100644 --- a/src/kaleidoscope/plugin/EEPROM-Settings.h +++ b/src/kaleidoscope/plugin/EEPROM-Settings.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #define _DEPRECATED_MESSAGE_EEPROMSETTINGS_VERSION_SET \ "The EEPROMSettings.version(uint8_t version) method has been deprecated,\n" \ diff --git a/src/kaleidoscope/plugin/Escape-OneShot.cpp b/src/kaleidoscope/plugin/Escape-OneShot.cpp index 7dd8451a..9e3d58c5 100644 --- a/src/kaleidoscope/plugin/Escape-OneShot.cpp +++ b/src/kaleidoscope/plugin/Escape-OneShot.cpp @@ -15,9 +15,10 @@ * this program. If not, see . */ -#include +#include "kaleidoscope/Runtime.h" #include #include +#include "kaleidoscope/keyswitch_state.h" namespace kaleidoscope { namespace plugin { @@ -32,7 +33,7 @@ EventHandlerResult EscapeOneShot::onKeyswitchEvent(Key &mapped_key, KeyAddr key_ return EventHandlerResult::OK; } - Kaleidoscope.device().maskKey(key_addr); + Runtime.device().maskKey(key_addr); ::OneShot.cancel(true); return EventHandlerResult::EVENT_CONSUMED; diff --git a/src/kaleidoscope/plugin/Escape-OneShot.h b/src/kaleidoscope/plugin/Escape-OneShot.h index 47592228..b330cb11 100644 --- a/src/kaleidoscope/plugin/Escape-OneShot.h +++ b/src/kaleidoscope/plugin/Escape-OneShot.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/FingerPainter.cpp b/src/kaleidoscope/plugin/FingerPainter.cpp index 1e5691c2..4196f8c9 100644 --- a/src/kaleidoscope/plugin/FingerPainter.cpp +++ b/src/kaleidoscope/plugin/FingerPainter.cpp @@ -21,6 +21,7 @@ #include #include #include +#include "kaleidoscope/keyswitch_state.h" namespace kaleidoscope { namespace plugin { @@ -46,7 +47,7 @@ void FingerPainter::toggle(void) { } EventHandlerResult FingerPainter::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) { - if (!Kaleidoscope.has_leds || !edit_mode_) + if (!Runtime.has_leds || !edit_mode_) return EventHandlerResult::OK; if (!keyToggledOn(key_state)) { @@ -58,7 +59,7 @@ EventHandlerResult FingerPainter::onKeyswitchEvent(Key &mapped_key, KeyAddr key_ // TODO: The following works only for keyboards with LEDs for each key. - uint8_t color_index = ::LEDPaletteTheme.lookupColorIndexAtPosition(color_base_, Kaleidoscope.device().getLedIndex(key_addr)); + uint8_t color_index = ::LEDPaletteTheme.lookupColorIndexAtPosition(color_base_, Runtime.device().getLedIndex(key_addr)); // Find the next color in the palette that is different. // But do not loop forever! @@ -75,7 +76,7 @@ EventHandlerResult FingerPainter::onKeyswitchEvent(Key &mapped_key, KeyAddr key_ new_color = ::LEDPaletteTheme.lookupPaletteColor(color_index); } - ::LEDPaletteTheme.updateColorIndexAtPosition(color_base_, Kaleidoscope.device().getLedIndex(key_addr), color_index); + ::LEDPaletteTheme.updateColorIndexAtPosition(color_base_, Runtime.device().getLedIndex(key_addr), color_index); return EventHandlerResult::EVENT_CONSUMED; } @@ -100,10 +101,10 @@ EventHandlerResult FingerPainter::onFocusEvent(const char *command) { return EventHandlerResult::OK; if (sub_command == CLEAR) { - for (uint16_t i = 0; i < Kaleidoscope.device().numKeys() / 2; i++) { - Kaleidoscope.storage().update(color_base_ + i, 0); + for (uint16_t i = 0; i < Runtime.device().numKeys() / 2; i++) { + Runtime.storage().update(color_base_ + i, 0); } - Kaleidoscope.storage().commit(); + Runtime.storage().commit(); return EventHandlerResult::OK; } diff --git a/src/kaleidoscope/plugin/FirmwareDump.h b/src/kaleidoscope/plugin/FirmwareDump.h index aa3a41a4..62d2befd 100644 --- a/src/kaleidoscope/plugin/FirmwareDump.h +++ b/src/kaleidoscope/plugin/FirmwareDump.h @@ -23,7 +23,7 @@ #ifdef __AVR__ -#include +#include "kaleidoscope/Runtime.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/FocusSerial.cpp b/src/kaleidoscope/plugin/FocusSerial.cpp index 7467b658..ef3c6f3b 100644 --- a/src/kaleidoscope/plugin/FocusSerial.cpp +++ b/src/kaleidoscope/plugin/FocusSerial.cpp @@ -27,20 +27,20 @@ namespace plugin { char FocusSerial::command_[32]; void FocusSerial::drain(void) { - if (Kaleidoscope.serialPort().available()) - while (Kaleidoscope.serialPort().peek() != '\n') - Kaleidoscope.serialPort().read(); + if (Runtime.serialPort().available()) + while (Runtime.serialPort().peek() != '\n') + Runtime.serialPort().read(); } EventHandlerResult FocusSerial::beforeReportingState() { - if (Kaleidoscope.serialPort().available() == 0) + if (Runtime.serialPort().available() == 0) return EventHandlerResult::OK; uint8_t i = 0; do { - command_[i++] = Kaleidoscope.serialPort().read(); + command_[i++] = Runtime.serialPort().read(); - if (Kaleidoscope.serialPort().peek() == '\n') + if (Runtime.serialPort().peek() == '\n') break; } while (command_[i - 1] != ' ' && i < 32); if (command_[i - 1] == ' ') @@ -48,14 +48,14 @@ EventHandlerResult FocusSerial::beforeReportingState() { else command_[i] = '\0'; - Kaleidoscope.onFocusEvent(command_); + Runtime.onFocusEvent(command_); - Kaleidoscope.serialPort().println(F("\r\n.")); + Runtime.serialPort().println(F("\r\n.")); drain(); - if (Kaleidoscope.serialPort().peek() == '\n') - Kaleidoscope.serialPort().read(); + if (Runtime.serialPort().peek() == '\n') + Runtime.serialPort().read(); return EventHandlerResult::OK; } @@ -65,7 +65,7 @@ bool FocusSerial::handleHelp(const char *command, if (strcmp_P(command, PSTR("help")) != 0) return false; - Kaleidoscope.serialPort().println((const __FlashStringHelper *)help_message); + Runtime.serialPort().println((const __FlashStringHelper *)help_message); return true; } @@ -75,7 +75,7 @@ EventHandlerResult FocusSerial::onFocusEvent(const char *command) { } void FocusSerial::printBool(bool b) { - Kaleidoscope.serialPort().print((b) ? F("true") : F("false")); + Runtime.serialPort().print((b) ? F("true") : F("false")); } } diff --git a/src/kaleidoscope/plugin/FocusSerial.h b/src/kaleidoscope/plugin/FocusSerial.h index 5a7230c0..0e8b5877 100644 --- a/src/kaleidoscope/plugin/FocusSerial.h +++ b/src/kaleidoscope/plugin/FocusSerial.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" namespace kaleidoscope { namespace plugin { @@ -37,12 +37,12 @@ class FocusSerial : public kaleidoscope::Plugin { } void send(const bool b) { printBool(b); - Kaleidoscope.serialPort().print(SEPARATOR); + Runtime.serialPort().print(SEPARATOR); } template void send(V v) { - Kaleidoscope.serialPort().print(v); - Kaleidoscope.serialPort().print(SEPARATOR); + Runtime.serialPort().print(v); + Runtime.serialPort().print(SEPARATOR); } template void send(Var v, Vars... vars) { @@ -53,31 +53,31 @@ class FocusSerial : public kaleidoscope::Plugin { void sendRaw() {} template void sendRaw(Var v, Vars... vars) { - Kaleidoscope.serialPort().print(v); + Runtime.serialPort().print(v); sendRaw(vars...); } const char peek() { - return Kaleidoscope.serialPort().peek(); + return Runtime.serialPort().peek(); } void read(Key &key) { - key.setRaw(Kaleidoscope.serialPort().parseInt()); + key.setRaw(Runtime.serialPort().parseInt()); } void read(cRGB &color) { - color.r = Kaleidoscope.serialPort().parseInt(); - color.g = Kaleidoscope.serialPort().parseInt(); - color.b = Kaleidoscope.serialPort().parseInt(); + color.r = Runtime.serialPort().parseInt(); + color.g = Runtime.serialPort().parseInt(); + color.b = Runtime.serialPort().parseInt(); } void read(uint8_t &u8) { - u8 = Kaleidoscope.serialPort().parseInt(); + u8 = Runtime.serialPort().parseInt(); } void read(uint16_t &u16) { - u16 = Kaleidoscope.serialPort().parseInt(); + u16 = Runtime.serialPort().parseInt(); } bool isEOL() { - return Kaleidoscope.serialPort().peek() == '\n'; + return Runtime.serialPort().peek() == '\n'; } static constexpr char COMMENT = '#'; diff --git a/src/kaleidoscope/plugin/GeminiPR.cpp b/src/kaleidoscope/plugin/GeminiPR.cpp index e3ae17fd..e2f54a7a 100644 --- a/src/kaleidoscope/plugin/GeminiPR.cpp +++ b/src/kaleidoscope/plugin/GeminiPR.cpp @@ -16,6 +16,7 @@ */ #include +#include "kaleidoscope/keyswitch_state.h" namespace kaleidoscope { namespace plugin { @@ -39,7 +40,7 @@ EventHandlerResult GeminiPR::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, if (keys_held_ == 0) { state_[0] |= 0x80; - Kaleidoscope.serialPort().write(state_, sizeof(state_)); + Runtime.serialPort().write(state_, sizeof(state_)); memset(state_, 0, sizeof(state_)); } } diff --git a/src/kaleidoscope/plugin/GeminiPR.h b/src/kaleidoscope/plugin/GeminiPR.h index 193c08e1..c89ac9af 100644 --- a/src/kaleidoscope/plugin/GeminiPR.h +++ b/src/kaleidoscope/plugin/GeminiPR.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include #define S(n) Key(kaleidoscope::plugin::steno::geminipr::n) diff --git a/src/kaleidoscope/plugin/GhostInTheFirmware.cpp b/src/kaleidoscope/plugin/GhostInTheFirmware.cpp index d582b86c..2929f07c 100644 --- a/src/kaleidoscope/plugin/GhostInTheFirmware.cpp +++ b/src/kaleidoscope/plugin/GhostInTheFirmware.cpp @@ -15,8 +15,9 @@ * this program. If not, see . */ -#include +#include "kaleidoscope/Runtime.h" #include +#include "kaleidoscope/keyswitch_state.h" namespace kaleidoscope { namespace plugin { @@ -46,11 +47,11 @@ EventHandlerResult GhostInTheFirmware::beforeReportingState() { return EventHandlerResult::OK; } is_pressed_ = true; - start_time_ = Kaleidoscope.millisAtCycleStart(); + start_time_ = Runtime.millisAtCycleStart(); } else { - if (is_pressed_ && Kaleidoscope.hasTimeExpired(start_time_, press_timeout_)) { + if (is_pressed_ && Runtime.hasTimeExpired(start_time_, press_timeout_)) { is_pressed_ = false; - start_time_ = Kaleidoscope.millisAtCycleStart(); + start_time_ = Runtime.millisAtCycleStart(); byte row = pgm_read_byte(&(ghost_keys[current_pos_].row)); byte col = pgm_read_byte(&(ghost_keys[current_pos_].col)); @@ -61,7 +62,7 @@ EventHandlerResult GhostInTheFirmware::beforeReportingState() { byte col = pgm_read_byte(&(ghost_keys[current_pos_].col)); handleKeyswitchEvent(Key_NoKey, KeyAddr(row, col), IS_PRESSED); - } else if (Kaleidoscope.hasTimeExpired(start_time_, delay_timeout_)) { + } else if (Runtime.hasTimeExpired(start_time_, delay_timeout_)) { current_pos_++; press_timeout_ = 0; } diff --git a/src/kaleidoscope/plugin/GhostInTheFirmware.h b/src/kaleidoscope/plugin/GhostInTheFirmware.h index 823e2f0e..38dd5598 100644 --- a/src/kaleidoscope/plugin/GhostInTheFirmware.h +++ b/src/kaleidoscope/plugin/GhostInTheFirmware.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/HardwareTestMode.cpp b/src/kaleidoscope/plugin/HardwareTestMode.cpp index 3297f7c3..ba550bfa 100644 --- a/src/kaleidoscope/plugin/HardwareTestMode.cpp +++ b/src/kaleidoscope/plugin/HardwareTestMode.cpp @@ -14,9 +14,10 @@ * this program. If not, see . */ -#include "Kaleidoscope.h" +#include "kaleidoscope/Runtime.h" #include "Kaleidoscope-HardwareTestMode.h" #include "Kaleidoscope-LEDEffect-Rainbow.h" +#include "kaleidoscope/hid.h" namespace kaleidoscope { namespace plugin { @@ -32,9 +33,9 @@ void HardwareTestMode::setActionKey(uint8_t key) { void HardwareTestMode::waitForKeypress() { while (1) { - Kaleidoscope.device().readMatrix(); - if (Kaleidoscope.device().isKeyswitchPressed(actionKey) && - ! Kaleidoscope.device().wasKeyswitchPressed(actionKey)) { + Runtime.device().readMatrix(); + if (Runtime.device().isKeyswitchPressed(actionKey) && + ! Runtime.device().wasKeyswitchPressed(actionKey)) { break; } } @@ -76,7 +77,7 @@ void HardwareTestMode::testLeds(void) { void HardwareTestMode::testMatrix() { // Reset bad keys from previous tests. - chatter_data state[Kaleidoscope.device().numKeys()] = {{0, 0, 0}}; + chatter_data state[Runtime.device().numKeys()] = {{0, 0, 0}}; constexpr cRGB red = CRGB(201, 0, 0); constexpr cRGB blue = CRGB(0, 0, 201); @@ -84,12 +85,12 @@ void HardwareTestMode::testMatrix() { constexpr cRGB yellow = CRGB(201, 100, 0); while (1) { - Kaleidoscope.device().readMatrix(); + Runtime.device().readMatrix(); for (auto key_addr : KeyAddr::all()) { uint8_t keynum = key_addr.toInt(); // If the key is toggled on - if (Kaleidoscope.device().isKeyswitchPressed(key_addr) && ! Kaleidoscope.device().wasKeyswitchPressed(key_addr)) { + if (Runtime.device().isKeyswitchPressed(key_addr) && ! Runtime.device().wasKeyswitchPressed(key_addr)) { // And it's too soon (in terms of cycles between changes) state[keynum].tested = 1; if (state[keynum].cyclesSinceStateChange < CHATTER_CYCLE_LIMIT) { @@ -100,19 +101,19 @@ void HardwareTestMode::testMatrix() { state[keynum].cyclesSinceStateChange++; } // If the key is held down - if (Kaleidoscope.device().isKeyswitchPressed(key_addr) && Kaleidoscope.device().wasKeyswitchPressed(key_addr)) { - Kaleidoscope.device().setCrgbAt(key_addr, green); + if (Runtime.device().isKeyswitchPressed(key_addr) && Runtime.device().wasKeyswitchPressed(key_addr)) { + Runtime.device().setCrgbAt(key_addr, green); } // If we triggered chatter detection ever on this key else if (state[keynum].bad == 1) { - Kaleidoscope.device().setCrgbAt(key_addr, red); + Runtime.device().setCrgbAt(key_addr, red); } else if (state[keynum].tested == 0) { - Kaleidoscope.device().setCrgbAt(key_addr, yellow); + Runtime.device().setCrgbAt(key_addr, yellow); } // If the key is not currently pressed and was not just released and is not marked bad - else if (! Kaleidoscope.device().isKeyswitchPressed(key_addr)) { - Kaleidoscope.device().setCrgbAt(key_addr, blue); + else if (! Runtime.device().isKeyswitchPressed(key_addr)) { + Runtime.device().setCrgbAt(key_addr, blue); } } ::LEDControl.syncLeds(); @@ -124,7 +125,7 @@ void HardwareTestMode::runTests() { // out and send a new report kaleidoscope::hid::releaseAllKeys(); kaleidoscope::hid::sendKeyboardReport(); - Kaleidoscope.device().enableHardwareTestMode(); + Runtime.device().enableHardwareTestMode(); testLeds(); testMatrix(); } diff --git a/src/kaleidoscope/plugin/HardwareTestMode.h b/src/kaleidoscope/plugin/HardwareTestMode.h index 65ab36e4..093e753d 100644 --- a/src/kaleidoscope/plugin/HardwareTestMode.h +++ b/src/kaleidoscope/plugin/HardwareTestMode.h @@ -17,7 +17,7 @@ #pragma once #include -#include "Kaleidoscope.h" +#include "kaleidoscope/Runtime.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/Heatmap.cpp b/src/kaleidoscope/plugin/Heatmap.cpp index 1fcf070e..2a492d2c 100644 --- a/src/kaleidoscope/plugin/Heatmap.cpp +++ b/src/kaleidoscope/plugin/Heatmap.cpp @@ -15,9 +15,10 @@ * this program. If not, see . */ -#include +#include "kaleidoscope/Runtime.h" #include #include +#include "kaleidoscope/keyswitch_state.h" namespace kaleidoscope { namespace plugin { @@ -38,7 +39,7 @@ Heatmap::TransientLEDMode::TransientLEDMode(const Heatmap *parent) // max of heatmap_ (we divide by it so we start at 1) highest_(1), // last heatmap computation time - last_heatmap_comp_time_(Kaleidoscope.millisAtCycleStart()) + last_heatmap_comp_time_(Runtime.millisAtCycleStart()) {} cRGB Heatmap::TransientLEDMode::computeColor(float v) { @@ -133,7 +134,7 @@ void Heatmap::TransientLEDMode::resetMap() { } EventHandlerResult Heatmap::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return EventHandlerResult::OK; // this methode is called frequently by Kaleidoscope @@ -175,7 +176,7 @@ EventHandlerResult Heatmap::TransientLEDMode::onKeyswitchEvent(Key &mapped_key, } EventHandlerResult Heatmap::beforeEachCycle() { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return EventHandlerResult::OK; if (::LEDControl.get_mode_index() != led_mode_id_) @@ -201,19 +202,19 @@ EventHandlerResult Heatmap::TransientLEDMode::beforeEachCycle() { } void Heatmap::TransientLEDMode::update(void) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return; // this methode is called frequently by the LEDControl::loopHook // do nothing if the update interval hasn't elapsed since the previous update - if (!Kaleidoscope.hasTimeExpired(last_heatmap_comp_time_, update_delay)) + if (!Runtime.hasTimeExpired(last_heatmap_comp_time_, update_delay)) return; // do the heatmap computing // (update_delay milliseconds elapsed since last_heatmap_comp_time) // schedule the next heatmap computing - last_heatmap_comp_time_ = Kaleidoscope.millisAtCycleStart(); + last_heatmap_comp_time_ = Runtime.millisAtCycleStart(); // for each key for (auto key_addr : KeyAddr::all()) { diff --git a/src/kaleidoscope/plugin/Heatmap.h b/src/kaleidoscope/plugin/Heatmap.h index ce8d4f27..829d6dd3 100644 --- a/src/kaleidoscope/plugin/Heatmap.h +++ b/src/kaleidoscope/plugin/Heatmap.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include namespace kaleidoscope { @@ -57,7 +57,7 @@ class Heatmap : public Plugin, private: - uint16_t heatmap_[Kaleidoscope.device().numKeys()]; + uint16_t heatmap_[Runtime.device().numKeys()]; uint16_t highest_; uint16_t last_heatmap_comp_time_; diff --git a/src/kaleidoscope/plugin/HostOS-Focus.h b/src/kaleidoscope/plugin/HostOS-Focus.h index 87a5f452..e9fe27ae 100644 --- a/src/kaleidoscope/plugin/HostOS-Focus.h +++ b/src/kaleidoscope/plugin/HostOS-Focus.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/HostOS.cpp b/src/kaleidoscope/plugin/HostOS.cpp index d38fc638..2c91b3be 100644 --- a/src/kaleidoscope/plugin/HostOS.cpp +++ b/src/kaleidoscope/plugin/HostOS.cpp @@ -33,15 +33,15 @@ EventHandlerResult HostOS::onSetup(void) { return EventHandlerResult::OK; } - os_ = (hostos::Type)Kaleidoscope.storage().read(eeprom_slice_); + os_ = (hostos::Type)Runtime.storage().read(eeprom_slice_); return EventHandlerResult::OK; } void HostOS::os(hostos::Type new_os) { os_ = new_os; - Kaleidoscope.storage().update(eeprom_slice_, os_); - Kaleidoscope.storage().commit(); + Runtime.storage().update(eeprom_slice_, os_); + Runtime.storage().commit(); } } diff --git a/src/kaleidoscope/plugin/HostOS.h b/src/kaleidoscope/plugin/HostOS.h index c959118f..3d9b4c36 100644 --- a/src/kaleidoscope/plugin/HostOS.h +++ b/src/kaleidoscope/plugin/HostOS.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/HostPowerManagement.cpp b/src/kaleidoscope/plugin/HostPowerManagement.cpp index 63bc187d..a85ad956 100644 --- a/src/kaleidoscope/plugin/HostPowerManagement.cpp +++ b/src/kaleidoscope/plugin/HostPowerManagement.cpp @@ -15,7 +15,7 @@ * this program. If not, see . */ -#include +#include "kaleidoscope/Runtime.h" #include #include diff --git a/src/kaleidoscope/plugin/HostPowerManagement.h b/src/kaleidoscope/plugin/HostPowerManagement.h index 0750193c..3d2ebe09 100644 --- a/src/kaleidoscope/plugin/HostPowerManagement.h +++ b/src/kaleidoscope/plugin/HostPowerManagement.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #define _DEPRECATED_MESSAGE_ENABLEWAKEUP \ "The HostPowerManagement.enableWakeup() call is not necessary anymore,\n" \ diff --git a/src/kaleidoscope/plugin/IdleLEDs.cpp b/src/kaleidoscope/plugin/IdleLEDs.cpp index f0809d38..8cac7e2e 100644 --- a/src/kaleidoscope/plugin/IdleLEDs.cpp +++ b/src/kaleidoscope/plugin/IdleLEDs.cpp @@ -37,7 +37,7 @@ void IdleLEDs::setIdleTimeoutSeconds(uint32_t new_limit) { EventHandlerResult IdleLEDs::beforeEachCycle() { if (!::LEDControl.paused && - Kaleidoscope.hasTimeExpired(start_time_, idle_time_limit)) { + Runtime.hasTimeExpired(start_time_, idle_time_limit)) { ::LEDControl.set_all_leds_to(CRGB(0, 0, 0)); ::LEDControl.syncLeds(); @@ -54,7 +54,7 @@ EventHandlerResult IdleLEDs::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, ::LEDControl.refreshAll(); } - start_time_ = Kaleidoscope.millisAtCycleStart(); + start_time_ = Runtime.millisAtCycleStart(); return EventHandlerResult::OK; } @@ -67,7 +67,7 @@ EventHandlerResult PersistentIdleLEDs::onSetup() { // If idleTime is max, assume that EEPROM is uninitialized, and store the // defaults. uint16_t idle_time; - Kaleidoscope.storage().get(settings_base_, idle_time); + Runtime.storage().get(settings_base_, idle_time); if (idle_time == 0xffff) { idle_time = idle_time_limit; } @@ -80,8 +80,8 @@ void PersistentIdleLEDs::setIdleTimeoutSeconds(uint32_t new_limit) { IdleLEDs::setIdleTimeoutSeconds(new_limit); uint16_t stored_limit = (uint16_t)new_limit; - Kaleidoscope.storage().put(settings_base_, stored_limit); - Kaleidoscope.storage().commit(); + Runtime.storage().put(settings_base_, stored_limit); + Runtime.storage().commit(); } EventHandlerResult PersistentIdleLEDs::onFocusEvent(const char *command) { diff --git a/src/kaleidoscope/plugin/IdleLEDs.h b/src/kaleidoscope/plugin/IdleLEDs.h index 1a4e3e92..c6da2981 100644 --- a/src/kaleidoscope/plugin/IdleLEDs.h +++ b/src/kaleidoscope/plugin/IdleLEDs.h @@ -18,7 +18,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/LED-ActiveLayerColor.cpp b/src/kaleidoscope/plugin/LED-ActiveLayerColor.cpp index 12eb2bf8..0cd7c081 100644 --- a/src/kaleidoscope/plugin/LED-ActiveLayerColor.cpp +++ b/src/kaleidoscope/plugin/LED-ActiveLayerColor.cpp @@ -16,6 +16,7 @@ */ #include +#include "kaleidoscope/layers.h" namespace kaleidoscope { namespace plugin { @@ -45,7 +46,7 @@ cRGB LEDActiveLayerColorEffect::TransientLEDMode::getActiveColor() { } void LEDActiveLayerColorEffect::TransientLEDMode::onActivate(void) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return; active_color_ = getActiveColor(); diff --git a/src/kaleidoscope/plugin/LED-ActiveModColor.cpp b/src/kaleidoscope/plugin/LED-ActiveModColor.cpp index 96269f6f..98cbeb2e 100644 --- a/src/kaleidoscope/plugin/LED-ActiveModColor.cpp +++ b/src/kaleidoscope/plugin/LED-ActiveModColor.cpp @@ -18,6 +18,7 @@ #include #include #include +#include "kaleidoscope/layers.h" namespace kaleidoscope { namespace plugin { @@ -33,7 +34,7 @@ cRGB ActiveModColorEffect::highlight_color = (cRGB) { cRGB ActiveModColorEffect::sticky_color = CRGB(160, 0, 0); EventHandlerResult ActiveModColorEffect::onLayerChange() { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return EventHandlerResult::OK; mod_key_count_ = 0; diff --git a/src/kaleidoscope/plugin/LED-ActiveModColor.h b/src/kaleidoscope/plugin/LED-ActiveModColor.h index c9ec5f7e..7b554f42 100644 --- a/src/kaleidoscope/plugin/LED-ActiveModColor.h +++ b/src/kaleidoscope/plugin/LED-ActiveModColor.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include #define MAX_MODS_PER_LAYER 16 diff --git a/src/kaleidoscope/plugin/LED-AlphaSquare.cpp b/src/kaleidoscope/plugin/LED-AlphaSquare.cpp index bef9d494..b75b3da9 100644 --- a/src/kaleidoscope/plugin/LED-AlphaSquare.cpp +++ b/src/kaleidoscope/plugin/LED-AlphaSquare.cpp @@ -64,7 +64,7 @@ static const uint16_t alphabet[] PROGMEM = { cRGB AlphaSquare::color = {0x80, 0x80, 0x80}; void AlphaSquare::display(Key key, KeyAddr key_addr, cRGB key_color) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return; if (key < Key_A || key > Key_0) @@ -81,7 +81,7 @@ void AlphaSquare::display(Key key, KeyAddr key_addr) { } void AlphaSquare::display(uint16_t symbol, KeyAddr key_addr, cRGB key_color) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return; for (uint8_t r = 0; r < 4; r++) { @@ -106,7 +106,7 @@ void AlphaSquare::display(uint16_t symbol, KeyAddr key_addr) { bool AlphaSquare::isSymbolPart(Key key, KeyAddr displayLedAddr, KeyAddr key_addr) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return false; if (key < Key_A || key > Key_0) @@ -121,7 +121,7 @@ bool AlphaSquare::isSymbolPart(Key key, bool AlphaSquare::isSymbolPart(uint16_t symbol, KeyAddr displayLedAddr, KeyAddr key_addr) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return false; for (uint8_t r = 0; r < 4; r++) { diff --git a/src/kaleidoscope/plugin/LED-AlphaSquare.h b/src/kaleidoscope/plugin/LED-AlphaSquare.h index 5dd38d80..6852b7e1 100644 --- a/src/kaleidoscope/plugin/LED-AlphaSquare.h +++ b/src/kaleidoscope/plugin/LED-AlphaSquare.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include #define SYM4x4( \ diff --git a/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.cpp b/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.cpp index d54e32d3..7db7dfe5 100644 --- a/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.cpp +++ b/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.cpp @@ -16,6 +16,7 @@ */ #include +#include "kaleidoscope/keyswitch_state.h" namespace kaleidoscope { namespace plugin { @@ -28,16 +29,16 @@ AlphaSquareEffect::TransientLEDMode::TransientLEDMode(AlphaSquareEffect */*paren {} void AlphaSquareEffect::TransientLEDMode::update(void) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return; if (last_key_left_ != Key_NoKey && - Kaleidoscope.hasTimeExpired(start_time_left_, length)) { + Runtime.hasTimeExpired(start_time_left_, length)) { ::AlphaSquare.clear(last_key_left_); last_key_left_ = Key_NoKey; } if (last_key_right_ != Key_NoKey && - Kaleidoscope.hasTimeExpired(start_time_right_, length)) { + Runtime.hasTimeExpired(start_time_right_, length)) { ::AlphaSquare.clear(last_key_right_, 10); last_key_right_ = Key_NoKey; } @@ -48,12 +49,12 @@ void AlphaSquareEffect::TransientLEDMode::refreshAt(KeyAddr key_addr) { uint8_t display_col = 2; Key key = last_key_left_; - if (key_addr.col() < Kaleidoscope.device().matrix_columns / 2) { - timed_out = Kaleidoscope.hasTimeExpired(start_time_left_, length); + if (key_addr.col() < Runtime.device().matrix_columns / 2) { + timed_out = Runtime.hasTimeExpired(start_time_left_, length); } else { key = last_key_right_; display_col = 10; - timed_out = Kaleidoscope.hasTimeExpired(start_time_right_, length); + timed_out = Runtime.hasTimeExpired(start_time_right_, length); } if (!::AlphaSquare.isSymbolPart(key, KeyAddr(0, display_col), key_addr) || timed_out) @@ -61,7 +62,7 @@ void AlphaSquareEffect::TransientLEDMode::refreshAt(KeyAddr key_addr) { } EventHandlerResult AlphaSquareEffect::onKeyswitchEvent(Key &mappedKey, KeyAddr key_addr, uint8_t keyState) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return EventHandlerResult::OK; if (::LEDControl.get_mode_index() != led_mode_id_) @@ -81,13 +82,13 @@ EventHandlerResult AlphaSquareEffect::onKeyswitchEvent(Key &mappedKey, KeyAddr k Key prev_key = this_led_mode->last_key_left_; - if (key_addr.col() < Kaleidoscope.device().matrix_columns / 2) { + if (key_addr.col() < Runtime.device().matrix_columns / 2) { this_led_mode->last_key_left_ = mappedKey; - this_led_mode->start_time_left_ = Kaleidoscope.millisAtCycleStart(); + this_led_mode->start_time_left_ = Runtime.millisAtCycleStart(); } else { prev_key = this_led_mode->last_key_right_; this_led_mode->last_key_right_ = mappedKey; - this_led_mode->start_time_right_ = Kaleidoscope.millisAtCycleStart(); + this_led_mode->start_time_right_ = Runtime.millisAtCycleStart(); display_col = 10; } diff --git a/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.h b/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.h index a7a9788a..2a60507d 100644 --- a/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.h +++ b/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include namespace kaleidoscope { diff --git a/src/kaleidoscope/plugin/LED-Palette-Theme.cpp b/src/kaleidoscope/plugin/LED-Palette-Theme.cpp index e733e83d..cbeffb59 100644 --- a/src/kaleidoscope/plugin/LED-Palette-Theme.cpp +++ b/src/kaleidoscope/plugin/LED-Palette-Theme.cpp @@ -28,27 +28,27 @@ uint16_t LEDPaletteTheme::reserveThemes(uint8_t max_themes) { if (!palette_base_) palette_base_ = ::EEPROMSettings.requestSlice(16 * sizeof(cRGB)); - return ::EEPROMSettings.requestSlice(max_themes * Kaleidoscope.device().led_count / 2); + return ::EEPROMSettings.requestSlice(max_themes * Runtime.device().led_count / 2); } void LEDPaletteTheme::updateHandler(uint16_t theme_base, uint8_t theme) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return; - uint16_t map_base = theme_base + (theme * Kaleidoscope.device().led_count / 2); + uint16_t map_base = theme_base + (theme * Runtime.device().led_count / 2); - for (uint8_t pos = 0; pos < Kaleidoscope.device().led_count; pos++) { + for (uint8_t pos = 0; pos < Runtime.device().led_count; pos++) { cRGB color = lookupColorAtPosition(map_base, pos); ::LEDControl.setCrgbAt(pos, color); } } void LEDPaletteTheme::refreshAt(uint16_t theme_base, uint8_t theme, KeyAddr key_addr) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return; - uint16_t map_base = theme_base + (theme * Kaleidoscope.device().led_count / 2); - uint8_t pos = Kaleidoscope.device().getLedIndex(key_addr); + uint16_t map_base = theme_base + (theme * Runtime.device().led_count / 2); + uint8_t pos = Runtime.device().getLedIndex(key_addr); cRGB color = lookupColorAtPosition(map_base, pos); ::LEDControl.setCrgbAt(key_addr, color); @@ -58,7 +58,7 @@ void LEDPaletteTheme::refreshAt(uint16_t theme_base, uint8_t theme, KeyAddr key_ const uint8_t LEDPaletteTheme::lookupColorIndexAtPosition(uint16_t map_base, uint16_t position) { uint8_t color_index; - color_index = Kaleidoscope.storage().read(map_base + position / 2); + color_index = Runtime.storage().read(map_base + position / 2); if (position % 2) color_index &= ~0xf0; else @@ -76,7 +76,7 @@ const cRGB LEDPaletteTheme::lookupColorAtPosition(uint16_t map_base, uint16_t po const cRGB LEDPaletteTheme::lookupPaletteColor(uint8_t color_index) { cRGB color; - Kaleidoscope.storage().get(palette_base_ + color_index * sizeof(cRGB), color); + Runtime.storage().get(palette_base_ + color_index * sizeof(cRGB), color); color.r ^= 0xff; color.g ^= 0xff; color.b ^= 0xff; @@ -87,7 +87,7 @@ const cRGB LEDPaletteTheme::lookupPaletteColor(uint8_t color_index) { void LEDPaletteTheme::updateColorIndexAtPosition(uint16_t map_base, uint16_t position, uint8_t color_index) { uint8_t indexes; - indexes = Kaleidoscope.storage().read(map_base + position / 2); + indexes = Runtime.storage().read(map_base + position / 2); if (position % 2) { uint8_t other = indexes >> 4; indexes = (other << 4) + color_index; @@ -95,12 +95,12 @@ void LEDPaletteTheme::updateColorIndexAtPosition(uint16_t map_base, uint16_t pos uint8_t other = indexes & ~0xf0; indexes = (color_index << 4) + other; } - Kaleidoscope.storage().update(map_base + position / 2, indexes); - Kaleidoscope.storage().commit(); + Runtime.storage().update(map_base + position / 2, indexes); + Runtime.storage().commit(); } EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return EventHandlerResult::OK; const char *cmd = PSTR("palette"); @@ -130,10 +130,10 @@ EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) { color.g ^= 0xff; color.b ^= 0xff; - Kaleidoscope.storage().put(palette_base_ + i * sizeof(color), color); + Runtime.storage().put(palette_base_ + i * sizeof(color), color); i++; } - Kaleidoscope.storage().commit(); + Runtime.storage().commit(); ::LEDControl.refreshAll(); @@ -144,7 +144,7 @@ EventHandlerResult LEDPaletteTheme::themeFocusEvent(const char *command, const char *expected_command, uint16_t theme_base, uint8_t max_themes) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return EventHandlerResult::OK; if (::Focus.handleHelp(command, expected_command)) @@ -153,11 +153,11 @@ EventHandlerResult LEDPaletteTheme::themeFocusEvent(const char *command, if (strcmp_P(command, expected_command) != 0) return EventHandlerResult::OK; - uint16_t max_index = (max_themes * Kaleidoscope.device().led_count) / 2; + uint16_t max_index = (max_themes * Runtime.device().led_count) / 2; if (::Focus.isEOL()) { for (uint16_t pos = 0; pos < max_index; pos++) { - uint8_t indexes = Kaleidoscope.storage().read(theme_base + pos); + uint8_t indexes = Runtime.storage().read(theme_base + pos); ::Focus.send((uint8_t)(indexes >> 4), indexes & ~0xf0); } @@ -173,10 +173,10 @@ EventHandlerResult LEDPaletteTheme::themeFocusEvent(const char *command, uint8_t indexes = (idx1 << 4) + idx2; - Kaleidoscope.storage().update(theme_base + pos, indexes); + Runtime.storage().update(theme_base + pos, indexes); pos++; } - Kaleidoscope.storage().commit(); + Runtime.storage().commit(); ::LEDControl.refreshAll(); diff --git a/src/kaleidoscope/plugin/LED-Palette-Theme.h b/src/kaleidoscope/plugin/LED-Palette-Theme.h index 08c96d63..54f45c45 100644 --- a/src/kaleidoscope/plugin/LED-Palette-Theme.h +++ b/src/kaleidoscope/plugin/LED-Palette-Theme.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include namespace kaleidoscope { diff --git a/src/kaleidoscope/plugin/LED-Stalker.cpp b/src/kaleidoscope/plugin/LED-Stalker.cpp index e2301d5e..e18598f0 100644 --- a/src/kaleidoscope/plugin/LED-Stalker.cpp +++ b/src/kaleidoscope/plugin/LED-Stalker.cpp @@ -17,6 +17,7 @@ #include #include +#include "kaleidoscope/keyswitch_state.h" namespace kaleidoscope { namespace plugin { @@ -34,7 +35,7 @@ StalkerEffect::TransientLEDMode::TransientLEDMode(const StalkerEffect *parent) {} EventHandlerResult StalkerEffect::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t keyState) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return EventHandlerResult::OK; if (!key_addr.isValid()) @@ -51,13 +52,13 @@ EventHandlerResult StalkerEffect::onKeyswitchEvent(Key &mapped_key, KeyAddr key_ } void StalkerEffect::TransientLEDMode::update(void) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return; if (!parent_->variant) return; - if (!Kaleidoscope.hasTimeExpired(step_start_time_, parent_->step_length)) + if (!Runtime.hasTimeExpired(step_start_time_, parent_->step_length)) return; for (auto key_addr : KeyAddr::all()) { @@ -72,7 +73,7 @@ void StalkerEffect::TransientLEDMode::update(void) { ::LEDControl.setCrgbAt(key_addr, parent_->inactive_color); } - step_start_time_ = Kaleidoscope.millisAtCycleStart(); + step_start_time_ = Runtime.millisAtCycleStart(); } namespace stalker { diff --git a/src/kaleidoscope/plugin/LED-Stalker.h b/src/kaleidoscope/plugin/LED-Stalker.h index 66da6bbd..9642983d 100644 --- a/src/kaleidoscope/plugin/LED-Stalker.h +++ b/src/kaleidoscope/plugin/LED-Stalker.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include #define STALKER(v, ...) ({static kaleidoscope::plugin::stalker::v _effect __VA_ARGS__; &_effect;}) @@ -61,7 +61,7 @@ class StalkerEffect : public Plugin, const StalkerEffect *parent_; uint16_t step_start_time_; - uint8_t map_[Kaleidoscope.device().numKeys()]; + uint8_t map_[Runtime.device().numKeys()]; friend class StalkerEffect; }; diff --git a/src/kaleidoscope/plugin/LED-Wavepool.cpp b/src/kaleidoscope/plugin/LED-Wavepool.cpp index ddc25a04..4f70e8c9 100644 --- a/src/kaleidoscope/plugin/LED-Wavepool.cpp +++ b/src/kaleidoscope/plugin/LED-Wavepool.cpp @@ -19,6 +19,7 @@ #ifdef ARDUINO_AVR_MODEL01 #include +#include "kaleidoscope/keyswitch_state.h" namespace kaleidoscope { namespace plugin { @@ -31,7 +32,7 @@ uint16_t WavepoolEffect::idle_timeout = 5000; // 5 seconds int16_t WavepoolEffect::ripple_hue = WavepoolEffect::rainbow_hue; // automatic hue // map native keyboard coordinates (16x4) into geometric space (14x5) -PROGMEM const uint8_t WavepoolEffect::TransientLEDMode::rc2pos[Kaleidoscope.device().numKeys()] = { +PROGMEM const uint8_t WavepoolEffect::TransientLEDMode::rc2pos[Runtime.device().numKeys()] = { 0, 1, 2, 3, 4, 5, 6, 59, 66, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 34, 60, 65, 35, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 48, 61, 64, 49, 36, 37, 38, 39, 40, 41, @@ -79,14 +80,14 @@ void WavepoolEffect::TransientLEDMode::raindrop(uint8_t x, uint8_t y, int8_t *pa uint8_t WavepoolEffect::TransientLEDMode::wp_rand() { static intptr_t offset = 0x400; offset = ((offset + 1) & 0x4fff) | 0x400; - return (Kaleidoscope.millisAtCycleStart() / MS_PER_FRAME) + pgm_read_byte((const uint8_t *)offset); + return (Runtime.millisAtCycleStart() / MS_PER_FRAME) + pgm_read_byte((const uint8_t *)offset); } void WavepoolEffect::TransientLEDMode::update(void) { // limit the frame rate; one frame every 64 ms static uint8_t prev_time = 0; - uint8_t now = Kaleidoscope.millisAtCycleStart() / MS_PER_FRAME; + uint8_t now = Runtime.millisAtCycleStart() / MS_PER_FRAME; if (now != prev_time) { prev_time = now; } else { diff --git a/src/kaleidoscope/plugin/LED-Wavepool.h b/src/kaleidoscope/plugin/LED-Wavepool.h index 62c98a40..e52d3081 100644 --- a/src/kaleidoscope/plugin/LED-Wavepool.h +++ b/src/kaleidoscope/plugin/LED-Wavepool.h @@ -20,7 +20,7 @@ #ifdef ARDUINO_AVR_MODEL01 -#include +#include "kaleidoscope/Runtime.h" #include #define WP_WID 14 @@ -64,7 +64,7 @@ class WavepoolEffect : public Plugin, uint8_t frames_since_event_; int8_t surface_[2][WP_WID * WP_HGT]; uint8_t page_; - static PROGMEM const uint8_t rc2pos[Kaleidoscope.device().numKeys()]; + static PROGMEM const uint8_t rc2pos[Runtime.device().numKeys()]; void raindrop(uint8_t x, uint8_t y, int8_t *page); uint8_t wp_rand(); diff --git a/src/kaleidoscope/plugin/LEDControl.cpp b/src/kaleidoscope/plugin/LEDControl.cpp index a5390072..8e8f668a 100644 --- a/src/kaleidoscope/plugin/LEDControl.cpp +++ b/src/kaleidoscope/plugin/LEDControl.cpp @@ -17,6 +17,7 @@ #include "Kaleidoscope-LEDControl.h" #include "Kaleidoscope-FocusSerial.h" #include "kaleidoscope_internal/LEDModeManager.h" +#include "kaleidoscope/keyswitch_state.h" using namespace kaleidoscope::internal; @@ -87,7 +88,7 @@ void LEDControl::activate(LEDModeInterface *plugin) { } void LEDControl::set_all_leds_to(uint8_t r, uint8_t g, uint8_t b) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return; cRGB color; @@ -98,31 +99,31 @@ void LEDControl::set_all_leds_to(uint8_t r, uint8_t g, uint8_t b) { } void LEDControl::set_all_leds_to(cRGB color) { - for (auto led_index : Kaleidoscope.device().LEDs().all()) { + for (auto led_index : Runtime.device().LEDs().all()) { setCrgbAt(led_index.offset(), color); } } void LEDControl::setCrgbAt(uint8_t led_index, cRGB crgb) { - Kaleidoscope.device().setCrgbAt(led_index, crgb); + Runtime.device().setCrgbAt(led_index, crgb); } void LEDControl::setCrgbAt(KeyAddr key_addr, cRGB color) { - Kaleidoscope.device().setCrgbAt(key_addr, color); + Runtime.device().setCrgbAt(key_addr, color); } cRGB LEDControl::getCrgbAt(uint8_t led_index) { - return Kaleidoscope.device().getCrgbAt(led_index); + return Runtime.device().getCrgbAt(led_index); } cRGB LEDControl::getCrgbAt(KeyAddr key_addr) { - return Kaleidoscope.device().getCrgbAt(Kaleidoscope.device().getLedIndex(key_addr)); + return Runtime.device().getCrgbAt(Runtime.device().getLedIndex(key_addr)); } void LEDControl::syncLeds(void) { if (paused) return; - Kaleidoscope.device().syncLeds(); + Runtime.device().syncLeds(); } kaleidoscope::EventHandlerResult LEDControl::onSetup() { @@ -156,7 +157,7 @@ kaleidoscope::EventHandlerResult LEDControl::beforeReportingState(void) { if (paused) return kaleidoscope::EventHandlerResult::OK; - if (Kaleidoscope.hasTimeExpired(syncTimer, syncDelay)) { + if (Runtime.hasTimeExpired(syncTimer, syncDelay)) { syncLeds(); syncTimer += syncDelay; update(); @@ -173,7 +174,7 @@ EventHandlerResult FocusLEDCommand::onFocusEvent(const char *command) { THEME, } subCommand; - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return EventHandlerResult::OK; if (::Focus.handleHelp(command, PSTR("led.at\n" @@ -241,7 +242,7 @@ EventHandlerResult FocusLEDCommand::onFocusEvent(const char *command) { } case THEME: { if (::Focus.isEOL()) { - for (auto led_index : Kaleidoscope.device().LEDs().all()) { + for (auto led_index : Runtime.device().LEDs().all()) { cRGB c = ::LEDControl.getCrgbAt(led_index.offset()); ::Focus.send(c); @@ -249,7 +250,7 @@ EventHandlerResult FocusLEDCommand::onFocusEvent(const char *command) { break; } - for (auto led_index : Kaleidoscope.device().LEDs().all()) { + for (auto led_index : Runtime.device().LEDs().all()) { if (::Focus.isEOL()) { break; } diff --git a/src/kaleidoscope/plugin/LEDControl.h b/src/kaleidoscope/plugin/LEDControl.h index 72fb8bf7..1636b8f2 100644 --- a/src/kaleidoscope/plugin/LEDControl.h +++ b/src/kaleidoscope/plugin/LEDControl.h @@ -16,7 +16,8 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" +#include "kaleidoscope/plugin/LEDMode.h" #define LED_TOGGLE B00000001 // Synthetic, internal @@ -41,13 +42,13 @@ class LEDControl : public kaleidoscope::Plugin { static void prev_mode(void); static void setup(void); static void update(void) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return; cur_led_mode_->update(); } static void refreshAt(KeyAddr key_addr) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return; cur_led_mode_->refreshAt(key_addr); @@ -69,7 +70,7 @@ class LEDControl : public kaleidoscope::Plugin { } static void refreshAll() { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return; if (paused) diff --git a/src/kaleidoscope/plugin/LEDControl/LEDUtils.cpp b/src/kaleidoscope/plugin/LEDControl/LEDUtils.cpp index d7faa18f..57c422da 100644 --- a/src/kaleidoscope/plugin/LEDControl/LEDUtils.cpp +++ b/src/kaleidoscope/plugin/LEDControl/LEDUtils.cpp @@ -18,6 +18,9 @@ cRGB breath_compute(uint8_t hue, uint8_t saturation, uint8_t phase_offset) { + + using kaleidoscope::Runtime; + // This code is adapted from FastLED lib8tion.h as of dd5d96c6b289cb6b4b891748a4aeef3ddceaf0e6 // Eventually, we should consider just using FastLED @@ -35,7 +38,7 @@ breath_compute(uint8_t hue, uint8_t saturation, uint8_t phase_offset) { // We do a bit shift here instead of division to ensure that there's no discontinuity // in the output brightness when the integer overflows. - uint8_t i = ((uint16_t)Kaleidoscope.millisAtCycleStart() + (phase_offset << 4)) >> 4; + uint8_t i = ((uint16_t)Runtime.millisAtCycleStart() + (phase_offset << 4)) >> 4; if (i & 0x80) { i = 255 - i; diff --git a/src/kaleidoscope/plugin/LEDControl/LEDUtils.h b/src/kaleidoscope/plugin/LEDControl/LEDUtils.h index 4ad853a3..ed8ffdcf 100644 --- a/src/kaleidoscope/plugin/LEDControl/LEDUtils.h +++ b/src/kaleidoscope/plugin/LEDControl/LEDUtils.h @@ -16,7 +16,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" cRGB breath_compute(uint8_t hue = 170, uint8_t saturation = 255, uint8_t phase_offset = 0); cRGB hsvToRgb(uint16_t h, uint16_t s, uint16_t v); diff --git a/src/kaleidoscope/plugin/LEDEffect-BootAnimation.cpp b/src/kaleidoscope/plugin/LEDEffect-BootAnimation.cpp index eda7dd59..a9b0cc04 100644 --- a/src/kaleidoscope/plugin/LEDEffect-BootAnimation.cpp +++ b/src/kaleidoscope/plugin/LEDEffect-BootAnimation.cpp @@ -16,6 +16,7 @@ */ #include "Kaleidoscope-LEDEffect-BootAnimation.h" +#include "kaleidoscope/layers.h" namespace kaleidoscope { namespace plugin { @@ -44,7 +45,7 @@ EventHandlerResult BootAnimationEffect::onSetup() { } EventHandlerResult BootAnimationEffect::afterEachCycle() { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return EventHandlerResult::OK; //If already done or we're not in a ready state, bail @@ -65,7 +66,7 @@ EventHandlerResult BootAnimationEffect::afterEachCycle() { } } - if (Kaleidoscope.hasTimeExpired(start_time_, timeout)) { + if (Runtime.hasTimeExpired(start_time_, timeout)) { current_index_++; if (current_index_ == sizeof(greeting_)) done_ = true; diff --git a/src/kaleidoscope/plugin/LEDEffect-BootAnimation.h b/src/kaleidoscope/plugin/LEDEffect-BootAnimation.h index 2081ffa1..ea5bc094 100644 --- a/src/kaleidoscope/plugin/LEDEffect-BootAnimation.h +++ b/src/kaleidoscope/plugin/LEDEffect-BootAnimation.h @@ -17,7 +17,7 @@ #pragma once -#include "Kaleidoscope.h" +#include "kaleidoscope/Runtime.h" #include "Kaleidoscope-LEDControl.h" namespace kaleidoscope { diff --git a/src/kaleidoscope/plugin/LEDEffect-BootGreeting.cpp b/src/kaleidoscope/plugin/LEDEffect-BootGreeting.cpp index 070a03b3..b853d41b 100644 --- a/src/kaleidoscope/plugin/LEDEffect-BootGreeting.cpp +++ b/src/kaleidoscope/plugin/LEDEffect-BootGreeting.cpp @@ -16,6 +16,7 @@ */ #include "Kaleidoscope-LEDEffect-BootGreeting.h" +#include "kaleidoscope/layers.h" namespace kaleidoscope { namespace plugin { @@ -59,7 +60,7 @@ EventHandlerResult BootGreetingEffect::onSetup() { } EventHandlerResult BootGreetingEffect::afterEachCycle() { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return EventHandlerResult::OK; //If already done or we're not in a ready state, bail @@ -68,7 +69,7 @@ EventHandlerResult BootGreetingEffect::afterEachCycle() { } //Only run for 'timeout' milliseconds - if (Kaleidoscope.hasTimeExpired(start_time, timeout)) { + if (Runtime.hasTimeExpired(start_time, timeout)) { done_ = true; ::LEDControl.refreshAt(key_addr_); return EventHandlerResult::OK; diff --git a/src/kaleidoscope/plugin/LEDEffect-Breathe.cpp b/src/kaleidoscope/plugin/LEDEffect-Breathe.cpp index 66111359..096b6f7b 100644 --- a/src/kaleidoscope/plugin/LEDEffect-Breathe.cpp +++ b/src/kaleidoscope/plugin/LEDEffect-Breathe.cpp @@ -19,10 +19,10 @@ namespace kaleidoscope { namespace plugin { void LEDBreatheEffect::TransientLEDMode::update(void) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return; - if (!Kaleidoscope.hasTimeExpired(last_update_, update_interval_)) + if (!Runtime.hasTimeExpired(last_update_, update_interval_)) return; last_update_ += update_interval_; diff --git a/src/kaleidoscope/plugin/LEDEffect-Chase.cpp b/src/kaleidoscope/plugin/LEDEffect-Chase.cpp index 5f74fe9e..46072ff5 100644 --- a/src/kaleidoscope/plugin/LEDEffect-Chase.cpp +++ b/src/kaleidoscope/plugin/LEDEffect-Chase.cpp @@ -20,10 +20,10 @@ namespace kaleidoscope { namespace plugin { void LEDChaseEffect::TransientLEDMode::update(void) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return; - if (!Kaleidoscope.hasTimeExpired(last_update_, parent_->update_delay_)) { + if (!Runtime.hasTimeExpired(last_update_, parent_->update_delay_)) { return; } last_update_ += parent_->update_delay_; @@ -38,7 +38,7 @@ void LEDChaseEffect::TransientLEDMode::update(void) { // Since it's an unsigned integer, even when it would have a value below zero, // it underflows and so one test is good for both ends of the range. ::LEDControl.setCrgbAt(pos_, CRGB(0, 0, 0)); - if (Kaleidoscope.device().LEDs().isValid(pos2)) + if (Runtime.device().LEDs().isValid(pos2)) ::LEDControl.setCrgbAt(pos2, CRGB(0, 0, 0)); // Next, we adjust the red light's position. If the direction hasn't changed (the red @@ -48,18 +48,18 @@ void LEDChaseEffect::TransientLEDMode::update(void) { // will be out of bounds. The simplest way to do this is to assign it a value that is // known to be invalid (LED_COUNT). pos_ += direction_; - if (Kaleidoscope.device().LEDs().isValid(pos_)) { + if (Runtime.device().LEDs().isValid(pos_)) { pos2 += direction_; } else { direction_ = -direction_; pos_ += direction_; - pos2 = Kaleidoscope.device().led_count; + pos2 = Runtime.device().led_count; } // Last, we turn on the LEDs at their new positions. As before, the blue light (pos2) is // only set if it's in the valid LED range. ::LEDControl.setCrgbAt(pos_, CRGB(255, 0, 0)); - if (Kaleidoscope.device().LEDs().isValid(pos2)) + if (Runtime.device().LEDs().isValid(pos2)) ::LEDControl.setCrgbAt(pos2, CRGB(0, 0, 255)); } diff --git a/src/kaleidoscope/plugin/LEDEffect-Chase.h b/src/kaleidoscope/plugin/LEDEffect-Chase.h index 9d09f094..912f9624 100644 --- a/src/kaleidoscope/plugin/LEDEffect-Chase.h +++ b/src/kaleidoscope/plugin/LEDEffect-Chase.h @@ -48,7 +48,7 @@ class LEDChaseEffect : public Plugin, // members of their parent class. Most LED modes can do without. // TransientLEDMode(const LEDChaseEffect *parent) - : parent_(parent), last_update_(Kaleidoscope.millisAtCycleStart()) {} + : parent_(parent), last_update_(Runtime.millisAtCycleStart()) {} protected: diff --git a/src/kaleidoscope/plugin/LEDEffect-Rainbow.cpp b/src/kaleidoscope/plugin/LEDEffect-Rainbow.cpp index 76fd05f0..948eb8f5 100644 --- a/src/kaleidoscope/plugin/LEDEffect-Rainbow.cpp +++ b/src/kaleidoscope/plugin/LEDEffect-Rainbow.cpp @@ -20,11 +20,11 @@ namespace kaleidoscope { namespace plugin { void LEDRainbowEffect::TransientLEDMode::update(void) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return; - if (!Kaleidoscope.hasTimeExpired(rainbow_last_update, - parent_->rainbow_update_delay)) { + if (!Runtime.hasTimeExpired(rainbow_last_update, + parent_->rainbow_update_delay)) { return; } else { rainbow_last_update += parent_->rainbow_update_delay; @@ -51,17 +51,17 @@ void LEDRainbowEffect::update_delay(byte delay) { // --------- void LEDRainbowWaveEffect::TransientLEDMode::update(void) { - if (!Kaleidoscope.has_leds) + if (!Runtime.has_leds) return; - if (!Kaleidoscope.hasTimeExpired(rainbow_last_update, - parent_->rainbow_update_delay)) { + if (!Runtime.hasTimeExpired(rainbow_last_update, + parent_->rainbow_update_delay)) { return; } else { rainbow_last_update += parent_->rainbow_update_delay; } - for (auto led_index : Kaleidoscope.device().LEDs().all()) { + for (auto led_index : Runtime.device().LEDs().all()) { uint16_t led_hue = rainbow_hue + 16 * (led_index.offset() / 4); // We want led_hue to be capped at 255, but we do not want to clip it to // that, because that does not result in a nice animation. Instead, when it diff --git a/src/kaleidoscope/plugin/LEDMode.h b/src/kaleidoscope/plugin/LEDMode.h index 6a412fb4..1a67e8cb 100644 --- a/src/kaleidoscope/plugin/LEDMode.h +++ b/src/kaleidoscope/plugin/LEDMode.h @@ -110,7 +110,7 @@ class LEDMode : public kaleidoscope::Plugin, /** Plugin initialization. * - * Called via `Kaleidoscope.use()`, registers the LED mode, and does the + * Called via `Runtime.use()`, registers the LED mode, and does the * necessary initialization steps. Calls @ref setup at the end. */ kaleidoscope::EventHandlerResult onSetup() { diff --git a/src/kaleidoscope/plugin/Leader.cpp b/src/kaleidoscope/plugin/Leader.cpp index ca5f2fd1..85926a72 100644 --- a/src/kaleidoscope/plugin/Leader.cpp +++ b/src/kaleidoscope/plugin/Leader.cpp @@ -16,6 +16,9 @@ */ #include +#include "kaleidoscope/keyswitch_state.h" +#include "kaleidoscope/keyswitch_state.h" +#include "kaleidoscope/key_events.h" namespace kaleidoscope { namespace plugin { @@ -94,7 +97,7 @@ EventHandlerResult Leader::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, u if (keyToggledOff(keyState)) { // not active, but a leader key = start the sequence on key release! - start_time_ = Kaleidoscope.millisAtCycleStart(); + start_time_ = Runtime.millisAtCycleStart(); sequence_pos_ = 0; sequence_[sequence_pos_] = mapped_key; } @@ -113,7 +116,7 @@ EventHandlerResult Leader::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, u return EventHandlerResult::OK; } - start_time_ = Kaleidoscope.millisAtCycleStart(); + start_time_ = Runtime.millisAtCycleStart(); sequence_[sequence_pos_] = mapped_key; action_index = lookup(); @@ -143,7 +146,7 @@ EventHandlerResult Leader::afterEachCycle() { if (!isActive()) return EventHandlerResult::OK; - if (Kaleidoscope.hasTimeExpired(start_time_, time_out)) + if (Runtime.hasTimeExpired(start_time_, time_out)) reset(); return EventHandlerResult::OK; diff --git a/src/kaleidoscope/plugin/Leader.h b/src/kaleidoscope/plugin/Leader.h index 2fe289a6..676cf54b 100644 --- a/src/kaleidoscope/plugin/Leader.h +++ b/src/kaleidoscope/plugin/Leader.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include #define LEADER_MAX_SEQUENCE_LENGTH 4 diff --git a/src/kaleidoscope/plugin/Macros.cpp b/src/kaleidoscope/plugin/Macros.cpp index cc89ce30..3bef8146 100644 --- a/src/kaleidoscope/plugin/Macros.cpp +++ b/src/kaleidoscope/plugin/Macros.cpp @@ -16,6 +16,8 @@ #include "Kaleidoscope-Macros.h" #include "kaleidoscope/hid.h" +#include "kaleidoscope/keyswitch_state.h" +#include "kaleidoscope/key_events.h" __attribute__((weak)) const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { diff --git a/src/kaleidoscope/plugin/Macros.h b/src/kaleidoscope/plugin/Macros.h index 2d398dd9..ca4aaf03 100644 --- a/src/kaleidoscope/plugin/Macros.h +++ b/src/kaleidoscope/plugin/Macros.h @@ -16,10 +16,12 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include "kaleidoscope/plugin/Macros/MacroKeyDefs.h" #include "kaleidoscope/plugin/Macros/MacroSteps.h" +#include "kaleidoscope/keyswitch_state.h" +#include "kaleidoscope/key_events.h" const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState); @@ -61,7 +63,7 @@ class Macros_ : public kaleidoscope::Plugin { /* What follows below, is a bit of template magic that allows us to use Macros.type() with any number of arguments, without having to use a - sentinel. See the comments on Kaleidoscope.use() for more details - this is + sentinel. See the comments on Runtime.use() for more details - this is the same trick. */ inline const macro_t *type() { diff --git a/src/kaleidoscope/plugin/MagicCombo.cpp b/src/kaleidoscope/plugin/MagicCombo.cpp index 934bee1c..6e7104bd 100644 --- a/src/kaleidoscope/plugin/MagicCombo.cpp +++ b/src/kaleidoscope/plugin/MagicCombo.cpp @@ -34,19 +34,19 @@ EventHandlerResult MagicCombo::beforeReportingState() { if (comboKey == 0) break; - match &= Kaleidoscope.device().isKeyswitchPressed(comboKey); + match &= Runtime.device().isKeyswitchPressed(comboKey); if (!match) break; } - if (j != Kaleidoscope.device().pressedKeyswitchCount()) + if (j != Runtime.device().pressedKeyswitchCount()) match = false; - if (match && Kaleidoscope.hasTimeExpired(start_time_, min_interval)) { + if (match && Runtime.hasTimeExpired(start_time_, min_interval)) { ComboAction action = (ComboAction) pgm_read_ptr((void const **) & (magiccombo::combos[i].action)); (*action)(i); - start_time_ = Kaleidoscope.millisAtCycleStart(); + start_time_ = Runtime.millisAtCycleStart(); } } diff --git a/src/kaleidoscope/plugin/MagicCombo.h b/src/kaleidoscope/plugin/MagicCombo.h index 21b7325b..05b0e52c 100644 --- a/src/kaleidoscope/plugin/MagicCombo.h +++ b/src/kaleidoscope/plugin/MagicCombo.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #define MAX_COMBO_LENGTH 5 diff --git a/src/kaleidoscope/plugin/Model01-TestMode.h b/src/kaleidoscope/plugin/Model01-TestMode.h index 127c6bb1..d8abd4b3 100644 --- a/src/kaleidoscope/plugin/Model01-TestMode.h +++ b/src/kaleidoscope/plugin/Model01-TestMode.h @@ -23,7 +23,7 @@ #ifdef ARDUINO_AVR_MODEL01 #include -#include "Kaleidoscope.h" +#include "kaleidoscope/Runtime.h" #include "kaleidoscope_internal/deprecations.h" #define _DEPRECATED_MESSAGE_MODEL01_TESTMODE \ diff --git a/src/kaleidoscope/plugin/MouseKeys.cpp b/src/kaleidoscope/plugin/MouseKeys.cpp index cf80c9ce..0717ba3a 100644 --- a/src/kaleidoscope/plugin/MouseKeys.cpp +++ b/src/kaleidoscope/plugin/MouseKeys.cpp @@ -16,8 +16,10 @@ #include -#include "Kaleidoscope.h" +#include "kaleidoscope/Runtime.h" #include "Kaleidoscope-MouseKeys.h" +#include "kaleidoscope/hid.h" +#include "kaleidoscope/keyswitch_state.h" namespace kaleidoscope { namespace plugin { @@ -46,10 +48,10 @@ void MouseKeys_::setSpeedLimit(uint8_t speed_limit) { } void MouseKeys_::scrollWheel(uint8_t keyCode) { - if (!Kaleidoscope.hasTimeExpired(wheel_start_time_, wheelDelay)) + if (!Runtime.hasTimeExpired(wheel_start_time_, wheelDelay)) return; - wheel_start_time_ = Kaleidoscope.millisAtCycleStart(); + wheel_start_time_ = Runtime.millisAtCycleStart(); if (keyCode & KEY_MOUSE_UP) kaleidoscope::hid::moveMouse(0, 0, wheelSpeed); @@ -75,18 +77,18 @@ EventHandlerResult MouseKeys_::beforeReportingState() { return EventHandlerResult::OK; } - if (!Kaleidoscope.hasTimeExpired(move_start_time_, speedDelay)) + if (!Runtime.hasTimeExpired(move_start_time_, speedDelay)) return EventHandlerResult::OK; - move_start_time_ = Kaleidoscope.millisAtCycleStart(); + move_start_time_ = Runtime.millisAtCycleStart(); int8_t moveX = 0, moveY = 0; - if (Kaleidoscope.hasTimeExpired(accel_start_time_, accelDelay)) { + if (Runtime.hasTimeExpired(accel_start_time_, accelDelay)) { if (MouseWrapper.accelStep < 255 - accelSpeed) { MouseWrapper.accelStep += accelSpeed; } - accel_start_time_ = Kaleidoscope.millisAtCycleStart(); + accel_start_time_ = Runtime.millisAtCycleStart(); } if (mouseMoveIntent & KEY_MOUSE_UP) @@ -124,9 +126,9 @@ EventHandlerResult MouseKeys_::onKeyswitchEvent(Key &mappedKey, KeyAddr key_addr } } else if (!(mappedKey.getKeyCode() & KEY_MOUSE_WARP)) { if (keyToggledOn(keyState)) { - move_start_time_ = Kaleidoscope.millisAtCycleStart(); - accel_start_time_ = Kaleidoscope.millisAtCycleStart(); - wheel_start_time_ = Kaleidoscope.millisAtCycleStart() - wheelDelay; + move_start_time_ = Runtime.millisAtCycleStart(); + accel_start_time_ = Runtime.millisAtCycleStart(); + wheel_start_time_ = Runtime.millisAtCycleStart() - wheelDelay; } if (keyIsPressed(keyState)) { if (mappedKey.getKeyCode() & KEY_MOUSE_WHEEL) { diff --git a/src/kaleidoscope/plugin/MouseKeys.h b/src/kaleidoscope/plugin/MouseKeys.h index c6cbfc0b..62a7113e 100644 --- a/src/kaleidoscope/plugin/MouseKeys.h +++ b/src/kaleidoscope/plugin/MouseKeys.h @@ -16,7 +16,7 @@ #pragma once -#include "Kaleidoscope.h" +#include "kaleidoscope/Runtime.h" #include "kaleidoscope/plugin/MouseKeys/MouseKeyDefs.h" #include "kaleidoscope/plugin/MouseKeys/MouseWarpModes.h" #include "kaleidoscope/plugin/MouseKeys/MouseWrapper.h" diff --git a/src/kaleidoscope/plugin/NumPad.cpp b/src/kaleidoscope/plugin/NumPad.cpp index 4a2629fe..4f878a4e 100644 --- a/src/kaleidoscope/plugin/NumPad.cpp +++ b/src/kaleidoscope/plugin/NumPad.cpp @@ -15,6 +15,7 @@ */ #include "Kaleidoscope-NumPad.h" +#include "kaleidoscope/layers.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/OneShot.cpp b/src/kaleidoscope/plugin/OneShot.cpp index 7cebc507..49f060b0 100644 --- a/src/kaleidoscope/plugin/OneShot.cpp +++ b/src/kaleidoscope/plugin/OneShot.cpp @@ -16,6 +16,8 @@ */ #include +#include "kaleidoscope/keyswitch_state.h" +#include "kaleidoscope/key_events.h" namespace kaleidoscope { namespace plugin { @@ -89,7 +91,7 @@ EventHandlerResult OneShot::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, if (keyToggledOff(keyState)) { state_[idx].pressed = false; } else if (keyToggledOn(keyState)) { - start_time_ = Kaleidoscope.millisAtCycleStart(); + start_time_ = Runtime.millisAtCycleStart(); state_[idx].position = key_addr.toInt(); state_[idx].pressed = true; state_[idx].active = true; @@ -112,7 +114,7 @@ EventHandlerResult OneShot::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, } else { if (keyToggledOff(keyState)) { state_[idx].pressed = false; - if (Kaleidoscope.hasTimeExpired(start_time_, hold_time_out)) { + if (Runtime.hasTimeExpired(start_time_, hold_time_out)) { cancelOneShot(idx); should_cancel_ = false; } @@ -123,12 +125,12 @@ EventHandlerResult OneShot::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, if (prev_key_ == mapped_key && isStickable(mapped_key)) { uint16_t dtto = (double_tap_time_out == -1) ? time_out : double_tap_time_out; - if (!Kaleidoscope.hasTimeExpired(start_time_, dtto)) { + if (!Runtime.hasTimeExpired(start_time_, dtto)) { state_[idx].sticky = true; prev_key_ = mapped_key; } } else { - start_time_ = Kaleidoscope.millisAtCycleStart(); + start_time_ = Runtime.millisAtCycleStart(); state_[idx].position = key_addr.toInt(); state_[idx].active = true; diff --git a/src/kaleidoscope/plugin/OneShot.h b/src/kaleidoscope/plugin/OneShot.h index b59a639e..b08a7d17 100644 --- a/src/kaleidoscope/plugin/OneShot.h +++ b/src/kaleidoscope/plugin/OneShot.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include #define OSM(kc) Key(kaleidoscope::ranges::OSM_FIRST + (Key_ ## kc).getKeyCode() - Key_LeftControl.getKeyCode()) @@ -103,7 +103,7 @@ class OneShot : public kaleidoscope::Plugin { return key.getRaw() >= ranges::OS_FIRST && key.getRaw() <= ranges::OS_LAST; } static bool hasTimedOut() { - return Kaleidoscope.hasTimeExpired(start_time_, time_out); + return Runtime.hasTimeExpired(start_time_, time_out); } }; } diff --git a/src/kaleidoscope/plugin/PersistentLEDMode.cpp b/src/kaleidoscope/plugin/PersistentLEDMode.cpp index 312dbd85..e3389ca5 100644 --- a/src/kaleidoscope/plugin/PersistentLEDMode.cpp +++ b/src/kaleidoscope/plugin/PersistentLEDMode.cpp @@ -16,7 +16,7 @@ * this program. If not, see . */ -#include +#include "kaleidoscope/Runtime.h" #include #include #include @@ -30,7 +30,7 @@ uint8_t PersistentLEDMode::cached_mode_index_; EventHandlerResult PersistentLEDMode::onSetup() { settings_base_ = ::EEPROMSettings.requestSlice(sizeof(cached_mode_index_)); - Kaleidoscope.storage().get(settings_base_, cached_mode_index_); + Runtime.storage().get(settings_base_, cached_mode_index_); // If the index is max, assume an uninitialized EEPROM, and don't set the LED // mode. We don't change the cached index here, `onLEDModeChange()` will do @@ -48,8 +48,8 @@ EventHandlerResult PersistentLEDMode::onLEDModeChange() { return EventHandlerResult::OK; cached_mode_index_ = ::LEDControl.get_mode_index(); - Kaleidoscope.storage().put(settings_base_, cached_mode_index_); - Kaleidoscope.storage().commit(); + Runtime.storage().put(settings_base_, cached_mode_index_); + Runtime.storage().commit(); return EventHandlerResult::OK; } diff --git a/src/kaleidoscope/plugin/PersistentLEDMode.h b/src/kaleidoscope/plugin/PersistentLEDMode.h index 07bc5c31..55508279 100644 --- a/src/kaleidoscope/plugin/PersistentLEDMode.h +++ b/src/kaleidoscope/plugin/PersistentLEDMode.h @@ -18,7 +18,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/Qukeys.cpp b/src/kaleidoscope/plugin/Qukeys.cpp index 09661c18..d823a517 100644 --- a/src/kaleidoscope/plugin/Qukeys.cpp +++ b/src/kaleidoscope/plugin/Qukeys.cpp @@ -18,9 +18,10 @@ #include "kaleidoscope/plugin/Qukeys.h" -#include +#include "kaleidoscope/Runtime.h" #include #include "kaleidoscope/progmem_helpers.h" +#include "kaleidoscope/layers.h" namespace kaleidoscope { @@ -118,7 +119,7 @@ EventHandlerResult Qukeys::beforeReportingState() { // If we get here, that means that the first event in the queue is a qukey // press. All that's left to do is to check if it's been held long enough that // it has timed out. - if (Kaleidoscope.hasTimeExpired(event_queue_.timestamp(0), hold_timeout_)) { + if (Runtime.hasTimeExpired(event_queue_.timestamp(0), hold_timeout_)) { // If it's a SpaceCadet-type key, it takes on its primary value, otherwise // it takes on its secondary value. Key event_key = isModifierKey(queue_head_.primary_key) ? @@ -356,7 +357,7 @@ bool Qukeys::releaseDelayed(uint16_t overlap_start, // here to make sure it doesn't overflow when we multiply by 100. uint32_t overlap_duration = overlap_end - overlap_start; uint32_t release_timeout = (overlap_duration * 100) / overlap_threshold_; - return !Kaleidoscope.hasTimeExpired(overlap_start, uint16_t(release_timeout)); + return !Runtime.hasTimeExpired(overlap_start, uint16_t(release_timeout)); } diff --git a/src/kaleidoscope/plugin/Qukeys.h b/src/kaleidoscope/plugin/Qukeys.h index 949134fb..55761c1e 100644 --- a/src/kaleidoscope/plugin/Qukeys.h +++ b/src/kaleidoscope/plugin/Qukeys.h @@ -18,7 +18,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include #include "kaleidoscope/plugin/Qukeys/KeyAddrEventQueue.h" diff --git a/src/kaleidoscope/plugin/Qukeys/KeyAddrEventQueue.h b/src/kaleidoscope/plugin/Qukeys/KeyAddrEventQueue.h index a39f4ba5..750ce2cd 100644 --- a/src/kaleidoscope/plugin/Qukeys/KeyAddrEventQueue.h +++ b/src/kaleidoscope/plugin/Qukeys/KeyAddrEventQueue.h @@ -20,8 +20,9 @@ #include //#include -#include "kaleidoscope/Kaleidoscope.h" +#include "kaleidoscope/Runtime.h" #include "kaleidoscope/KeyAddr.h" +#include "kaleidoscope/keyswitch_state.h" namespace kaleidoscope { namespace plugin { @@ -85,7 +86,7 @@ class KeyAddrEventQueue { void append(KeyAddr k, uint8_t keyswitch_state) { // assert(length_ < _capacity); addrs_[length_] = k; - timestamps_[length_] = Kaleidoscope.millisAtCycleStart(); + timestamps_[length_] = Runtime.millisAtCycleStart(); bitWrite(release_event_bits_, length_, keyToggledOff(keyswitch_state)); ++length_; } diff --git a/src/kaleidoscope/plugin/Redial.cpp b/src/kaleidoscope/plugin/Redial.cpp index 20c951cb..5b2e0263 100644 --- a/src/kaleidoscope/plugin/Redial.cpp +++ b/src/kaleidoscope/plugin/Redial.cpp @@ -16,6 +16,7 @@ */ #include +#include "kaleidoscope/keyswitch_state.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/Redial.h b/src/kaleidoscope/plugin/Redial.h index 09c9d567..ad483e59 100644 --- a/src/kaleidoscope/plugin/Redial.h +++ b/src/kaleidoscope/plugin/Redial.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include #define Key_Redial Key(kaleidoscope::ranges::REDIAL) diff --git a/src/kaleidoscope/plugin/ShapeShifter.h b/src/kaleidoscope/plugin/ShapeShifter.h index c1d8bcdd..cdb2dc72 100644 --- a/src/kaleidoscope/plugin/ShapeShifter.h +++ b/src/kaleidoscope/plugin/ShapeShifter.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/SpaceCadet.cpp b/src/kaleidoscope/plugin/SpaceCadet.cpp index 7db08f4f..476b324c 100644 --- a/src/kaleidoscope/plugin/SpaceCadet.cpp +++ b/src/kaleidoscope/plugin/SpaceCadet.cpp @@ -17,6 +17,8 @@ #include #include +#include "kaleidoscope/keyswitch_state.h" +#include "kaleidoscope/key_events.h" namespace kaleidoscope { namespace plugin { @@ -119,7 +121,7 @@ EventHandlerResult SpaceCadet::onKeyswitchEvent(Key &mapped_key, KeyAddr key_add if (mapped_key == map[i].input) { //The keypress was valid and a match. Mark it as flagged and reset the counter map[i].flagged = true; - map[i].start_time = Kaleidoscope.millisAtCycleStart(); + map[i].start_time = Runtime.millisAtCycleStart(); //yes, we found a valid key valid_key = true; @@ -199,7 +201,7 @@ EventHandlerResult SpaceCadet::onKeyswitchEvent(Key &mapped_key, KeyAddr key_add } //Check to determine if we have surpassed our timeout for holding this key - if (Kaleidoscope.hasTimeExpired(map[index].start_time, current_timeout)) { + if (Runtime.hasTimeExpired(map[index].start_time, current_timeout)) { // if we timed out, that means we need to keep pressing the mapped // key, but we won't need to send the alternative key in the end map[index].flagged = false; diff --git a/src/kaleidoscope/plugin/SpaceCadet.h b/src/kaleidoscope/plugin/SpaceCadet.h index 22a4f078..d2ef8e06 100644 --- a/src/kaleidoscope/plugin/SpaceCadet.h +++ b/src/kaleidoscope/plugin/SpaceCadet.h @@ -18,7 +18,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include #ifndef SPACECADET_MAP_END diff --git a/src/kaleidoscope/plugin/Syster.cpp b/src/kaleidoscope/plugin/Syster.cpp index d8dee378..f19e180c 100644 --- a/src/kaleidoscope/plugin/Syster.cpp +++ b/src/kaleidoscope/plugin/Syster.cpp @@ -17,6 +17,8 @@ #include #include +#include "kaleidoscope/keyswitch_state.h" +#include "kaleidoscope/key_events.h" #undef SYSTER diff --git a/src/kaleidoscope/plugin/Syster.h b/src/kaleidoscope/plugin/Syster.h index 1433b7eb..7a3ec8de 100644 --- a/src/kaleidoscope/plugin/Syster.h +++ b/src/kaleidoscope/plugin/Syster.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include #define SYSTER_MAX_SYMBOL_LENGTH 32 diff --git a/src/kaleidoscope/plugin/TapDance.cpp b/src/kaleidoscope/plugin/TapDance.cpp index 7a8da000..59ec8c41 100644 --- a/src/kaleidoscope/plugin/TapDance.cpp +++ b/src/kaleidoscope/plugin/TapDance.cpp @@ -17,6 +17,7 @@ #include #include +#include "kaleidoscope/keyswitch_state.h" namespace kaleidoscope { namespace plugin { @@ -38,7 +39,7 @@ void TapDance::interrupt(KeyAddr key_addr) { last_tap_dance_key_ = Key_NoKey; - Kaleidoscope.device().maskKey(key_addr); + Runtime.device().maskKey(key_addr); kaleidoscope::hid::sendKeyboardReport(); kaleidoscope::hid::releaseAllKeys(); @@ -74,7 +75,7 @@ void TapDance::tap(void) { uint8_t idx = last_tap_dance_key_.getRaw() - ranges::TD_FIRST; state_[idx].count++; - start_time_ = Kaleidoscope.millisAtCycleStart(); + start_time_ = Runtime.millisAtCycleStart(); tapDanceAction(idx, last_tap_dance_addr_, state_[idx].count, Tap); } @@ -117,8 +118,8 @@ EventHandlerResult TapDance::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, if (keyToggledOn(keyState)) interrupt(key_addr); - if (Kaleidoscope.device().isKeyMasked(key_addr)) { - Kaleidoscope.device().unMaskKey(key_addr); + if (Runtime.device().isKeyMasked(key_addr)) { + Runtime.device().unMaskKey(key_addr); return EventHandlerResult::EVENT_CONSUMED; } return EventHandlerResult::OK; @@ -193,7 +194,7 @@ EventHandlerResult TapDance::afterEachCycle() { if (last_tap_dance_key_ == Key_NoKey) return EventHandlerResult::OK; - if (Kaleidoscope.hasTimeExpired(start_time_, time_out)) + if (Runtime.hasTimeExpired(start_time_, time_out)) timeout(); return EventHandlerResult::OK; diff --git a/src/kaleidoscope/plugin/TapDance.h b/src/kaleidoscope/plugin/TapDance.h index 9e60bc34..3e4592f2 100644 --- a/src/kaleidoscope/plugin/TapDance.h +++ b/src/kaleidoscope/plugin/TapDance.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include #define TD(n) Key(kaleidoscope::ranges::TD_FIRST + n) diff --git a/src/kaleidoscope/plugin/TopsyTurvy.cpp b/src/kaleidoscope/plugin/TopsyTurvy.cpp index 65417a1e..81c39a21 100644 --- a/src/kaleidoscope/plugin/TopsyTurvy.cpp +++ b/src/kaleidoscope/plugin/TopsyTurvy.cpp @@ -17,6 +17,7 @@ #include #include "kaleidoscope/hid.h" +#include "kaleidoscope/keyswitch_state.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/TopsyTurvy.h b/src/kaleidoscope/plugin/TopsyTurvy.h index b90b86e7..bfd77c24 100644 --- a/src/kaleidoscope/plugin/TopsyTurvy.h +++ b/src/kaleidoscope/plugin/TopsyTurvy.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include #define TOPSY(k) Key(kaleidoscope::ranges::TT_FIRST + (Key_ ## k).getKeyCode()) diff --git a/src/kaleidoscope/plugin/TriColor.cpp b/src/kaleidoscope/plugin/TriColor.cpp index 8f6b7ef5..81534cd7 100644 --- a/src/kaleidoscope/plugin/TriColor.cpp +++ b/src/kaleidoscope/plugin/TriColor.cpp @@ -16,6 +16,7 @@ */ #include +#include "kaleidoscope/layers.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/TriColor.h b/src/kaleidoscope/plugin/TriColor.h index ead3cd40..099fbc5b 100644 --- a/src/kaleidoscope/plugin/TriColor.h +++ b/src/kaleidoscope/plugin/TriColor.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include namespace kaleidoscope { diff --git a/src/kaleidoscope/plugin/Turbo.cpp b/src/kaleidoscope/plugin/Turbo.cpp index fd6dde41..86c06dfc 100644 --- a/src/kaleidoscope/plugin/Turbo.cpp +++ b/src/kaleidoscope/plugin/Turbo.cpp @@ -17,6 +17,9 @@ #include #include +#include "kaleidoscope/layers.h" +#include "kaleidoscope/keyswitch_state.h" +#include "kaleidoscope/hid.h" namespace kaleidoscope { namespace plugin { @@ -101,18 +104,18 @@ EventHandlerResult Turbo::onKeyswitchEvent(Key &key, KeyAddr key_addr, uint8_t k EventHandlerResult Turbo::afterEachCycle() { if (enable) { - if (Kaleidoscope.millisAtCycleStart() - startTime > interval_) { + if (Runtime.millisAtCycleStart() - startTime > interval_) { kaleidoscope::hid::sendKeyboardReport(); - startTime = Kaleidoscope.millisAtCycleStart(); + startTime = Runtime.millisAtCycleStart(); } if (flash_) { - if (Kaleidoscope.millisAtCycleStart() - flashStartTime > flashInterval_ * 2) { + if (Runtime.millisAtCycleStart() - flashStartTime > flashInterval_ * 2) { for (uint16_t i = 0; i < numKeys; i++) { LEDControl::setCrgbAt(KeyAddr(keyPositions[i]), activeColor_); } - flashStartTime = Kaleidoscope.millisAtCycleStart(); - } else if (Kaleidoscope.millisAtCycleStart() - flashStartTime > flashInterval_) { + flashStartTime = Runtime.millisAtCycleStart(); + } else if (Runtime.millisAtCycleStart() - flashStartTime > flashInterval_) { for (uint16_t i = 0; i < numKeys; i++) { LEDControl::setCrgbAt(KeyAddr(keyPositions[i]), {0, 0, 0}); } diff --git a/src/kaleidoscope/plugin/Turbo.h b/src/kaleidoscope/plugin/Turbo.h index 4e1ad7b7..f5d67e4f 100644 --- a/src/kaleidoscope/plugin/Turbo.h +++ b/src/kaleidoscope/plugin/Turbo.h @@ -16,7 +16,7 @@ */ #include -#include +#include "kaleidoscope/Runtime.h" #include #define Key_Turbo Key{kaleidoscope::ranges::TURBO } diff --git a/src/kaleidoscope/plugin/TypingBreaks.cpp b/src/kaleidoscope/plugin/TypingBreaks.cpp index f150cea2..65dfb977 100644 --- a/src/kaleidoscope/plugin/TypingBreaks.cpp +++ b/src/kaleidoscope/plugin/TypingBreaks.cpp @@ -18,6 +18,7 @@ #include #include #include +#include "kaleidoscope/keyswitch_state.h" namespace kaleidoscope { namespace plugin { @@ -46,14 +47,14 @@ EventHandlerResult TypingBreaks::onKeyswitchEvent(Key &mapped_key, KeyAddr key_a // If we are locked... if (keyboard_locked_) { // ...and the lock has not expired yet - if (!Kaleidoscope.hasTimeExpired(lock_start_time_, lock_length)) { + if (!Runtime.hasTimeExpired(lock_start_time_, lock_length)) { return EventHandlerResult::EVENT_CONSUMED; // remain locked } // ...otherwise clear the lock keyboard_locked_ = false; left_hand_keys_ = right_hand_keys_ = 0; - session_start_time_ = Kaleidoscope.millisAtCycleStart(); + session_start_time_ = Runtime.millisAtCycleStart(); TypingBreak(false); } @@ -61,10 +62,10 @@ EventHandlerResult TypingBreaks::onKeyswitchEvent(Key &mapped_key, KeyAddr key_a // Any other case, we are not locked yet! (or we just unlocked) // Are we still in the same session? - if (Kaleidoscope.hasTimeExpired(last_key_time_, idle_time_limit)) { + if (Runtime.hasTimeExpired(last_key_time_, idle_time_limit)) { // No, we are not. Clear timers and start over. left_hand_keys_ = right_hand_keys_ = 0; - session_start_time_ = Kaleidoscope.millisAtCycleStart(); + session_start_time_ = Runtime.millisAtCycleStart(); } // If we have a limit on the either hand, and we reached it, lock up! @@ -78,7 +79,7 @@ EventHandlerResult TypingBreaks::onKeyswitchEvent(Key &mapped_key, KeyAddr key_a if (lock_time_out) { // Is the session longer than lock_time_out? - if (Kaleidoscope.hasTimeExpired(session_start_time_, lock_time_out)) { + if (Runtime.hasTimeExpired(session_start_time_, lock_time_out)) { // Yeah, it is. keyboard_locked_ = true; lock_start_time_ = last_key_time_; @@ -91,11 +92,11 @@ EventHandlerResult TypingBreaks::onKeyswitchEvent(Key &mapped_key, KeyAddr key_a // counters if need be. if (keyToggledOn(key_state)) { - if (key_addr.col() <= Kaleidoscope.device().matrix_columns / 2) + if (key_addr.col() <= Runtime.device().matrix_columns / 2) left_hand_keys_++; else right_hand_keys_++; - last_key_time_ = Kaleidoscope.millisAtCycleStart(); + last_key_time_ = Runtime.millisAtCycleStart(); } return EventHandlerResult::OK; @@ -107,13 +108,13 @@ EventHandlerResult TypingBreaks::onSetup() { // If idleTime is max, assume that EEPROM is uninitialized, and store the // defaults. uint32_t idle_time; - Kaleidoscope.storage().get(settings_base_, idle_time); + Runtime.storage().get(settings_base_, idle_time); if (idle_time == 0xffffffff) { - Kaleidoscope.storage().put(settings_base_, settings); - Kaleidoscope.storage().commit(); + Runtime.storage().put(settings_base_, settings); + Runtime.storage().commit(); } - Kaleidoscope.storage().get(settings_base_, settings); + Runtime.storage().get(settings_base_, settings); return EventHandlerResult::OK; } @@ -193,8 +194,8 @@ EventHandlerResult TypingBreaks::onFocusEvent(const char *command) { break; } - Kaleidoscope.storage().put(settings_base_, settings); - Kaleidoscope.storage().commit(); + Runtime.storage().put(settings_base_, settings); + Runtime.storage().commit(); return EventHandlerResult::EVENT_CONSUMED; } diff --git a/src/kaleidoscope/plugin/TypingBreaks.h b/src/kaleidoscope/plugin/TypingBreaks.h index 4bbc0379..2488b726 100644 --- a/src/kaleidoscope/plugin/TypingBreaks.h +++ b/src/kaleidoscope/plugin/TypingBreaks.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/USB-Quirks.cpp b/src/kaleidoscope/plugin/USB-Quirks.cpp index aef10d1f..f679f257 100644 --- a/src/kaleidoscope/plugin/USB-Quirks.cpp +++ b/src/kaleidoscope/plugin/USB-Quirks.cpp @@ -29,11 +29,11 @@ void USBQuirks::toggleKeyboardProtocol() { #if KALEIDOSCOPE_HIDADAPTOR_ENABLE_KEYBOARD_BOOT_PROTOCOL uint8_t new_protocol = !BootKeyboard.getProtocol(); - Kaleidoscope.detachFromHost(); + Runtime.detachFromHost(); BootKeyboard.default_protocol = new_protocol; BootKeyboard.setProtocol(new_protocol); delay(1000); - Kaleidoscope.attachToHost(); + Runtime.attachToHost(); #endif } diff --git a/src/kaleidoscope/plugin/USB-Quirks.h b/src/kaleidoscope/plugin/USB-Quirks.h index df56b7ab..e942dd34 100644 --- a/src/kaleidoscope/plugin/USB-Quirks.h +++ b/src/kaleidoscope/plugin/USB-Quirks.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/Unicode.h b/src/kaleidoscope/plugin/Unicode.h index 16e2f363..654248f5 100644 --- a/src/kaleidoscope/plugin/Unicode.h +++ b/src/kaleidoscope/plugin/Unicode.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" #include namespace kaleidoscope { diff --git a/src/kaleidoscope/plugin/WinKeyToggle.cpp b/src/kaleidoscope/plugin/WinKeyToggle.cpp index c4273269..89ce0a26 100644 --- a/src/kaleidoscope/plugin/WinKeyToggle.cpp +++ b/src/kaleidoscope/plugin/WinKeyToggle.cpp @@ -15,7 +15,7 @@ * this program. If not, see . */ -#include +#include "kaleidoscope/Runtime.h" #include namespace kaleidoscope { diff --git a/src/kaleidoscope/plugin/WinKeyToggle.h b/src/kaleidoscope/plugin/WinKeyToggle.h index 08380713..6c2dff90 100644 --- a/src/kaleidoscope/plugin/WinKeyToggle.h +++ b/src/kaleidoscope/plugin/WinKeyToggle.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "kaleidoscope/Runtime.h" namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope_internal/deprecations.h b/src/kaleidoscope_internal/deprecations.h index cc2c2851..9ce2bd84 100644 --- a/src/kaleidoscope_internal/deprecations.h +++ b/src/kaleidoscope_internal/deprecations.h @@ -71,3 +71,11 @@ "\n" \ "For further information and examples on how to do that, \n" \ "please see UPGRADING.md." + +#define _DEPRECATED_MESSAGE_GLOBAL_VARIABLE_KALEIDOSCOPE \ + "Variable `Kaleidoscope` in global namespace has been deprecated.\n" \ + "Please use `kaleidoscope::Runtime` instead." + +#define _DEPRECATED_MESSAGE_GLOBAL_TYPENAME_KALEIDOSCOPE \ + "Type `Kaleidoscope_` in global namespace has been deprecated.\n" \ + "Please use `kaleidoscope::Runtime_` instead." diff --git a/src/kaleidoscope_internal/device.cpp b/src/kaleidoscope_internal/device.cpp index c86de8c1..14415db1 100644 --- a/src/kaleidoscope_internal/device.cpp +++ b/src/kaleidoscope_internal/device.cpp @@ -14,7 +14,7 @@ * this program. If not, see . */ -#include +#include "kaleidoscope_internal/device.h" namespace kaleidoscope_internal { kaleidoscope::Device device; diff --git a/src/kaleidoscope_internal/device.h b/src/kaleidoscope_internal/device.h index 7ed95819..0e02321a 100644 --- a/src/kaleidoscope_internal/device.h +++ b/src/kaleidoscope_internal/device.h @@ -16,6 +16,8 @@ #pragma once +#include "kaleidoscope/device/device.h" + namespace kaleidoscope_internal { extern kaleidoscope::Device device; }