From 57a4fd916112d30607dc334d8a22cb21772d1044 Mon Sep 17 00:00:00 2001 From: Evy Bongers Date: Wed, 27 Mar 2024 20:48:15 +0100 Subject: [PATCH] Store both primary and alt keys in PROGMEM Signed-off-by: Evy Bongers --- .../src/kaleidoscope/plugin/Qukeys.cpp | 6 +++--- .../src/kaleidoscope/plugin/Qukeys.h | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/Kaleidoscope-Qukeys/src/kaleidoscope/plugin/Qukeys.cpp b/plugins/Kaleidoscope-Qukeys/src/kaleidoscope/plugin/Qukeys.cpp index f53286ae9c..02455897cc 100644 --- a/plugins/Kaleidoscope-Qukeys/src/kaleidoscope/plugin/Qukeys.cpp +++ b/plugins/Kaleidoscope-Qukeys/src/kaleidoscope/plugin/Qukeys.cpp @@ -316,10 +316,10 @@ bool Qukeys::isQukey(KeyAddr k) { // Then, we check to see if this is a Qukey using the new API (defined in the keymap) if (key >= ranges::QK_FIRST && key <= ranges::QK_LAST) { - key.setRaw(key.getRaw() - ranges::QK_FIRST); + uint8_t qkey_index = key.getRaw() - ranges::QK_FIRST; - // TODO(EvyBongers): retrieve the stored qkey index - Key qkey = cloneFromProgmem(qkeys_[i]); + key.setRaw(cloneFromProgmem(qkeys_[i])[0].getRaw()); + Key qkey = cloneFromProgmem(qkeys_[i])[1]; queue_head_.primary_key = key; queue_head_.alternate_key = qkey; diff --git a/plugins/Kaleidoscope-Qukeys/src/kaleidoscope/plugin/Qukeys.h b/plugins/Kaleidoscope-Qukeys/src/kaleidoscope/plugin/Qukeys.h index e030fd8e9b..a13a1de441 100644 --- a/plugins/Kaleidoscope-Qukeys/src/kaleidoscope/plugin/Qukeys.h +++ b/plugins/Kaleidoscope-Qukeys/src/kaleidoscope/plugin/Qukeys.h @@ -141,8 +141,9 @@ class Qukeys : public kaleidoscope::Plugin { } // Function to store a Qkey - uint8_t storeQkey(Key alt_key) { - qkeys_[qkeys_count_] = alt_key; + uint8_t storeQkey(Key primary_key, Key alt_key) { + qkeys_[qkeys_count_][0] = primary_key; + qkeys_[qkeys_count_][1] = alt_key; ++qkeys_count_; return (qkeys_count_ - 1); } @@ -167,10 +168,6 @@ class Qukeys : public kaleidoscope::Plugin { EventHandlerResult afterEachCycle(); private: - // An array of Qkeys in PROGMEM. - Key const *qkeys_ PROGMEM; - uint8_t qkeys_count_{0}; - // An array of Qukey objects in PROGMEM. Qukey const *qukeys_{nullptr}; uint8_t qukeys_count_{0}; @@ -235,6 +232,10 @@ class Qukeys : public kaleidoscope::Plugin { uint8_t timeout{200}; } tap_repeat_; bool shouldWaitForTapRepeat(); + + // An array of Qkeys in PROGMEM. + uint8_t qkeys_count_{0}; + Key const qkeys_[][2] PROGMEM; }; // This function returns true for any key that we expect to be used chorded with @@ -248,9 +249,8 @@ bool isModifierKey(Key key); extern kaleidoscope::plugin::Qukeys Qukeys; constexpr Key Qkey(Key tap_key, Key qkey) { - uint8_t qkey_index = Qukeys.storeQkey(qkey); - // TODO(EvyBongers): store the qkey index somewhere, somehow - return Key(kaleidoscope::ranges::QK_FIRST + tap_key.getRaw()); + uint8_t qkey_index = Qukeys.storeQkey(tap_key, qkey); + return Key(kaleidoscope::ranges::QK_FIRST + qkey_index); } // Macro for use in sketch file to simplify definition of the qukeys array and