Merge pull request #1 from keyboardio/f/plugin-v2

Updated to use the new plugin APIs
pull/389/head
Gergely Nagy 7 years ago committed by GitHub
commit 2021f527e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -39,9 +39,9 @@ void cycleAction(Key previous_key, uint8_t cycle_count) {
} }
} }
void setup(void) { KALEIDOSCOPE_INIT_PLUGINS(Cycle);
Kaleidoscope.use(&Cycle);
void setup(void) {
Kaleidoscope.setup(); Kaleidoscope.setup();
} }
``` ```

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-Cycle -- Key sequence cycling dead key for Kaleidoscope. * Kaleidoscope-Cycle -- Key sequence cycling dead key for Kaleidoscope.
* Copyright (C) 2016, 2017 Gergely Nagy * Copyright (C) 2016, 2017, 2018 Gergely Nagy
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -51,9 +51,9 @@ void cycleAction(Key previous_key, uint8_t cycle_count) {
} }
} }
void setup() { KALEIDOSCOPE_INIT_PLUGINS(Cycle);
Kaleidoscope.use(&Cycle);
void setup() {
Kaleidoscope.setup(); Kaleidoscope.setup();
} }

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-Cycle -- Key sequence cycling dead key for Kaleidoscope. * Kaleidoscope-Cycle -- Key sequence cycling dead key for Kaleidoscope.
* Copyright (C) 2016, 2017 Gergely Nagy * Copyright (C) 2016, 2017, 2018 Gergely Nagy
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -31,13 +31,6 @@ uint8_t Cycle::cycle_count_;
// --- api --- // --- api ---
Cycle::Cycle(void) {
}
void Cycle::begin(void) {
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
}
void Cycle::replace(Key key) { void Cycle::replace(Key key) {
handleKeyswitchEvent(Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED); handleKeyswitchEvent(Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
hid::sendKeyboardReport(); hid::sendKeyboardReport();
@ -60,14 +53,15 @@ void Cycle::replace(uint8_t cycle_size, const Key cycle_steps[]) {
// --- hooks --- // --- hooks ---
Key Cycle::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) { EventHandlerResult Cycle::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state) {
if (key_state & INJECTED) if (key_state & INJECTED)
return mapped_key; return EventHandlerResult::OK;
if (!keyIsPressed(key_state) && !keyWasPressed(key_state)) { if (!keyIsPressed(key_state) && !keyWasPressed(key_state)) {
if (isCycle(mapped_key)) if (isCycle(mapped_key)) {
return Key_NoKey; return EventHandlerResult::EVENT_CONSUMED;
return mapped_key; }
return EventHandlerResult::OK;
} }
if (!isCycle(mapped_key)) { if (!isCycle(mapped_key)) {
@ -75,16 +69,32 @@ Key Cycle::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_stat
last_non_cycle_key_.raw = mapped_key.raw; last_non_cycle_key_.raw = mapped_key.raw;
cycle_count_ = 0; cycle_count_ = 0;
} }
return mapped_key; return EventHandlerResult::OK;
} }
if (!keyToggledOff(key_state)) if (!keyToggledOff(key_state)) {
return Key_NoKey; return EventHandlerResult::EVENT_CONSUMED;
}
++cycle_count_; ++cycle_count_;
cycleAction(last_non_cycle_key_, cycle_count_); cycleAction(last_non_cycle_key_, cycle_count_);
return EventHandlerResult::EVENT_CONSUMED;
}
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
// Deprecated v1 API
void Cycle::begin() {
Kaleidoscope.useEventHandlerHook(legacyEventHandler);
}
Key Cycle::legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state) {
EventHandlerResult r = ::Cycle.onKeyswitchEvent(mapped_key, row, col, key_state);
if (r == EventHandlerResult::OK)
return mapped_key;
return Key_NoKey; return Key_NoKey;
} }
#endif
}; };
__attribute__((weak)) __attribute__((weak))

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-Cycle -- Key sequence cycling dead key for Kaleidoscope. * Kaleidoscope-Cycle -- Key sequence cycling dead key for Kaleidoscope.
* Copyright (C) 2016, 2017 Gergely Nagy * Copyright (C) 2016, 2017, 2018 Gergely Nagy
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -29,20 +29,24 @@
}) })
namespace kaleidoscope { namespace kaleidoscope {
class Cycle : public KaleidoscopePlugin { class Cycle : public kaleidoscope::Plugin {
public: public:
Cycle(void); Cycle(void) {}
void begin(void) final;
static void replace(Key key); static void replace(Key key);
static void replace(uint8_t cycle_size, const Key cycle_steps[]); static void replace(uint8_t cycle_size, const Key cycle_steps[]);
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 last_non_cycle_key_; static Key last_non_cycle_key_;
static uint8_t cycle_count_; static uint8_t cycle_count_;
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
}; };
}; };

Loading…
Cancel
Save