mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 16:38:16 +01:00
Fixing colon for tm1637 display if inverted set true (#5072)
This commit is contained in:
parent
119bbba254
commit
e4a640844c
1 changed files with 15 additions and 14 deletions
|
@ -300,6 +300,7 @@ uint8_t TM1637Display::read_byte_() {
|
||||||
uint8_t TM1637Display::print(uint8_t start_pos, const char *str) {
|
uint8_t TM1637Display::print(uint8_t start_pos, const char *str) {
|
||||||
// ESP_LOGV(TAG, "Print at %d: %s", start_pos, str);
|
// ESP_LOGV(TAG, "Print at %d: %s", start_pos, str);
|
||||||
uint8_t pos = start_pos;
|
uint8_t pos = start_pos;
|
||||||
|
bool use_dot = false;
|
||||||
for (; *str != '\0'; str++) {
|
for (; *str != '\0'; str++) {
|
||||||
uint8_t data = TM1637_UNKNOWN_CHAR;
|
uint8_t data = TM1637_UNKNOWN_CHAR;
|
||||||
if (*str >= ' ' && *str <= '~')
|
if (*str >= ' ' && *str <= '~')
|
||||||
|
@ -312,7 +313,7 @@ uint8_t TM1637Display::print(uint8_t start_pos, const char *str) {
|
||||||
// XABCDEFG, but TM1637 is // XGFEDCBA
|
// XABCDEFG, but TM1637 is // XGFEDCBA
|
||||||
if (this->inverted_) {
|
if (this->inverted_) {
|
||||||
// XABCDEFG > XGCBAFED
|
// XABCDEFG > XGCBAFED
|
||||||
data = ((data & 0x80) ? 0x80 : 0) | // no move X
|
data = ((data & 0x80) || use_dot ? 0x80 : 0) | // no move X
|
||||||
((data & 0x40) ? 0x8 : 0) | // A
|
((data & 0x40) ? 0x8 : 0) | // A
|
||||||
((data & 0x20) ? 0x10 : 0) | // B
|
((data & 0x20) ? 0x10 : 0) | // B
|
||||||
((data & 0x10) ? 0x20 : 0) | // C
|
((data & 0x10) ? 0x20 : 0) | // C
|
||||||
|
@ -331,18 +332,18 @@ uint8_t TM1637Display::print(uint8_t start_pos, const char *str) {
|
||||||
((data & 0x2) ? 0x20 : 0) | // F
|
((data & 0x2) ? 0x20 : 0) | // F
|
||||||
((data & 0x1) ? 0x40 : 0); // G
|
((data & 0x1) ? 0x40 : 0); // G
|
||||||
}
|
}
|
||||||
if (*str == '.') {
|
use_dot = *str == '.';
|
||||||
if (pos != start_pos)
|
if (use_dot) {
|
||||||
pos--;
|
if ((!this->inverted_) && (pos != start_pos)) {
|
||||||
this->buffer_[pos] |= 0b10000000;
|
this->buffer_[pos - 1] |= 0b10000000;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (pos >= 6) {
|
if (pos >= 6) {
|
||||||
ESP_LOGE(TAG, "String is too long for the display!");
|
ESP_LOGE(TAG, "String is too long for the display!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this->buffer_[pos] = data;
|
this->buffer_[pos++] = data;
|
||||||
}
|
}
|
||||||
pos++;
|
|
||||||
}
|
}
|
||||||
return pos - start_pos;
|
return pos - start_pos;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue