Update Turbo plugin for LinearAddressing

pull/640/head
Jesse Vincent 6 years ago
parent 617dca07dd
commit 51b8adfdc6

@ -30,7 +30,7 @@ cRGB Turbo::activeColor_ = CRGB(160, 0, 0);
bool Turbo::enable = false; bool Turbo::enable = false;
uint32_t Turbo::startTime = 0; uint32_t Turbo::startTime = 0;
uint32_t Turbo::flashStartTime = 0; uint32_t Turbo::flashStartTime = 0;
byte Turbo::keyPositions[4]; KeyAddr Turbo::keyPositions[4];
uint16_t Turbo::numKeys = 0; uint16_t Turbo::numKeys = 0;
uint16_t Turbo::interval() { uint16_t Turbo::interval() {
@ -70,11 +70,10 @@ void Turbo::activeColor(cRGB newVal) {
void Turbo::findKeyPositions() { void Turbo::findKeyPositions() {
numKeys = 0; numKeys = 0;
for (byte r = 0; r < ROWS; r++) {
for (byte c = 0; c < COLS; c++) { for (auto key_addr : KeyAddr::all()) {
if (Layer.lookupOnActiveLayer(r, c) == Key_Turbo) { if (Layer.lookupOnActiveLayer(key_addr) == Key_Turbo) {
keyPositions[numKeys++] = r * COLS + c; keyPositions[numKeys++] = key_addr;
}
} }
} }
} }
@ -89,12 +88,12 @@ EventHandlerResult Turbo::onLayerChange() {
return EventHandlerResult::OK; 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; if (key != Key_Turbo) return EventHandlerResult::OK;
enable = sticky_ ? (keyIsPressed(key_state) ? enable : !enable) : keyIsPressed(key_state); enable = sticky_ ? (keyIsPressed(key_state) ? enable : !enable) : keyIsPressed(key_state);
if (!enable) { if (!enable) {
for (uint16_t i = 0; i < numKeys; i++) { 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; return EventHandlerResult::EVENT_CONSUMED;
@ -110,18 +109,18 @@ EventHandlerResult Turbo::afterEachCycle() {
if (flash_) { if (flash_) {
if (Kaleidoscope.millisAtCycleStart() - flashStartTime > flashInterval_ * 2) { if (Kaleidoscope.millisAtCycleStart() - flashStartTime > flashInterval_ * 2) {
for (uint16_t i = 0; i < numKeys; i++) { 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(); flashStartTime = Kaleidoscope.millisAtCycleStart();
} else if (Kaleidoscope.millisAtCycleStart() - flashStartTime > flashInterval_) { } else if (Kaleidoscope.millisAtCycleStart() - flashStartTime > flashInterval_) {
for (uint16_t i = 0; i < numKeys; i++) { 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(); LEDControl::syncLeds();
} else { } else {
for (uint16_t i = 0; i < numKeys; i++) { for (uint16_t i = 0; i < numKeys; i++) {
LEDControl::setCrgbAt(keyPositions[i] / COLS, keyPositions[i] % COLS, activeColor_); LEDControl::setCrgbAt(KeyAddr(keyPositions[i]), activeColor_);
} }
} }
} }

@ -44,7 +44,7 @@ class Turbo : public kaleidoscope::Plugin {
EventHandlerResult onSetup(); EventHandlerResult onSetup();
EventHandlerResult onLayerChange(); 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(); EventHandlerResult afterEachCycle();
private: private:
void findKeyPositions(); void findKeyPositions();
@ -58,7 +58,7 @@ class Turbo : public kaleidoscope::Plugin {
static bool enable; static bool enable;
static uint32_t startTime; static uint32_t startTime;
static uint32_t flashStartTime; static uint32_t flashStartTime;
static byte keyPositions[4]; static KeyAddr keyPositions[4];
static uint16_t numKeys; static uint16_t numKeys;
}; };
} }

Loading…
Cancel
Save