Updated to use the new plugin APIs

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/389/head
Gergely Nagy 7 years ago
parent 93d7d7bacf
commit 6d13e82366

@ -31,11 +31,12 @@ enum {
// Place Key_Redial somewhere on the keymap...
void setup() {
Kaleidoscope.use(&Redial);
Redial.key = Key_Redial;
KALEIDOSCOPE_INIT_PLUGINS(Redial);
void setup() {
Kaleidoscope.setup();
Redial.key = Key_Redial;
}
```

@ -53,11 +53,12 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
};
// *INDENT-ON*
void setup() {
Kaleidoscope.use(&Redial);
Redial.key = Key_Redial;
KALEIDOSCOPE_INIT_PLUGINS(Redial);
void setup() {
Kaleidoscope.setup();
Redial.key = Key_Redial;
}
void loop() {

@ -23,23 +23,20 @@ namespace kaleidoscope {
Key Redial::key;
Key Redial::key_to_redial_;
Key Redial::eventHandlerHook_(Key mapped_key, byte row, byte col, uint8_t key_state) {
EventHandlerResult Redial::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state) {
if (key == Key_NoKey)
return mapped_key;
return EventHandlerResult::OK;
if (mapped_key == key) {
return key_to_redial_;
mapped_key = key_to_redial_;
return EventHandlerResult::OK;
}
if (keyToggledOn(key_state) && shouldRemember(mapped_key)) {
key_to_redial_ = mapped_key;
}
return mapped_key;
}
void Redial::begin(void) {
Kaleidoscope.useEventHandlerHook(eventHandlerHook_);
return EventHandlerResult::OK;
}
__attribute__((weak)) bool Redial::shouldRemember(Key mapped_key) {
@ -51,6 +48,20 @@ __attribute__((weak)) bool Redial::shouldRemember(Key mapped_key) {
return false;
}
// Legacy V1 API
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void Redial::begin() {
Kaleidoscope.useEventHandlerHook(legacyEventHandler);
}
Key Redial::legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state) {
EventHandlerResult r = ::Redial.onKeyswitchEvent(mapped_key, row, col, key_state);
if (r == EventHandlerResult::OK)
return mapped_key;
return Key_NoKey;
}
#endif
}
kaleidoscope::Redial Redial;

@ -24,18 +24,22 @@ namespace kaleidoscope {
class Redial : public KaleidoscopePlugin {
public:
Redial(void) {};
void begin(void) final;
Redial(void) {}
static Key key;
static bool shouldRemember(Key mappedKey);
EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state);
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
protected:
void begin();
static Key legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state);
#endif
private:
static Key key_to_redial_;
static Key eventHandlerHook_(Key mapped_key, byte row, byte col, uint8_t key_state);
};
}

Loading…
Cancel
Save