Fixing colon for tm1637 display if inverted set true (#5072)

This commit is contained in:
Pavlo Dudnytskyi 2023-07-12 22:24:49 +02:00 committed by GitHub
parent 119bbba254
commit e4a640844c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -300,6 +300,7 @@ uint8_t TM1637Display::read_byte_() {
uint8_t TM1637Display::print(uint8_t start_pos, const char *str) {
// ESP_LOGV(TAG, "Print at %d: %s", start_pos, str);
uint8_t pos = start_pos;
bool use_dot = false;
for (; *str != '\0'; str++) {
uint8_t data = TM1637_UNKNOWN_CHAR;
if (*str >= ' ' && *str <= '~')
@ -312,14 +313,14 @@ uint8_t TM1637Display::print(uint8_t start_pos, const char *str) {
// XABCDEFG, but TM1637 is // XGFEDCBA
if (this->inverted_) {
// XABCDEFG > XGCBAFED
data = ((data & 0x80) ? 0x80 : 0) | // no move X
((data & 0x40) ? 0x8 : 0) | // A
((data & 0x20) ? 0x10 : 0) | // B
((data & 0x10) ? 0x20 : 0) | // C
((data & 0x8) ? 0x1 : 0) | // D
((data & 0x4) ? 0x2 : 0) | // E
((data & 0x2) ? 0x4 : 0) | // F
((data & 0x1) ? 0x40 : 0); // G
data = ((data & 0x80) || use_dot ? 0x80 : 0) | // no move X
((data & 0x40) ? 0x8 : 0) | // A
((data & 0x20) ? 0x10 : 0) | // B
((data & 0x10) ? 0x20 : 0) | // C
((data & 0x8) ? 0x1 : 0) | // D
((data & 0x4) ? 0x2 : 0) | // E
((data & 0x2) ? 0x4 : 0) | // F
((data & 0x1) ? 0x40 : 0); // G
} else {
// XABCDEFG > XGFEDCBA
data = ((data & 0x80) ? 0x80 : 0) | // no move X
@ -331,18 +332,18 @@ uint8_t TM1637Display::print(uint8_t start_pos, const char *str) {
((data & 0x2) ? 0x20 : 0) | // F
((data & 0x1) ? 0x40 : 0); // G
}
if (*str == '.') {
if (pos != start_pos)
pos--;
this->buffer_[pos] |= 0b10000000;
use_dot = *str == '.';
if (use_dot) {
if ((!this->inverted_) && (pos != start_pos)) {
this->buffer_[pos - 1] |= 0b10000000;
}
} else {
if (pos >= 6) {
ESP_LOGE(TAG, "String is too long for the display!");
break;
}
this->buffer_[pos] = data;
this->buffer_[pos++] = data;
}
pos++;
}
return pos - start_pos;
}