Add support for another variant of the 6-digit TM1637 display

Add support for another variant of the 6-digit TM1637 display module selected by command ``DisplayType 1`` (#11422)
This commit is contained in:
Theo Arends 2021-03-22 12:47:15 +01:00
parent 633489a91e
commit 11beacf956
1 changed files with 33 additions and 13 deletions

View File

@ -53,7 +53,7 @@
CS hardware pin --> "MAX7219 CS"
CLK hardware pin --> "MAX7219 CLK"
Once the GPIO configuration is saved and the ESP8266/ESP32 module restarts,
Once the GPIO configuration is saved and the ESP8266/ESP32 module restarts,
set the Display Model to 15 and Display Mode to 0
using the command "Backlog DisplayModel 15 ; DisplayMode 0"
@ -61,7 +61,7 @@
display has, using the command "DisplayWidth 6".
After the ESP8266/ESP32 module restarts again, turn ON the display with the command "Power 1"
Now, the following "Display" commands can be used:
@ -146,7 +146,7 @@
"DisplayClock 0" // turn off clock
In addition, setting DisplayMode to 1 shows the time, setting it to 2 shows the date
In addition, setting DisplayMode to 1 shows the time, setting it to 2 shows the date
and setting it to 3 alternates between time and date.
@ -190,6 +190,7 @@ struct
uint8_t scroll_index = 0;
uint8_t iteration = 0;
uint8_t display_type = TM1637;
uint8_t digit_order[6] = { 0, 1, 2, 3, 4, 5 };
bool init_done = false;
bool scroll = false;
@ -214,7 +215,9 @@ void TM1637Init(void)
if ((!Settings.display_width || Settings.display_width > 6))
{
Settings.display_width = 4;
Settings.display_options.type = 0;
}
TM1637SetDigitOrder();
}
else if (PinUsed(GPIO_MAX7219DIN) && PinUsed(GPIO_MAX7219CLK) && PinUsed(GPIO_MAX7219CS))
{
@ -253,7 +256,7 @@ void TM1637Init(void)
TM1637ClearDisplay();
TM1637Dim();
TM1637Data.init_done = true;
AddLog(LOG_LEVEL_INFO, PSTR("DSP: %s with %d digits"), TM1637Data.model_name, Settings.display_width);
AddLog(LOG_LEVEL_INFO, PSTR("DSP: %s with %d digits (type %d)"), TM1637Data.model_name, Settings.display_width, Settings.display_options.type);
}
// Function to display specified ascii char at specified position for MAX7219
@ -289,6 +292,23 @@ void displayMAX72197Seg(uint8_t pos, uint8_t seg)
max7219display->setRow(MAX7219_ADDR, pos, seg);
}
// Function to fix order of hardware digits for different TM1637 variants
void TM1637SetDigitOrder(void) {
if (0 == Settings.display_options.type) {
for (uint32_t i = 0; i < 6; i++) {
TM1637Data.digit_order[i] = i;
}
}
else if (1 == Settings.display_options.type) {
TM1637Data.digit_order[0] = 2;
TM1637Data.digit_order[1] = 1;
TM1637Data.digit_order[2] = 0;
TM1637Data.digit_order[3] = 5;
TM1637Data.digit_order[4] = 4;
TM1637Data.digit_order[5] = 3;
}
}
/*********************************************************************************************\
* Displays number without decimal, with/without leading zeros, specifying start-position
* and length, optionally skipping clearing display before displaying the number.
@ -349,7 +369,7 @@ bool CmndTM1637Number(bool clear)
if (TM1637 == TM1637Data.display_type)
{
rawBytes[0] = tm1637display->encode(pad);
tm1637display->printRaw(rawBytes, 1, i);
tm1637display->printRaw(rawBytes, 1, TM1637Data.digit_order[i]);
}
else if (TM1638 == TM1637Data.display_type)
tm1638display->displayASCII(i, pad);
@ -370,7 +390,7 @@ bool CmndTM1637Number(bool clear)
if (TM1637 == TM1637Data.display_type)
{
rawBytes[0] = tm1637display->encode(txt[j]);
tm1637display->printRaw(rawBytes, 1, i);
tm1637display->printRaw(rawBytes, 1, TM1637Data.digit_order[i]);
}
else if (TM1638 == TM1637Data.display_type)
tm1638display->displayASCII(i, txt[j]);
@ -456,7 +476,7 @@ bool CmndTM1637Float(bool clear)
}
if ((j + position) > Settings.display_width)
break;
tm1637display->printRaw(rawBytes, 1, j + position);
tm1637display->printRaw(rawBytes, 1, TM1637Data.digit_order[j + position]);
}
}
else if (TM1638 == TM1637Data.display_type)
@ -626,7 +646,7 @@ void TM1637ScrollText(void)
}
if (TM1637 == TM1637Data.display_type)
{
tm1637display->printRaw(rawBytes, 1, i);
tm1637display->printRaw(rawBytes, 1, TM1637Data.digit_order[i]);
}
else if (TM1638 == TM1637Data.display_type)
{
@ -673,7 +693,7 @@ bool CmndTM1637Level(void)
if (TM1637 == TM1637Data.display_type)
{
rawBytes[0] = value;
tm1637display->printRaw(rawBytes, 1, digit);
tm1637display->printRaw(rawBytes, 1, TM1637Data.digit_order[digit]);
}
else if (TM1638 == TM1637Data.display_type)
{
@ -758,7 +778,7 @@ bool CmndTM1637Raw(void)
if (i > (Settings.display_width - 1))
break;
rawBytes[0] = DATA[i - position];
tm1637display->printRaw(rawBytes, 1, i);
tm1637display->printRaw(rawBytes, 1, TM1637Data.digit_order[i]);
}
}
else if (TM1638 == TM1637Data.display_type)
@ -845,7 +865,7 @@ bool CmndTM1637Text(bool clear)
}
if (!dotSkipped && sString[j] == '.')
rawBytes[0] = 128;
tm1637display->printRaw(rawBytes, 1, i);
tm1637display->printRaw(rawBytes, 1, TM1637Data.digit_order[i]);
}
}
else if (TM1638 == TM1637Data.display_type)
@ -971,7 +991,7 @@ void TM1637ShowTime()
rawBytes[0] = tm1637display->encode(tm[i]);
if ((millis() % 1000) > 500 && (i == 1))
rawBytes[0] = rawBytes[0] | 128;
tm1637display->printRaw(rawBytes, 1, i);
tm1637display->printRaw(rawBytes, 1, TM1637Data.digit_order[i]);
}
}
else if (TM1638 == TM1637Data.display_type)
@ -1084,7 +1104,7 @@ void TM1637Print(char *txt)
uint8_t rawBytes[1];
rawBytes[0] = tm1637display->encode(txt[i]);
// if ((millis() % 1000) > 500 && (i == 1)) { rawBytes[0] = rawBytes[0] | 128; }
tm1637display->printRaw(rawBytes, 1, i);
tm1637display->printRaw(rawBytes, 1, TM1637Data.digit_order[i]);
}
else if (TM1638 == TM1637Data.display_type)
{