diff --git a/src/kaleidoscope/plugin/LED-AlphaSquare.cpp b/src/kaleidoscope/plugin/LED-AlphaSquare.cpp index 261d3e01..30ee3249 100644 --- a/src/kaleidoscope/plugin/LED-AlphaSquare.cpp +++ b/src/kaleidoscope/plugin/LED-AlphaSquare.cpp @@ -101,6 +101,40 @@ void AlphaSquare::display(uint16_t symbol, uint8_t row, uint8_t col) { display(symbol, row, col, color); } +bool AlphaSquare::isSymbolPart(Key key, + uint8_t display_row, uint8_t display_col, + uint8_t row, uint8_t col) { + if (!Kaleidoscope.has_leds) + return false; + + if (key < Key_A || key > Key_0) + return false; + + uint8_t index = key.keyCode - Key_A.keyCode; + uint16_t symbol = pgm_read_word(&alphabet[index]); + + return isSymbolPart(symbol, display_row, display_col, row, col); +} + +bool AlphaSquare::isSymbolPart(uint16_t symbol, + uint8_t display_row, uint8_t display_col, + uint8_t row, uint8_t col) { + if (!Kaleidoscope.has_leds) + return false; + + for (uint8_t r = 0; r < 4; r++) { + for (uint8_t c = 0; c < 4; c++) { + uint8_t pixel = bitRead(symbol, r * 4 + c); + + if (display_row + r == row && + display_col + c == col) + return !!pixel; + } + } + + return false; +} + } } diff --git a/src/kaleidoscope/plugin/LED-AlphaSquare.h b/src/kaleidoscope/plugin/LED-AlphaSquare.h index 296a7ca7..2c8525af 100644 --- a/src/kaleidoscope/plugin/LED-AlphaSquare.h +++ b/src/kaleidoscope/plugin/LED-AlphaSquare.h @@ -75,6 +75,13 @@ class AlphaSquare : public kaleidoscope::Plugin { clear(symbol, 0, 2); } + static bool isSymbolPart(Key key, + uint8_t display_row, uint8_t display_col, + uint8_t row, uint8_t col); + static bool isSymbolPart(uint16_t symbol, + uint8_t display_row, uint8_t display_col, + uint8_t row, uint8_t col); + static cRGB color; }; diff --git a/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.cpp b/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.cpp index bf9400d6..692a7151 100644 --- a/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.cpp +++ b/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.cpp @@ -38,6 +38,23 @@ void AlphaSquareEffect::update(void) { } } +void AlphaSquareEffect::refreshAt(byte row, byte col) { + bool timed_out; + uint8_t display_col = 2; + Key key = last_key_left_; + + if (col < COLS / 2) { + timed_out = !end_time_left_ || (end_time_left_ && millis() > end_time_left_); + } else { + key = last_key_right_; + display_col = 10; + timed_out = !end_time_right_ || (end_time_right_ && millis() > end_time_right_); + } + + if (!::AlphaSquare.isSymbolPart(key, 0, display_col, row, col) || timed_out) + ::LEDControl.setCrgbAt(row, col, CRGB(0, 0, 0)); +} + EventHandlerResult AlphaSquareEffect::onKeyswitchEvent(Key &mappedKey, byte row, byte col, uint8_t keyState) { if (!Kaleidoscope.has_leds) return EventHandlerResult::OK; diff --git a/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.h b/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.h index 3227afdf..43579e6b 100644 --- a/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.h +++ b/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.h @@ -32,6 +32,7 @@ class AlphaSquareEffect : public LEDMode { protected: void update(void) final; + void refreshAt(byte row, byte col) final; private: static uint32_t end_time_left_, end_time_right_;