From 51b8adfdc6e291cd560b3993bc0b4b9d9a1bbb9a Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sun, 7 Jul 2019 14:10:31 -0700 Subject: [PATCH] Update Turbo plugin for LinearAddressing --- src/kaleidoscope/plugin/Turbo.cpp | 21 ++++++++++----------- src/kaleidoscope/plugin/Turbo.h | 4 ++-- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/kaleidoscope/plugin/Turbo.cpp b/src/kaleidoscope/plugin/Turbo.cpp index cf50f4d8..fd6dde41 100644 --- a/src/kaleidoscope/plugin/Turbo.cpp +++ b/src/kaleidoscope/plugin/Turbo.cpp @@ -30,7 +30,7 @@ cRGB Turbo::activeColor_ = CRGB(160, 0, 0); bool Turbo::enable = false; uint32_t Turbo::startTime = 0; uint32_t Turbo::flashStartTime = 0; -byte Turbo::keyPositions[4]; +KeyAddr Turbo::keyPositions[4]; uint16_t Turbo::numKeys = 0; uint16_t Turbo::interval() { @@ -70,11 +70,10 @@ void Turbo::activeColor(cRGB newVal) { void Turbo::findKeyPositions() { numKeys = 0; - for (byte r = 0; r < ROWS; r++) { - for (byte c = 0; c < COLS; c++) { - if (Layer.lookupOnActiveLayer(r, c) == Key_Turbo) { - keyPositions[numKeys++] = r * COLS + c; - } + + for (auto key_addr : KeyAddr::all()) { + if (Layer.lookupOnActiveLayer(key_addr) == Key_Turbo) { + keyPositions[numKeys++] = key_addr; } } } @@ -89,12 +88,12 @@ EventHandlerResult Turbo::onLayerChange() { return EventHandlerResult::OK; } -EventHandlerResult Turbo::onKeyswitchEvent(Key &key, byte row, byte col, uint8_t key_state) { +EventHandlerResult Turbo::onKeyswitchEvent(Key &key, KeyAddr key_addr, uint8_t key_state) { if (key != Key_Turbo) return EventHandlerResult::OK; enable = sticky_ ? (keyIsPressed(key_state) ? enable : !enable) : keyIsPressed(key_state); if (!enable) { for (uint16_t i = 0; i < numKeys; i++) { - LEDControl::refreshAt(keyPositions[i] / COLS, keyPositions[i] % COLS); + LEDControl::refreshAt(KeyAddr(keyPositions[i])); } } return EventHandlerResult::EVENT_CONSUMED; @@ -110,18 +109,18 @@ EventHandlerResult Turbo::afterEachCycle() { if (flash_) { if (Kaleidoscope.millisAtCycleStart() - flashStartTime > flashInterval_ * 2) { for (uint16_t i = 0; i < numKeys; i++) { - LEDControl::setCrgbAt(keyPositions[i] / COLS, keyPositions[i] % COLS, activeColor_); + LEDControl::setCrgbAt(KeyAddr(keyPositions[i]), activeColor_); } flashStartTime = Kaleidoscope.millisAtCycleStart(); } else if (Kaleidoscope.millisAtCycleStart() - flashStartTime > flashInterval_) { for (uint16_t i = 0; i < numKeys; i++) { - LEDControl::setCrgbAt(keyPositions[i] / COLS, keyPositions[i] % COLS, {0, 0, 0}); + LEDControl::setCrgbAt(KeyAddr(keyPositions[i]), {0, 0, 0}); } } LEDControl::syncLeds(); } else { for (uint16_t i = 0; i < numKeys; i++) { - LEDControl::setCrgbAt(keyPositions[i] / COLS, keyPositions[i] % COLS, activeColor_); + LEDControl::setCrgbAt(KeyAddr(keyPositions[i]), activeColor_); } } } diff --git a/src/kaleidoscope/plugin/Turbo.h b/src/kaleidoscope/plugin/Turbo.h index 0e534d12..a6d2202d 100644 --- a/src/kaleidoscope/plugin/Turbo.h +++ b/src/kaleidoscope/plugin/Turbo.h @@ -44,7 +44,7 @@ class Turbo : public kaleidoscope::Plugin { EventHandlerResult onSetup(); EventHandlerResult onLayerChange(); - EventHandlerResult onKeyswitchEvent(Key &key, byte row, byte col, uint8_t key_state); + EventHandlerResult onKeyswitchEvent(Key &key, KeyAddr key_addr, uint8_t key_state); EventHandlerResult afterEachCycle(); private: void findKeyPositions(); @@ -58,7 +58,7 @@ class Turbo : public kaleidoscope::Plugin { static bool enable; static uint32_t startTime; static uint32_t flashStartTime; - static byte keyPositions[4]; + static KeyAddr keyPositions[4]; static uint16_t numKeys; }; }