|
|
|
/* -*- mode: c++ -*-
|
|
|
|
* Kaleidoscope-LED-ActiveModColor -- Light up the LEDs under the active modifiers
|
|
|
|
* 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-LED-ActiveModColor.h>
|
|
|
|
#include <Kaleidoscope-OneShot.h>
|
|
|
|
#include <kaleidoscope/hid.h>
|
|
|
|
|
|
|
|
namespace kaleidoscope {
|
|
|
|
namespace plugin {
|
|
|
|
|
ActiveModColor: Improve latency by caching interesting keys on layer change
Keys normally only change when switching layers, so instead of going through
every key in every cycle to look for modifiers, do that once, when layers
change (using the new `onLayerChange` event), and store the coordinates of keys
we consider modifiers in an array (currently limited to 16 items).
Then, when we want to highlight them, go over this array only, significantly
reducing the work we need to do. In a typical case, on a full-size keyboard, one
would have eight modifiers and a few layer keys, so instead of going through a
hundred keys, we go through sixteen at most, but usually considerably less.
This fixes #403, at the cost of noticeably higher PROGMEM and RAM use.
Signed-off-by: Gergely Nagy <algernon@keyboard.io>
6 years ago
|
|
|
uint8_t ActiveModColorEffect::mod_keys_[MAX_MODS_PER_LAYER];
|
|
|
|
uint8_t ActiveModColorEffect::mod_key_count_;
|
|
|
|
|
|
|
|
cRGB ActiveModColorEffect::highlight_color = (cRGB) {
|
|
|
|
0xff, 0xff, 0xff
|
|
|
|
};
|
|
|
|
|
|
|
|
cRGB ActiveModColorEffect::sticky_color = CRGB(0xff, 0x00, 0x00);
|
|
|
|
|
ActiveModColor: Improve latency by caching interesting keys on layer change
Keys normally only change when switching layers, so instead of going through
every key in every cycle to look for modifiers, do that once, when layers
change (using the new `onLayerChange` event), and store the coordinates of keys
we consider modifiers in an array (currently limited to 16 items).
Then, when we want to highlight them, go over this array only, significantly
reducing the work we need to do. In a typical case, on a full-size keyboard, one
would have eight modifiers and a few layer keys, so instead of going through a
hundred keys, we go through sixteen at most, but usually considerably less.
This fixes #403, at the cost of noticeably higher PROGMEM and RAM use.
Signed-off-by: Gergely Nagy <algernon@keyboard.io>
6 years ago
|
|
|
EventHandlerResult ActiveModColorEffect::onLayerChange() {
|
|
|
|
if (!Kaleidoscope.has_leds)
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
|
ActiveModColor: Improve latency by caching interesting keys on layer change
Keys normally only change when switching layers, so instead of going through
every key in every cycle to look for modifiers, do that once, when layers
change (using the new `onLayerChange` event), and store the coordinates of keys
we consider modifiers in an array (currently limited to 16 items).
Then, when we want to highlight them, go over this array only, significantly
reducing the work we need to do. In a typical case, on a full-size keyboard, one
would have eight modifiers and a few layer keys, so instead of going through a
hundred keys, we go through sixteen at most, but usually considerably less.
This fixes #403, at the cost of noticeably higher PROGMEM and RAM use.
Signed-off-by: Gergely Nagy <algernon@keyboard.io>
6 years ago
|
|
|
mod_key_count_ = 0;
|
|
|
|
|
|
|
|
for (byte r = 0; r < ROWS; r++) {
|
|
|
|
for (byte c = 0; c < COLS; c++) {
|
ActiveModColor: Improve latency by caching interesting keys on layer change
Keys normally only change when switching layers, so instead of going through
every key in every cycle to look for modifiers, do that once, when layers
change (using the new `onLayerChange` event), and store the coordinates of keys
we consider modifiers in an array (currently limited to 16 items).
Then, when we want to highlight them, go over this array only, significantly
reducing the work we need to do. In a typical case, on a full-size keyboard, one
would have eight modifiers and a few layer keys, so instead of going through a
hundred keys, we go through sixteen at most, but usually considerably less.
This fixes #403, at the cost of noticeably higher PROGMEM and RAM use.
Signed-off-by: Gergely Nagy <algernon@keyboard.io>
6 years ago
|
|
|
Key k = Layer.lookup(r, c);
|
|
|
|
|
|
|
|
if (::OneShot.isOneShotKey(k) ||
|
|
|
|
(k.raw >= Key_LeftControl.raw && k.raw <= Key_RightGui.raw) ||
|
|
|
|
(k.flags == (SYNTHETIC | SWITCH_TO_KEYMAP))) {
|
|
|
|
uint8_t coords = r * COLS + c;
|
|
|
|
mod_keys_[mod_key_count_++] = coords;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
}
|
|
|
|
|
ActiveModColor: Improve latency by caching interesting keys on layer change
Keys normally only change when switching layers, so instead of going through
every key in every cycle to look for modifiers, do that once, when layers
change (using the new `onLayerChange` event), and store the coordinates of keys
we consider modifiers in an array (currently limited to 16 items).
Then, when we want to highlight them, go over this array only, significantly
reducing the work we need to do. In a typical case, on a full-size keyboard, one
would have eight modifiers and a few layer keys, so instead of going through a
hundred keys, we go through sixteen at most, but usually considerably less.
This fixes #403, at the cost of noticeably higher PROGMEM and RAM use.
Signed-off-by: Gergely Nagy <algernon@keyboard.io>
6 years ago
|
|
|
EventHandlerResult ActiveModColorEffect::beforeReportingState() {
|
|
|
|
for (uint8_t i = 0; i < mod_key_count_; i++) {
|
|
|
|
uint8_t coords = mod_keys_[i];
|
|
|
|
byte c = coords % COLS;
|
|
|
|
byte r = (coords - c) / COLS;
|
|
|
|
|
|
|
|
Key k = Layer.lookup(r, c);
|
|
|
|
|
|
|
|
if (::OneShot.isOneShotKey(k)) {
|
|
|
|
if (::OneShot.isSticky(k))
|
|
|
|
::LEDControl.setCrgbAt(r, c, sticky_color);
|
|
|
|
else if (::OneShot.isActive(k))
|
|
|
|
::LEDControl.setCrgbAt(r, c, highlight_color);
|
|
|
|
else
|
|
|
|
::LEDControl.refreshAt(r, c);
|
|
|
|
} else if (k.raw >= Key_LeftControl.raw && k.raw <= Key_RightGui.raw) {
|
|
|
|
if (hid::isModifierKeyActive(k))
|
|
|
|
::LEDControl.setCrgbAt(r, c, highlight_color);
|
|
|
|
else
|
|
|
|
::LEDControl.refreshAt(r, c);
|
|
|
|
} else if (k.flags == (SYNTHETIC | SWITCH_TO_KEYMAP)) {
|
|
|
|
uint8_t layer = k.keyCode;
|
|
|
|
if (layer >= LAYER_SHIFT_OFFSET)
|
|
|
|
layer -= LAYER_SHIFT_OFFSET;
|
|
|
|
|
|
|
|
if (Layer.isOn(layer))
|
|
|
|
::LEDControl.setCrgbAt(r, c, highlight_color);
|
|
|
|
else
|
|
|
|
::LEDControl.refreshAt(r, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
kaleidoscope::plugin::ActiveModColorEffect ActiveModColorEffect;
|