From b3e1f73546f6f060badf8f6f82c41e14936bb1c1 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Fri, 18 Aug 2017 09:51:35 +0200 Subject: [PATCH] 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 --- README.md | 9 +++++++++ src/Kaleidoscope/LED-ActiveModColor.cpp | 4 ++++ src/Kaleidoscope/LED-ActiveModColor.h | 1 + 3 files changed, 14 insertions(+) diff --git a/README.md b/README.md index 3f8b7512..9e2a71c5 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/src/Kaleidoscope/LED-ActiveModColor.cpp b/src/Kaleidoscope/LED-ActiveModColor.cpp index e47d16c5..25bb39df 100644 --- a/src/Kaleidoscope/LED-ActiveModColor.cpp +++ b/src/Kaleidoscope/LED-ActiveModColor.cpp @@ -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); diff --git a/src/Kaleidoscope/LED-ActiveModColor.h b/src/Kaleidoscope/LED-ActiveModColor.h index 2d0a05b6..82a880de 100644 --- a/src/Kaleidoscope/LED-ActiveModColor.h +++ b/src/Kaleidoscope/LED-ActiveModColor.h @@ -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);