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... // Place Key_Redial somewhere on the keymap...
void setup() { KALEIDOSCOPE_INIT_PLUGINS(Redial);
Kaleidoscope.use(&Redial);
Redial.key = Key_Redial;
void setup() {
Kaleidoscope.setup(); Kaleidoscope.setup();
Redial.key = Key_Redial;
} }
``` ```

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

@ -23,23 +23,20 @@ namespace kaleidoscope {
Key Redial::key; Key Redial::key;
Key Redial::key_to_redial_; 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) if (key == Key_NoKey)
return mapped_key; return EventHandlerResult::OK;
if (mapped_key == key) { if (mapped_key == key) {
return key_to_redial_; mapped_key = key_to_redial_;
return EventHandlerResult::OK;
} }
if (keyToggledOn(key_state) && shouldRemember(mapped_key)) { if (keyToggledOn(key_state) && shouldRemember(mapped_key)) {
key_to_redial_ = mapped_key; key_to_redial_ = mapped_key;
} }
return mapped_key; return EventHandlerResult::OK;
}
void Redial::begin(void) {
Kaleidoscope.useEventHandlerHook(eventHandlerHook_);
} }
__attribute__((weak)) bool Redial::shouldRemember(Key mapped_key) { __attribute__((weak)) bool Redial::shouldRemember(Key mapped_key) {
@ -51,6 +48,20 @@ __attribute__((weak)) bool Redial::shouldRemember(Key mapped_key) {
return false; 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; kaleidoscope::Redial Redial;

@ -24,18 +24,22 @@ namespace kaleidoscope {
class Redial : public KaleidoscopePlugin { class Redial : public KaleidoscopePlugin {
public: public:
Redial(void) {}; Redial(void) {}
void begin(void) final;
static Key key; static Key key;
static bool shouldRemember(Key mappedKey); 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: private:
static Key key_to_redial_; static Key key_to_redial_;
static Key eventHandlerHook_(Key mapped_key, byte row, byte col, uint8_t key_state);
}; };
} }

Loading…
Cancel
Save