Updated to use the new plugin APIs

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/389/head
Gergely Nagy 7 years ago
parent 8431bed1ed
commit 191ecdb000

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

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* 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
* 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.use(&Cycle);
KALEIDOSCOPE_INIT_PLUGINS(Cycle);
void setup() {
Kaleidoscope.setup();
}

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* 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
* it under the terms of the GNU General Public License as published by
@ -31,13 +31,6 @@ uint8_t Cycle::cycle_count_;
// --- api ---
Cycle::Cycle(void) {
}
void Cycle::begin(void) {
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
}
void Cycle::replace(Key key) {
handleKeyswitchEvent(Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
hid::sendKeyboardReport();
@ -60,14 +53,15 @@ void Cycle::replace(uint8_t cycle_size, const Key cycle_steps[]) {
// --- 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)
return mapped_key;
return EventHandlerResult::OK;
if (!keyIsPressed(key_state) && !keyWasPressed(key_state)) {
if (isCycle(mapped_key))
return Key_NoKey;
return mapped_key;
if (isCycle(mapped_key)) {
return EventHandlerResult::EVENT_CONSUMED;
}
return EventHandlerResult::OK;
}
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;
cycle_count_ = 0;
}
return mapped_key;
return EventHandlerResult::OK;
}
if (!keyToggledOff(key_state))
return Key_NoKey;
if (!keyToggledOff(key_state)) {
return EventHandlerResult::EVENT_CONSUMED;
}
++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;
}
#endif
};
__attribute__((weak))

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* 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
* it under the terms of the GNU General Public License as published by
@ -29,20 +29,24 @@
})
namespace kaleidoscope {
class Cycle : public KaleidoscopePlugin {
class Cycle : public kaleidoscope::Plugin {
public:
Cycle(void);
void begin(void) final;
Cycle(void) {}
static void replace(Key key);
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:
static Key last_non_cycle_key_;
static uint8_t cycle_count_;
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
};
};

Loading…
Cancel
Save