Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for another variant of the 6-digit TM1637 display module #11422

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tasmota/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ typedef union {
struct {
uint8_t ilimode : 3;
uint8_t Invert : 1;
uint8_t spare2 : 1;
uint8_t tm1637_variant : 1;
uint8_t spare3 : 1;
uint8_t spare4 : 1;
uint8_t spare5 : 1;
Expand Down
16 changes: 14 additions & 2 deletions tasmota/xdrv_13_display.ino
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const uint8_t DISPLAY_LOG_ROWS = 32; // Number of lines in display log
#define D_CMND_DISP_SCROLLTEXT "ScrollText"
#define D_CMND_DISP_ILIMODE "ILIMode"
#define D_CMND_DISP_ILIINVERT "Invert"
#define D_CMND_DISP_TMVARIANT "TMVariant" // `DisplayTMVariant 0` = 6 digit, standard model; `DisplayTMVariant 1` = 6 digit, "jumbled" model


enum XdspFunctions { FUNC_DISPLAY_INIT_DRIVER, FUNC_DISPLAY_INIT, FUNC_DISPLAY_EVERY_50_MSECOND, FUNC_DISPLAY_EVERY_SECOND,
Expand Down Expand Up @@ -110,7 +111,7 @@ const char kDisplayCommands[] PROGMEM = D_PRFX_DISPLAY "|" // Prefix
D_CMND_DISP_CLEAR "|" D_CMND_DISP_NUMBER "|" D_CMND_DISP_FLOAT "|" D_CMND_DISP_NUMBERNC "|" D_CMND_DISP_FLOATNC "|"
D_CMND_DISP_RAW "|" D_CMND_DISP_LEVEL "|" D_CMND_DISP_SEVENSEG_TEXT "|" D_CMND_DISP_SEVENSEG_TEXTNC "|"
D_CMND_DISP_SCROLLDELAY "|" D_CMND_DISP_CLOCK "|" D_CMND_DISP_TEXTNC "|"
D_CMND_DISP_SCROLLTEXT "|" D_CMND_DISP_ILIMODE "|" D_CMND_DISP_ILIINVERT
D_CMND_DISP_SCROLLTEXT "|" D_CMND_DISP_ILIMODE "|" D_CMND_DISP_ILIINVERT "|" D_CMND_DISP_TMVARIANT
;

void (* const DisplayCommand[])(void) PROGMEM = {
Expand All @@ -123,7 +124,7 @@ void (* const DisplayCommand[])(void) PROGMEM = {
&CmndDisplayClear, &CmndDisplayNumber, &CmndDisplayFloat, &CmndDisplayNumberNC, &CmndDisplayFloatNC,
&CmndDisplayRaw, &CmndDisplayLevel, &CmndDisplaySevensegText, &CmndDisplaySevensegTextNC,
&CmndDisplayScrollDelay, &CmndDisplayClock, &CmndDisplayTextNC,
&CmndDisplayScrollText, &CmndDisplayILIMOde , &CmndDisplayILIInvert
&CmndDisplayScrollText, &CmndDisplayILIMOde , &CmndDisplayILIInvert, &CmndDisplayTMVariant
};

char *dsp_str;
Expand Down Expand Up @@ -1892,6 +1893,17 @@ void CmndDisplayILIMOde(void)
ResponseCmndNumber(Settings.display_options.ilimode);
}


void CmndDisplayTMVariant(void)
{
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 2)) {
Settings.display_options.tm1637_variant = XdrvMailbox.payload;
TasmotaGlobal.restart_flag = 2;
}
ResponseCmndNumber(Settings.display_options.tm1637_variant);
}


void CmndDisplayILIInvert(void)
{
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
Expand Down
37 changes: 28 additions & 9 deletions tasmota/xdsp_15_tm1637.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -214,7 +215,9 @@ void TM1637Init(void)
if ((!Settings.display_width || Settings.display_width > 6))
{
Settings.display_width = 4;
Settings.display_options.tm1637_variant = 0;
}
setTM1637DigitOrder();
}
else if (PinUsed(GPIO_MAX7219DIN) && PinUsed(GPIO_MAX7219CLK) && PinUsed(GPIO_MAX7219CS))
{
Expand Down Expand Up @@ -254,6 +257,8 @@ void TM1637Init(void)
TM1637Dim();
TM1637Data.init_done = true;
AddLog(LOG_LEVEL_INFO, PSTR("DSP: %s with %d digits"), TM1637Data.model_name, Settings.display_width);
if(TM1637 == TM1637Data.display_type)
AddLog(LOG_LEVEL_INFO, PSTR("DSP: TM1637 variant is %d"), Settings.display_options.tm1637_variant);
}

// Function to display specified ascii char at specified position for MAX7219
Expand Down Expand Up @@ -289,6 +294,20 @@ 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 setTM1637DigitOrder() {
if(Settings.display_options.tm1637_variant == 0) {
for(uint8_t i=0; i<6; i++) TM1637Data.digit_order[i] = i;
} else if(Settings.display_options.tm1637_variant == 1) {
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.
Expand Down Expand Up @@ -349,7 +368,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);
Expand All @@ -370,7 +389,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]);
Expand Down Expand Up @@ -456,7 +475,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)
Expand Down Expand Up @@ -626,7 +645,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)
{
Expand Down Expand Up @@ -673,7 +692,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)
{
Expand Down Expand Up @@ -758,7 +777,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)
Expand Down Expand Up @@ -845,7 +864,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)
Expand Down Expand Up @@ -971,7 +990,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)
Expand Down Expand Up @@ -1084,7 +1103,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)
{
Expand Down