diff --git a/docs/firmware-1.3.0.bin b/docs/firmware-1.3.0.bin index 7773cf1d0a..229a399cf0 100644 Binary files a/docs/firmware-1.3.0.bin and b/docs/firmware-1.3.0.bin differ diff --git a/wled00/7segmdisp.cpp b/wled00/7segmdisp.cpp index 4cd184b284..b4cd59407d 100644 --- a/wled00/7segmdisp.cpp +++ b/wled00/7segmdisp.cpp @@ -24,8 +24,10 @@ void LedBasedDisplay::setColor(bool state, CRGB color) { SevenSegmentDisplay::SevenSegmentDisplay(LedBasedDisplayOutput output, uint8_t ledsPerSegment): _output(output), + _backgroundColor(CRGB::Black), _ledsPerSegment(ledsPerSegment), _value(_7SEG_SYM_EMPTY), + _paintBackground(false), _mode(LedBasedDisplayMode::SET_ALL_LEDS) { _offColors = (CRGB*) malloc(7 * _ledsPerSegment * sizeof(CRGB)); @@ -47,6 +49,14 @@ uint8_t SevenSegmentDisplay::columnCount() { return _ledsPerSegment + 2; } +CRGB SevenSegmentDisplay::getBackgroundColor() { + return _backgroundColor; +} + +void SevenSegmentDisplay::setBackgroundColor(CRGB color) { + _backgroundColor = color; +} + CRGB* SevenSegmentDisplay::getLedColor(uint8_t row, uint8_t column, bool state) { uint8_t idx = _internalIndex(segmentOfCoords(row, column), row, column); @@ -67,9 +77,9 @@ void SevenSegmentDisplay::setLedColor(uint8_t row, uint8_t column, bool state, C (state ? _onColors : _offColors)[idx] = color; } -void SevenSegmentDisplay::update(uint8_t rowOffset, uint8_t columnOffset) { - for (uint8_t r = 0, rc = rowCount(); r < rc; ++r) { - for (uint8_t c = 0, cc = columnCount(); c < cc; ++c) { +void SevenSegmentDisplay::update(uint8_t rowOffset, uint8_t columnOffset, uint8_t width, uint8_t height) { + for (uint8_t r = 0; r < height; ++r) { + for (uint8_t c = 0; c < width; ++c) { uint8_t segment = segmentOfCoords(r, c); if (segment != _7SEG_UNDEF) { bool on = _value & _7SEG_MASK(segment); @@ -77,11 +87,17 @@ void SevenSegmentDisplay::update(uint8_t rowOffset, uint8_t columnOffset) { CRGB crgb = (on ? _onColors : _offColors)[_internalIndex(segment, r, c)]; (*_output)(c + columnOffset, r + rowOffset, crgb.red, crgb.green, crgb.blue); } + } else if (_paintBackground) { + (*_output)(c + columnOffset, r + rowOffset, _backgroundColor.red, _backgroundColor.green, _backgroundColor.blue); } } } } +void SevenSegmentDisplay::setPaintBackground(bool paint) { + _paintBackground = paint; +} + void SevenSegmentDisplay::setMode(LedBasedDisplayMode mode) { _mode = mode; } @@ -185,7 +201,7 @@ void SevenSegmentDisplay::setCharacter(char charcter) { } } -void SevenSegmentDisplay::setShowZero(boolean showZero) { +void SevenSegmentDisplay::setShowZero(bool showZero) { _showZero = showZero; } @@ -207,6 +223,8 @@ SeparatorDisplay::SeparatorDisplay(LedBasedDisplayOutput output, uint8_t ledCoun _maxLeds(ledCount), _ledCount(0), _mappings(NULL), + _backgroundColor(CRGB::Black), + _paintBackground(false), _state(false), _mode(LedBasedDisplayMode::SET_ALL_LEDS) { @@ -237,6 +255,14 @@ uint8_t SeparatorDisplay::columnCount() { return max + 1; } +CRGB SeparatorDisplay::getBackgroundColor() { + return _backgroundColor; +} + +void SeparatorDisplay::setBackgroundColor(CRGB color) { + _backgroundColor = color; +} + CRGB* SeparatorDisplay::getLedColor(uint8_t row, uint8_t column, bool state) { for (uint8_t i = 0; i < _ledCount; ++i) { if (_mappings[i].row == row && _mappings[i].column == column) { @@ -263,15 +289,31 @@ void SeparatorDisplay::setLedColor(uint8_t row, uint8_t column, bool state, CRGB } } -void SeparatorDisplay::update(uint8_t rowOffset, uint8_t columnOffset) { - if (_7SEG_MODE(_mode, _state)) { - for (uint8_t i = 0; i < _ledCount; ++i) { - CRGB crgb = _state ? _mappings[i].onColor : _mappings[i].offColor; - (*_output)(_mappings[i].column + columnOffset, _mappings[i].row + rowOffset, crgb.red, crgb.green, crgb.blue); +void SeparatorDisplay::update(uint8_t rowOffset, uint8_t columnOffset, uint8_t width, uint8_t height) { + for (uint8_t r = 0; r < height; ++r) { + for (uint8_t c = 0; c < width; ++c) { + bool found = false; + for (uint8_t i = 0; i < _ledCount; ++i) { + if (_mappings[i].row == r && _mappings[i].column == c) { + if (_7SEG_MODE(_mode, _state)) { + CRGB crgb = _state ? _mappings[i].onColor : _mappings[i].offColor; + (*_output)(c + columnOffset, r + rowOffset, crgb.red, crgb.green, crgb.blue); + } + found = true; + break; + } + } + if (!found && _paintBackground) { + (*_output)(c + columnOffset, r + rowOffset, _backgroundColor.red, _backgroundColor.green, _backgroundColor.blue); + } } } } +void SeparatorDisplay::setPaintBackground(bool paint) { + _paintBackground = paint; +} + void SeparatorDisplay::setMode(LedBasedDisplayMode mode) { _mode = mode; } @@ -320,6 +362,20 @@ uint8_t LedBasedRowDisplay::columnCount() { return columnCount; } +CRGB LedBasedRowDisplay::getBackgroundColor() { + if (_displayCount > 0) { + return _displays[0]->getBackgroundColor(); + } else { + return CRGB::Black; + } +} + +void LedBasedRowDisplay::setBackgroundColor(CRGB color) { + for (uint8_t i = 0; i < _displayCount; i++) { + _displays[i]->setBackgroundColor(color); + } +} + CRGB* LedBasedRowDisplay::getLedColor(uint8_t row, uint8_t column, bool state) { uint8_t c = column; for (uint8_t i = 0; i < _displayCount; i++) { @@ -346,10 +402,18 @@ void LedBasedRowDisplay::setLedColor(uint8_t row, uint8_t column, bool state, CR } } -void LedBasedRowDisplay::update(uint8_t rowOffset, uint8_t columnOffset) { +void LedBasedRowDisplay::update(uint8_t rowOffset, uint8_t columnOffset, uint8_t width, uint8_t height) { + uint8_t h = rowCount(); + for (uint8_t i = 0; i < _displayCount; i++) { + uint8_t cc = _displays[i]->columnCount(); + _displays[i]->update(rowOffset, columnOffset, cc, h); + columnOffset += cc; + } +} + +void LedBasedRowDisplay::setPaintBackground(bool paint) { for (uint8_t i = 0; i < _displayCount; i++) { - _displays[i]->update(rowOffset, columnOffset); - columnOffset += _displays[i]->columnCount(); + _displays[i]->setPaintBackground(paint); } } diff --git a/wled00/7segmdisp.h b/wled00/7segmdisp.h index c382e753d0..f50ac33f94 100644 --- a/wled00/7segmdisp.h +++ b/wled00/7segmdisp.h @@ -103,11 +103,15 @@ class LedBasedDisplay { virtual uint8_t rowCount() = 0; virtual uint8_t columnCount() = 0; + virtual CRGB getBackgroundColor() = 0; + virtual void setBackgroundColor(CRGB color) = 0; + virtual CRGB* getLedColor(uint8_t row, uint8_t column, bool state) = 0; virtual void setLedColor(uint8_t row, uint8_t column, bool state, CRGB color) = 0; - virtual void update(uint8_t rowOffset = 0, uint8_t columnOffset = 0) = 0; + virtual void update(uint8_t rowOffset = 0, uint8_t columnOffset = 0, uint8_t width = 0, uint8_t height = 0) = 0; + virtual void setPaintBackground(bool paint) = 0; virtual void setMode(LedBasedDisplayMode mode) = 0; void setRowColor(uint8_t row, bool state, CRGB color); @@ -125,11 +129,15 @@ class SevenSegmentDisplay : public LedBasedDisplay { virtual uint8_t rowCount() override; virtual uint8_t columnCount() override; + virtual CRGB getBackgroundColor() override; + virtual void setBackgroundColor(CRGB color) override; + virtual CRGB* getLedColor(uint8_t row, uint8_t column, bool state) override; virtual void setLedColor(uint8_t row, uint8_t column, bool state, CRGB color) override; - virtual void update(uint8_t rowOffset = 0, uint8_t columnOffset = 0) override; + virtual void update(uint8_t rowOffset = 0, uint8_t columnOffset = 0, uint8_t width = 0, uint8_t height = 0) override; + virtual void setPaintBackground(bool paint) override; virtual void setMode(LedBasedDisplayMode mode) override; uint8_t segmentOfCoords(uint8_t row, uint8_t column); @@ -137,17 +145,19 @@ class SevenSegmentDisplay : public LedBasedDisplay { void setSymbol(uint8_t symbol); void setDigit(uint8_t digit); void setCharacter(char charcter); - void setShowZero(boolean showZero); + void setShowZero(bool showZero); private: LedBasedDisplayOutput _output; + CRGB _backgroundColor; CRGB* _offColors; CRGB* _onColors; uint8_t _ledsPerSegment; uint8_t _value; - boolean _showZero; + bool _paintBackground; + bool _showZero; LedBasedDisplayMode _mode; @@ -164,11 +174,15 @@ class SeparatorDisplay : public LedBasedDisplay { virtual uint8_t rowCount() override; virtual uint8_t columnCount() override; + virtual CRGB getBackgroundColor() override; + virtual void setBackgroundColor(CRGB color) override; + virtual CRGB* getLedColor(uint8_t row, uint8_t column, bool state) override; virtual void setLedColor(uint8_t row, uint8_t column, bool state, CRGB color) override; - virtual void update(uint8_t rowOffset = 0, uint8_t columnOffset = 0) override; + virtual void update(uint8_t rowOffset = 0, uint8_t columnOffset = 0, uint8_t width = 0, uint8_t height = 0) override; + virtual void setPaintBackground(bool paint) override; virtual void setMode(LedBasedDisplayMode mode) override; void addLed(uint8_t row, uint8_t column); @@ -186,6 +200,8 @@ class SeparatorDisplay : public LedBasedDisplay { uint8_t _maxLeds; uint8_t _ledCount; struct _Mapping* _mappings; + CRGB _backgroundColor; + bool _paintBackground; bool _state; LedBasedDisplayMode _mode; }; @@ -200,11 +216,15 @@ class LedBasedRowDisplay : public LedBasedDisplay { virtual uint8_t rowCount() override; virtual uint8_t columnCount() override; + virtual CRGB getBackgroundColor() override; + virtual void setBackgroundColor(CRGB color) override; + virtual CRGB* getLedColor(uint8_t row, uint8_t column, bool state) override; virtual void setLedColor(uint8_t row, uint8_t column, bool state, CRGB color) override; - virtual void update(uint8_t rowOffset = 0, uint8_t columnOffset = 0) override; + virtual void update(uint8_t rowOffset = 0, uint8_t columnOffset = 0, uint8_t width = 0, uint8_t height = 0) override; + virtual void setPaintBackground(bool paint) override; virtual void setMode(LedBasedDisplayMode mode) override; private: diff --git a/wled00/um_ledclock.h b/wled00/um_ledclock.h index cd49e2e633..22a6421bf0 100644 --- a/wled00/um_ledclock.h +++ b/wled00/um_ledclock.h @@ -574,6 +574,9 @@ class UsermodLedClock : public Usermod, public LedClockSettings { sep.addLed(sepLedRowIndices[i], 0); } + display.setBackgroundColor(CRGB::Black); + display.setPaintBackground(true); + display.setColor(false, CRGB::Black); display.setMode(LedBasedDisplayMode::SET_OFF_LEDS);