Skip to content

Commit

Permalink
Fix ABL issue by setting "virtual" LEDs to black.
Browse files Browse the repository at this point in the history
  • Loading branch information
imeszaros committed Jan 22, 2024
1 parent 995fd4e commit 5a7bc92
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 18 deletions.
Binary file modified docs/firmware-1.3.0.bin
Binary file not shown.
88 changes: 76 additions & 12 deletions wled00/7segmdisp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);

Expand All @@ -67,21 +77,27 @@ 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);
if (_7SEG_MODE(_mode, on)) {
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;
}
Expand Down Expand Up @@ -185,7 +201,7 @@ void SevenSegmentDisplay::setCharacter(char charcter) {
}
}

void SevenSegmentDisplay::setShowZero(boolean showZero) {
void SevenSegmentDisplay::setShowZero(bool showZero) {
_showZero = showZero;
}

Expand All @@ -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) {

Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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++) {
Expand All @@ -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);
}
}

Expand Down
32 changes: 26 additions & 6 deletions wled00/7segmdisp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -125,29 +129,35 @@ 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);

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;

Expand All @@ -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);
Expand All @@ -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;
};
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions wled00/um_ledclock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 5a7bc92

Please sign in to comment.