Add a way to optimize for a one-shot-only setup.

OneShot has a convenient way to tell us if any OneShot keys are active:
`OneShot.isActive()`. Thus, if we are using oneshots only, we can skip scanning
the whole keymap if no one-shots are active, saving us a whole lot of time per
cycle we would be spending needlessly.

The optimization is off by default, and must be turned on by the user's sketch.

Signed-off-by: Gergely Nagy <kaleidoscope@gergo.csillger.hu>
pull/389/head
Gergely Nagy 7 years ago
parent 2765bca10b
commit b3e1f73546

@ -46,6 +46,15 @@ property:
> The color to use for highlighting the modifiers. Defaults to a white color.
### `.oneshot_only`
> A flag one can set to tell the plugin that they are using one-shot modifiers
> and layers only. This allows it to take some shortcuts, and optimize
> performance, at the cost of not highlighting any non-oneshot keys it otherwise
> would.
>
> Defaults to `false`.
## Dependencies
* [Kaleidoscope-LEDControl](https://github.com/keyboardio/Kaleidoscope-LEDControl)

@ -25,6 +25,7 @@ namespace kaleidoscope {
cRGB ActiveModColorEffect::highlight_color = (cRGB) {
0xff, 0xff, 0xff
};
bool ActiveModColorEffect::oneshot_only;
void ActiveModColorEffect::begin(void) {
Kaleidoscope.useLoopHook(loopHook);
@ -34,6 +35,9 @@ void ActiveModColorEffect::loopHook(bool is_post_clear) {
if (is_post_clear)
return;
if (oneshot_only && !::OneShot.isActive())
return;
for (byte r = 0; r < ROWS; r++) {
for (byte c = 0; c < COLS; c++) {
Key k = Layer.lookupOnActiveLayer(r, c);

@ -29,6 +29,7 @@ class ActiveModColorEffect : public KaleidoscopePlugin {
void begin(void) final;
static cRGB highlight_color;
static bool oneshot_only;
private:
static void loopHook(bool is_post_clear);

Loading…
Cancel
Save