diff --git a/plugins/Kaleidoscope-CharShift/src/kaleidoscope/plugin/CharShift.cpp b/plugins/Kaleidoscope-CharShift/src/kaleidoscope/plugin/CharShift.cpp index dd453991..a193c596 100644 --- a/plugins/Kaleidoscope-CharShift/src/kaleidoscope/plugin/CharShift.cpp +++ b/plugins/Kaleidoscope-CharShift/src/kaleidoscope/plugin/CharShift.cpp @@ -34,6 +34,10 @@ namespace plugin { // CharShift class variables CharShift::KeyPair const * CharShift::progmem_keypairs_{nullptr}; uint8_t CharShift::num_keypairs_{0}; +CharShift::GetNumKeyPairsFunction CharShift::numKeyPairs_ = + CharShift::numProgmemKeyPairs; +CharShift::ReadKeyPairFunction CharShift::readKeyPair_ = + CharShift::readKeyPairFromProgmem; bool CharShift::reverse_shift_state_{false}; @@ -117,24 +121,12 @@ bool CharShift::isCharShiftKey(Key key) { CharShift::KeyPair CharShift::decodeCharShiftKey(Key key) { uint8_t i = key.getRaw() - ranges::CS_FIRST; - if (i < numKeyPairs()) { - return readKeyPair(i); + if (i < numKeyPairs_()) { + return readKeyPair_(i); } return {Key_NoKey, Key_NoKey}; } -// This should be overridden if the KeyPairs array is stored in EEPROM -__attribute__((weak)) -uint8_t CharShift::numKeyPairs() { - return numProgmemKeyPairs(); -} - -// This should be overridden if the KeyPairs array is stored in EEPROM -__attribute__((weak)) -CharShift::KeyPair CharShift::readKeyPair(uint8_t n) { - return readKeyPairFromProgmem(n); -} - uint8_t CharShift::numProgmemKeyPairs() { return num_keypairs_; } diff --git a/plugins/Kaleidoscope-CharShift/src/kaleidoscope/plugin/CharShift.h b/plugins/Kaleidoscope-CharShift/src/kaleidoscope/plugin/CharShift.h index f2ace27a..293f88fd 100644 --- a/plugins/Kaleidoscope-CharShift/src/kaleidoscope/plugin/CharShift.h +++ b/plugins/Kaleidoscope-CharShift/src/kaleidoscope/plugin/CharShift.h @@ -76,12 +76,25 @@ class CharShift : public Plugin { num_keypairs_ = _num_keypairs; } + typedef uint8_t (*GetNumKeyPairsFunction)(); + typedef KeyPair (*ReadKeyPairFunction)(uint8_t n); + + static void setNumKeyPairsFunction(GetNumKeyPairsFunction f) { + numKeyPairs_ = f; + } + static void setReadKeyPairFunction(ReadKeyPairFunction f) { + readKeyPair_ = f; + } + private: // A pointer to an array of `KeyPair` objects in PROGMEM static KeyPair const * progmem_keypairs_; // The size of the PROGMEM array of `KeyPair` objects static uint8_t num_keypairs_; + static GetNumKeyPairsFunction numKeyPairs_; + static ReadKeyPairFunction readKeyPair_; + // If a `shift` key needs to be suppressed in `beforeReportingState()` static bool reverse_shift_state_; @@ -91,18 +104,6 @@ class CharShift : public Plugin { /// Look up the `KeyPair` specified by the given keymap entry static KeyPair decodeCharShiftKey(Key key); - /// Get the total number of KeyPairs defined - /// - /// This function can be overridden in order to store the `KeyPair` array in - /// EEPROM instead of PROGMEM. - static uint8_t numKeyPairs(); - - /// Get the `KeyPair` at the specified index from the defined `KeyPair` array - /// - /// This function can be overridden in order to store the `KeyPair` array in - /// EEPROM instead of PROGMEM. - static KeyPair readKeyPair(uint8_t n); - // Default for `keypairsCount()`: size of the PROGMEM array static uint8_t numProgmemKeyPairs(); // Default for `readKeypair(i)`: fetch the value from PROGMEM