commit
3962ffff1a
@ -0,0 +1,97 @@
|
|||||||
|
# Kaleidoscope-Cycle
|
||||||
|
|
||||||
|
If you ever wanted a key that works like keys on old cell phones, when you press
|
||||||
|
a key and it cycles through a number of options in a sequence, then the cycling
|
||||||
|
key is what you are looking for. It is a bit different than on cell phones of
|
||||||
|
old, as it is a separate key, that works in combination of other keys: you press
|
||||||
|
a key, then the cycle key, and the cycle key will replace the previously input
|
||||||
|
symbol with another. Keep tapping the cycle key, and it will replace symbols
|
||||||
|
with new ones, in a loop.
|
||||||
|
|
||||||
|
## Using the plugin
|
||||||
|
|
||||||
|
To use the plugin, we need to include the header, and declare the behaviour
|
||||||
|
used. Then, we need to place a cycle key or two on the keymap. And finally, we
|
||||||
|
need to implement the [`cycleAction`][cycleaction] function that gets called
|
||||||
|
each time the cycling key triggers.
|
||||||
|
|
||||||
|
[cycleaction]: #cycleactionpreviouskey-cyclecount
|
||||||
|
|
||||||
|
```c++
|
||||||
|
#include <Kaleidoscope-Cycle.h>
|
||||||
|
|
||||||
|
// Somewhere in the keymap:
|
||||||
|
Key_Cycle
|
||||||
|
|
||||||
|
// later in the Sketch:
|
||||||
|
void cycleAction(Key previous_key, uint8_t cycle_count) {
|
||||||
|
if (previous_key.raw == Key_A.raw) {
|
||||||
|
cycleThrough (Key_B, Key_C, Key_D);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
KALEIDOSCOPE_INIT_PLUGINS(Cycle);
|
||||||
|
|
||||||
|
void setup(void) {
|
||||||
|
Kaleidoscope.setup();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Keymap markup
|
||||||
|
|
||||||
|
### `Key_Cycle`
|
||||||
|
|
||||||
|
> The key code for the cycle key. There can be as many of this on the keymap, as
|
||||||
|
> many one wants, but they all behave the same. There is little point in having
|
||||||
|
> more than one on each side.
|
||||||
|
|
||||||
|
## Plugin methods
|
||||||
|
|
||||||
|
The plugin provides a `Cycle` object, but to implement the actions, we need to
|
||||||
|
define a function ([`cycleAction`][cycleaction]) outside of the object. A
|
||||||
|
handler, of sorts. The object also provides a helper method to replace the
|
||||||
|
previous symbol with another. The plugin also provides one macro that is
|
||||||
|
particularly useful, and in most cases, should be used over the `.replace()`
|
||||||
|
method explained below.
|
||||||
|
|
||||||
|
### `cycleThrough(keys...)`
|
||||||
|
|
||||||
|
> Cycles through all the possibilities given in `keys` (starting from the
|
||||||
|
> beginning once it reached the end). This should be used from
|
||||||
|
> the [`cycleAction`][cycleaction] function, once it is determined what sequence
|
||||||
|
> to cycle through.
|
||||||
|
>
|
||||||
|
> To make the cycling loop complete, the first element of the `keys` list should
|
||||||
|
> be the one that - when followed by the Cycle key - triggers the action.
|
||||||
|
|
||||||
|
### `.replace(key)`
|
||||||
|
|
||||||
|
> Deletes the previous symbol (by sending a `Backspace`), and inputs the new
|
||||||
|
> one. This is used by `cycleThrough()` above, behind the scenes.
|
||||||
|
>
|
||||||
|
> The recommended method is to use the macro, but in special circumstances, this
|
||||||
|
> function can be of direct use as well.
|
||||||
|
|
||||||
|
## Overrideable methods
|
||||||
|
|
||||||
|
### `cycleAction(previous_key, cycle_count)`
|
||||||
|
|
||||||
|
> The heart and soul of the plugin, that must be defined in the Sketch. It will
|
||||||
|
> be called whenever the cycling key triggers, and the two arguments are the
|
||||||
|
> last key pressed (not counting repeated taps of the cycling key itself), and
|
||||||
|
> the number of times the cycling key has been pressed.
|
||||||
|
>
|
||||||
|
> It is up to us to decide what to do, and when. But the most common - and
|
||||||
|
> expected - action is to call `cycleThrough()` with a different sequence for
|
||||||
|
> each key we want to use together with the cycling key.
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
* [Kaleidoscope-Ranges](Ranges.md)
|
||||||
|
|
||||||
|
## Further reading
|
||||||
|
|
||||||
|
Starting from the [example][plugin:example] is the recommended way of getting
|
||||||
|
started with the plugin.
|
||||||
|
|
||||||
|
[plugin:example]: ../../examples/Cycle/Cycle.ino
|
@ -0,0 +1,61 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Kaleidoscope-Cycle -- Key sequence cycling dead key for Kaleidoscope.
|
||||||
|
* Copyright (C) 2016, 2017, 2018 Keyboard.io, Inc
|
||||||
|
*
|
||||||
|
* 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 the Free Software
|
||||||
|
* Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Kaleidoscope.h>
|
||||||
|
#include <Kaleidoscope-Cycle.h>
|
||||||
|
|
||||||
|
const Key keymaps[][ROWS][COLS] PROGMEM = {
|
||||||
|
[0] = KEYMAP_STACKED
|
||||||
|
(Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey,
|
||||||
|
Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab,
|
||||||
|
Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G,
|
||||||
|
Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
|
||||||
|
|
||||||
|
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
|
||||||
|
Key_Cycle,
|
||||||
|
|
||||||
|
Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip,
|
||||||
|
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals,
|
||||||
|
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
|
||||||
|
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
|
||||||
|
|
||||||
|
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
|
||||||
|
Key_Cycle),
|
||||||
|
};
|
||||||
|
|
||||||
|
void cycleAction(Key previous_key, uint8_t cycle_count) {
|
||||||
|
if (previous_key.raw == Key_E.raw) {
|
||||||
|
if (cycle_count == 1) {
|
||||||
|
Cycle.replace(Key_F);
|
||||||
|
} else if (cycle_count == 2) {
|
||||||
|
Cycle.replace(Key_G);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (previous_key.raw == Key_A.raw) {
|
||||||
|
cycleThrough(Key_A, Key_B, Key_C, Key_D);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
KALEIDOSCOPE_INIT_PLUGINS(Cycle);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Kaleidoscope.setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
Kaleidoscope.loop();
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Kaleidoscope-Cycle -- Key sequence cycling dead key for Kaleidoscope.
|
||||||
|
* Copyright (C) 2016, 2017 Keyboard.io, Inc
|
||||||
|
*
|
||||||
|
* 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 the Free Software
|
||||||
|
* Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <kaleidoscope/plugin/Cycle.h>
|
@ -0,0 +1,91 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Kaleidoscope-Cycle -- Key sequence cycling dead key for Kaleidoscope.
|
||||||
|
* Copyright (C) 2016, 2017, 2018 Keyboard.io, Inc
|
||||||
|
*
|
||||||
|
* 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 the Free Software
|
||||||
|
* Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Kaleidoscope.h>
|
||||||
|
#include <Kaleidoscope-Cycle.h>
|
||||||
|
#include "kaleidoscope/hid.h"
|
||||||
|
|
||||||
|
namespace kaleidoscope {
|
||||||
|
namespace plugin {
|
||||||
|
// --- state ---
|
||||||
|
Key Cycle::last_non_cycle_key_;
|
||||||
|
uint8_t Cycle::cycle_count_;
|
||||||
|
|
||||||
|
// --- helpers ---
|
||||||
|
|
||||||
|
#define isCycle(k) (k.raw == kaleidoscope::ranges::CYCLE)
|
||||||
|
|
||||||
|
// --- api ---
|
||||||
|
|
||||||
|
void Cycle::replace(Key key) {
|
||||||
|
handleKeyswitchEvent(Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
|
||||||
|
hid::sendKeyboardReport();
|
||||||
|
handleKeyswitchEvent(Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED);
|
||||||
|
hid::sendKeyboardReport();
|
||||||
|
|
||||||
|
handleKeyswitchEvent(key, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
|
||||||
|
hid::sendKeyboardReport();
|
||||||
|
handleKeyswitchEvent(key, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED);
|
||||||
|
hid::sendKeyboardReport();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Cycle::replace(uint8_t cycle_size, const Key cycle_steps[]) {
|
||||||
|
uint8_t idx = cycle_count_ % cycle_size;
|
||||||
|
Key key;
|
||||||
|
|
||||||
|
key.raw = pgm_read_word(cycle_steps + idx);
|
||||||
|
replace(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- hooks ---
|
||||||
|
|
||||||
|
EventHandlerResult Cycle::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state) {
|
||||||
|
if (key_state & INJECTED)
|
||||||
|
return EventHandlerResult::OK;
|
||||||
|
|
||||||
|
if (!keyIsPressed(key_state) && !keyWasPressed(key_state)) {
|
||||||
|
if (isCycle(mapped_key)) {
|
||||||
|
return EventHandlerResult::EVENT_CONSUMED;
|
||||||
|
}
|
||||||
|
return EventHandlerResult::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isCycle(mapped_key)) {
|
||||||
|
if (keyToggledOn(key_state)) {
|
||||||
|
last_non_cycle_key_.raw = mapped_key.raw;
|
||||||
|
cycle_count_ = 0;
|
||||||
|
}
|
||||||
|
return EventHandlerResult::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!keyToggledOff(key_state)) {
|
||||||
|
return EventHandlerResult::EVENT_CONSUMED;
|
||||||
|
}
|
||||||
|
|
||||||
|
++cycle_count_;
|
||||||
|
cycleAction(last_non_cycle_key_, cycle_count_);
|
||||||
|
return EventHandlerResult::EVENT_CONSUMED;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((weak))
|
||||||
|
void cycleAction(Key previous_key, uint8_t cycle_count) {
|
||||||
|
}
|
||||||
|
|
||||||
|
kaleidoscope::plugin::Cycle Cycle;
|
@ -0,0 +1,50 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Kaleidoscope-Cycle -- Key sequence cycling dead key for Kaleidoscope.
|
||||||
|
* Copyright (C) 2016, 2017, 2018 Keyboard.io, Inc
|
||||||
|
*
|
||||||
|
* 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 the Free Software
|
||||||
|
* Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Kaleidoscope.h>
|
||||||
|
#include <Kaleidoscope-Ranges.h>
|
||||||
|
|
||||||
|
#define Key_Cycle ((Key) { .raw = kaleidoscope::ranges::CYCLE })
|
||||||
|
|
||||||
|
#define cycleThrough(...) ({ \
|
||||||
|
static const Key __k[] PROGMEM = { __VA_ARGS__ }; \
|
||||||
|
Cycle.replace(sizeof(__k) / sizeof(Key), &__k[0]); \
|
||||||
|
})
|
||||||
|
|
||||||
|
namespace kaleidoscope {
|
||||||
|
namespace plugin {
|
||||||
|
class Cycle : public kaleidoscope::Plugin {
|
||||||
|
public:
|
||||||
|
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);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static Key last_non_cycle_key_;
|
||||||
|
static uint8_t cycle_count_;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cycleAction(Key previous_key, uint8_t cycle_count);
|
||||||
|
|
||||||
|
extern kaleidoscope::plugin::Cycle Cycle;
|
Loading…
Reference in new issue