From ced43adb7a086d8a2a87f9df81136bee845d64ae Mon Sep 17 00:00:00 2001 From: Ajith Vasudevan Date: Mon, 22 Mar 2021 09:57:40 +0530 Subject: [PATCH] Added support for another variant of the 6-digit TM1637 display module --- tasmota/settings.h | 2 +- tasmota/xdrv_13_display.ino | 16 ++++++++++++++-- tasmota/xdsp_15_tm1637.ino | 37 ++++++++++++++++++++++++++++--------- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/tasmota/settings.h b/tasmota/settings.h index 05ab839223d2..f8599346bf9f 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -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; diff --git a/tasmota/xdrv_13_display.ino b/tasmota/xdrv_13_display.ino index a8f50d73559b..b2aae146f4c5 100755 --- a/tasmota/xdrv_13_display.ino +++ b/tasmota/xdrv_13_display.ino @@ -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, @@ -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 = { @@ -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; @@ -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)) { diff --git a/tasmota/xdsp_15_tm1637.ino b/tasmota/xdsp_15_tm1637.ino index e2c5ae8eae59..2b330d5518a4 100644 --- a/tasmota/xdsp_15_tm1637.ino +++ b/tasmota/xdsp_15_tm1637.ino @@ -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.tm1637_variant = 0; } + setTM1637DigitOrder(); } else if (PinUsed(GPIO_MAX7219DIN) && PinUsed(GPIO_MAX7219CLK) && PinUsed(GPIO_MAX7219CS)) { @@ -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 @@ -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. @@ -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); @@ -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]); @@ -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) @@ -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) { @@ -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) { @@ -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) @@ -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) @@ -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) @@ -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) {