|
|
@ -24,6 +24,10 @@
|
|
|
|
namespace kaleidoscope {
|
|
|
|
namespace kaleidoscope {
|
|
|
|
namespace plugin {
|
|
|
|
namespace plugin {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace charshift {
|
|
|
|
|
|
|
|
class Storage;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
// =============================================================================
|
|
|
|
/// Kaleidoscope plugin for independently assigning shifted symbols
|
|
|
|
/// Kaleidoscope plugin for independently assigning shifted symbols
|
|
|
|
///
|
|
|
|
///
|
|
|
@ -36,9 +40,11 @@ namespace plugin {
|
|
|
|
class CharShift : public Plugin {
|
|
|
|
class CharShift : public Plugin {
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
|
|
|
|
EventHandlerResult onSetup();
|
|
|
|
EventHandlerResult onNameQuery();
|
|
|
|
EventHandlerResult onNameQuery();
|
|
|
|
EventHandlerResult onKeyEvent(KeyEvent &event);
|
|
|
|
EventHandlerResult onKeyEvent(KeyEvent &event);
|
|
|
|
EventHandlerResult beforeReportingState(const KeyEvent &event);
|
|
|
|
EventHandlerResult beforeReportingState(const KeyEvent &event);
|
|
|
|
|
|
|
|
EventHandlerResult onFocusEvent(const char *command);
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/// A structure that stores CharShift key pair values
|
|
|
|
/// A structure that stores CharShift key pair values
|
|
|
@ -63,39 +69,15 @@ class CharShift : public Plugin {
|
|
|
|
KeyPair() = default;
|
|
|
|
KeyPair() = default;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Configure the KeyPairs array in PROGMEM
|
|
|
|
charshift::Storage &storage() {
|
|
|
|
///
|
|
|
|
return *storage_;
|
|
|
|
/// This function configures the PROGMEM array of `KeyPair` objects,
|
|
|
|
|
|
|
|
/// automatically setting the internal count variable from the size of the
|
|
|
|
|
|
|
|
/// `keypairs` array given, which must be a fixed-sized array, not a pointer.
|
|
|
|
|
|
|
|
/// Generally, it will be called via the `KEYPAIRS()` preprocessor macro, not
|
|
|
|
|
|
|
|
/// directly by user code.
|
|
|
|
|
|
|
|
template <uint8_t _num_keypairs>
|
|
|
|
|
|
|
|
static void setProgmemKeyPairs(KeyPair const(&keypairs)[_num_keypairs]) {
|
|
|
|
|
|
|
|
progmem_keypairs_ = keypairs;
|
|
|
|
|
|
|
|
num_keypairs_ = _num_keypairs;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void setStorage(charshift::Storage *st) {
|
|
|
|
typedef uint8_t (*GetNumKeyPairsFunction)();
|
|
|
|
storage_ = st;
|
|
|
|
typedef KeyPair (*ReadKeyPairFunction)(uint8_t n);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void setNumKeyPairsFunction(GetNumKeyPairsFunction f) {
|
|
|
|
|
|
|
|
numKeyPairs_ = f;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void setReadKeyPairFunction(ReadKeyPairFunction f) {
|
|
|
|
|
|
|
|
readKeyPair_ = f;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
friend class CharShiftConfig;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
// A pointer to an array of `KeyPair` objects in PROGMEM
|
|
|
|
static charshift::Storage *storage_;
|
|
|
|
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()`
|
|
|
|
// If a `shift` key needs to be suppressed in `beforeReportingState()`
|
|
|
|
static bool reverse_shift_state_;
|
|
|
|
static bool reverse_shift_state_;
|
|
|
@ -105,41 +87,68 @@ class CharShift : public Plugin {
|
|
|
|
|
|
|
|
|
|
|
|
/// Look up the `KeyPair` specified by the given keymap entry
|
|
|
|
/// Look up the `KeyPair` specified by the given keymap entry
|
|
|
|
static KeyPair decodeCharShiftKey(Key key);
|
|
|
|
static KeyPair decodeCharShiftKey(Key key);
|
|
|
|
|
|
|
|
|
|
|
|
// Default for `keypairsCount()`: size of the PROGMEM array
|
|
|
|
|
|
|
|
static uint8_t numProgmemKeyPairs();
|
|
|
|
|
|
|
|
// Default for `readKeypair(i)`: fetch the value from PROGMEM
|
|
|
|
|
|
|
|
static KeyPair readKeyPairFromProgmem(uint8_t n);
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CharShiftConfig: public Plugin {
|
|
|
|
namespace charshift {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Storage {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
CharShiftConfig() {}
|
|
|
|
Storage() {}
|
|
|
|
|
|
|
|
|
|
|
|
EventHandlerResult onNameQuery();
|
|
|
|
static uint8_t numKeyPairs() {
|
|
|
|
EventHandlerResult onFocusEvent(const char *command);
|
|
|
|
return num_keypairs_;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static CharShift::KeyPair readKeyPair(uint8_t n) {
|
|
|
|
|
|
|
|
return CharShift::KeyPair(Key_NoKey, Key_NoKey);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void setup(uint8_t dynamic_offset, uint8_t max_pairs);
|
|
|
|
EventHandlerResult onFocusEvent(const char *command) {
|
|
|
|
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
protected:
|
|
|
|
static uint8_t max_pairs_;
|
|
|
|
static uint8_t num_keypairs_;
|
|
|
|
static uint16_t storage_base_;
|
|
|
|
};
|
|
|
|
static uint8_t dynamic_offset_;
|
|
|
|
|
|
|
|
|
|
|
|
class ProgmemStorage: public Storage {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static CharShift::KeyPair readKeyPair(uint8_t n);
|
|
|
|
|
|
|
|
|
|
|
|
static uint8_t numEEPROMPairs() {
|
|
|
|
/// Configure the KeyPairs array in PROGMEM
|
|
|
|
return max_pairs_;
|
|
|
|
///
|
|
|
|
|
|
|
|
/// This function configures the PROGMEM array of `KeyPair` objects,
|
|
|
|
|
|
|
|
/// automatically setting the internal count variable from the size of the
|
|
|
|
|
|
|
|
/// `keypairs` array given, which must be a fixed-sized array, not a pointer.
|
|
|
|
|
|
|
|
/// Generally, it will be called via the `KEYPAIRS()` preprocessor macro, not
|
|
|
|
|
|
|
|
/// directly by user code.
|
|
|
|
|
|
|
|
template <uint8_t _num_keypairs>
|
|
|
|
|
|
|
|
static void setKeyPairs(CharShift::KeyPair const(&keypairs)[_num_keypairs]) {
|
|
|
|
|
|
|
|
keypairs_ = keypairs;
|
|
|
|
|
|
|
|
num_keypairs_ = _num_keypairs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static CharShift::KeyPair readKeyPairFromEEPROM(uint8_t n);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint8_t numPairs();
|
|
|
|
private:
|
|
|
|
|
|
|
|
// A pointer to an array of `KeyPair` objects in PROGMEM
|
|
|
|
|
|
|
|
static CharShift::KeyPair const *keypairs_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EEPROMStorage: public Storage {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
void setup(uint8_t num_pairs);
|
|
|
|
static CharShift::KeyPair readKeyPair(uint8_t n);
|
|
|
|
static CharShift::KeyPair readKeyPair(uint8_t n);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EventHandlerResult onFocusEvent(const char *command);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
static uint16_t storage_base_;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace plugin
|
|
|
|
} // namespace plugin
|
|
|
|
} // namespace kaleidoscope
|
|
|
|
} // namespace kaleidoscope
|
|
|
|
|
|
|
|
|
|
|
|
extern kaleidoscope::plugin::CharShift CharShift;
|
|
|
|
extern kaleidoscope::plugin::CharShift CharShift;
|
|
|
|
extern kaleidoscope::plugin::CharShiftConfig CharShiftConfig;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Define an array of `KeyPair` objects in PROGMEM
|
|
|
|
/// Define an array of `KeyPair` objects in PROGMEM
|
|
|
|
///
|
|
|
|
///
|
|
|
@ -151,7 +160,7 @@ extern kaleidoscope::plugin::CharShiftConfig CharShiftConfig;
|
|
|
|
static kaleidoscope::plugin::CharShift::KeyPair const kp_table[] PROGMEM = { \
|
|
|
|
static kaleidoscope::plugin::CharShift::KeyPair const kp_table[] PROGMEM = { \
|
|
|
|
keypairs \
|
|
|
|
keypairs \
|
|
|
|
}; \
|
|
|
|
}; \
|
|
|
|
CharShift.setProgmemKeyPairs(kp_table); \
|
|
|
|
CharShift.storage().setKeyPairs(kp_table); \
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Define an `KeyPair` entry in a keymap
|
|
|
|
/// Define an `KeyPair` entry in a keymap
|
|
|
|