From ba77e6d1c0d5632133e80d14bf66c38e45912cad Mon Sep 17 00:00:00 2001 From: Ajith Vasudevan Date: Thu, 18 Mar 2021 19:30:50 +0530 Subject: [PATCH] Removed DisplayType and TM1638 Buttons and LEDs support --- tasmota/xdrv_13_display.ino | 58 +------ tasmota/xdsp_15_tm1637.ino | 330 ++++++++---------------------------- 2 files changed, 78 insertions(+), 310 deletions(-) diff --git a/tasmota/xdrv_13_display.ino b/tasmota/xdrv_13_display.ino index 4524858ac..35e4e05ee 100755 --- a/tasmota/xdrv_13_display.ino +++ b/tasmota/xdrv_13_display.ino @@ -77,11 +77,7 @@ const uint8_t DISPLAY_LOG_ROWS = 32; // Number of lines in display log #define D_CMND_DISP_SCROLLDELAY "ScrollDelay" #define D_CMND_DISP_CLOCK "Clock" #define D_CMND_DISP_TEXTNC "TextNC" // NC - "No Clear" -#define D_CMND_DISP_SETLEDS "SetLEDs" -#define D_CMND_DISP_SETLED "SetLED" -#define D_CMND_DISP_BUTTONS "Buttons" #define D_CMND_DISP_SCROLLTEXT "ScrollText" -#define D_CMND_DISP_TYPE "Type" #define D_CMND_DISP_ILIMODE "ILIMode" #define D_CMND_DISP_ILIINVERT "Invert" @@ -99,8 +95,7 @@ enum XdspFunctions { FUNC_DISPLAY_INIT_DRIVER, FUNC_DISPLAY_INIT, FUNC_DISPLAY_E #endif , FUNC_DISPLAY_NUMBER, FUNC_DISPLAY_FLOAT, FUNC_DISPLAY_NUMBERNC, FUNC_DISPLAY_FLOATNC, FUNC_DISPLAY_BRIGHTNESS, FUNC_DISPLAY_RAW, FUNC_DISPLAY_LEVEL, FUNC_DISPLAY_SEVENSEG_TEXT, FUNC_DISPLAY_SEVENSEG_TEXTNC, - FUNC_DISPLAY_SCROLLDELAY, FUNC_DISPLAY_CLOCK, FUNC_DISPLAY_SETLEDS, FUNC_DISPLAY_SETLED, - FUNC_DISPLAY_BUTTONS, FUNC_DISPLAY_SCROLLTEXT, FUNC_DISPLAY_TYPE + FUNC_DISPLAY_SCROLLDELAY, FUNC_DISPLAY_CLOCK, FUNC_DISPLAY_SCROLLTEXT }; enum DisplayInitModes { DISPLAY_INIT_MODE, DISPLAY_INIT_PARTIAL, DISPLAY_INIT_FULL }; @@ -114,8 +109,8 @@ const char kDisplayCommands[] PROGMEM = D_PRFX_DISPLAY "|" // Prefix #endif "|" D_CMND_DISP_CLEAR "|" D_CMND_DISP_NUMBER "|" D_CMND_DISP_FLOAT "|" D_CMND_DISP_NUMBERNC "|" D_CMND_DISP_FLOATNC "|" D_CMND_DISP_BRIGHTNESS "|" 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_SETLEDS "|" D_CMND_DISP_SETLED "|" - D_CMND_DISP_BUTTONS "|" D_CMND_DISP_SCROLLTEXT "|" D_CMND_DISP_TYPE "|" D_CMND_DISP_ILIMODE "|" D_CMND_DISP_ILIINVERT + D_CMND_DISP_SCROLLDELAY "|" D_CMND_DISP_CLOCK "|" D_CMND_DISP_TEXTNC "|" + D_CMND_DISP_SCROLLTEXT "|" D_CMND_DISP_ILIMODE "|" D_CMND_DISP_ILIINVERT ; void (* const DisplayCommand[])(void) PROGMEM = { @@ -127,8 +122,8 @@ void (* const DisplayCommand[])(void) PROGMEM = { #endif , &CmndDisplayClear, &CmndDisplayNumber, &CmndDisplayFloat, &CmndDisplayNumberNC, &CmndDisplayFloatNC, &CmndDisplayBrightness, &CmndDisplayRaw, &CmndDisplayLevel, &CmndDisplaySevensegText, &CmndDisplaySevensegTextNC, - &CmndDisplayScrollDelay, &CmndDisplayClock, &CmndDisplayTextNC, &CmndDisplaySetLEDs, &CmndDisplaySetLED, - &CmndDisplayButtons, &CmndDisplayScrollText, &CmndDisplayType, &CmndDisplayILIMOde , &CmndDisplayILIInvert + &CmndDisplayScrollDelay, &CmndDisplayClock, &CmndDisplayTextNC, + &CmndDisplayScrollText, &CmndDisplayILIMOde , &CmndDisplayILIInvert }; char *dsp_str; @@ -1865,33 +1860,6 @@ void CmndDisplayClock(void) ResponseCmndNumber(XdrvMailbox.payload); } -void CmndDisplaySetLEDs(void) -{ - bool result = false; - if (!renderer) { - result = XdspCall(FUNC_DISPLAY_SETLEDS); - } - if(result) ResponseCmndNumber(XdrvMailbox.payload); -} - - -void CmndDisplaySetLED(void) -{ - bool result = false; - if (!renderer) { - result = XdspCall(FUNC_DISPLAY_SETLED); - } - if(result) ResponseCmndNumber(XdrvMailbox.payload); -} - -void CmndDisplayButtons(void) -{ - bool result = false; - if (!renderer) { - XdspCall(FUNC_DISPLAY_BUTTONS); - } -} - void CmndDisplayScrollText(void) { @@ -1903,22 +1871,6 @@ void CmndDisplayScrollText(void) } -void CmndDisplayType(void) -{ - if(ArgC() == 0) { - XdrvMailbox.payload = Settings.display_options.data; - } else { - uint8_t prev_type = Settings.display_options.data; - if(prev_type != XdrvMailbox.payload) { - if (!renderer) { - XdspCall(FUNC_DISPLAY_TYPE); - Settings.display_options.data = XdrvMailbox.payload; - } - } - } - ResponseCmndNumber(XdrvMailbox.payload); -} - void CmndDisplaySize(void) { #ifdef USE_DISPLAY_TM1637 diff --git a/tasmota/xdsp_15_tm1637.ino b/tasmota/xdsp_15_tm1637.ino index d551582b0..2d2f17bba 100644 --- a/tasmota/xdsp_15_tm1637.ino +++ b/tasmota/xdsp_15_tm1637.ino @@ -21,9 +21,7 @@ #ifdef USE_DISPLAY_TM1637 /*********************************************************************************************\ This driver enables the display of numbers (both integers and floats) and basic text - on the inexpensive TM1637- and TM1638-based seven-segment modules. Additionally, for the TM1638, - it allows the TM1638 LEDs to be toggled using its buttons. - Useful STAT messages are also sent when the TM1638 buttons are pressed. + on the inexpensive TM1637- and TM1638-based seven-segment modules. Raw segments can also be displayed. @@ -51,23 +49,12 @@ Once the GPIO configuration is saved and the ESP8266/ESP32 module restarts, set the Display Model to 15 using the command "DisplayModel 15" - After this, depending upon your display variant, set your Display Type to 0, 1 or 2 using the command - "DisplayType 0" // for the 4-digit TM1637 - or "DisplayType 1" // for the 6-digit TM1637 - or "DisplayType 2" // for the 8-digit TM1638 + If your display is a TM1637 with 6 digits, set Display Columns to the number of digits your + display has, using the command "DisplayCols 6" and restart the ESP module. After the ESP8266/ESP32 module restarts again, the following "Display" commands can be used: - DisplayType type {0|1|2} - - Sets the display type. 0 => TM1637, 4 digit - 1 => TM1637, 6 digit - 2 => TM1638, 8 digit - Command e.g., "TM1637Data.display_type 1" // to enable TM1637 6-digit variant - - - DisplayClear Clears the display, command: "DisplayClear" @@ -156,56 +143,6 @@ -Commands specific to TM1638 -==================================== - - DisplaySetLEDs bit_array {0-255} - - Sets the 8 LEDs (not the digits!) on the TM1638 module to the binary number represented by the input bit_array. - For example, "DisplaySetLEDs 3" would light up the first and second LED (from left), because 3 => 00000011 - - - - DisplaySetLED position {0-7}, value {0|1} - - Sets a specified LED to either ON or OFF. e.g., "DisplaySetLED 2, 1" would light up the 3rd LED (2 => 3rd position) - - - - DisplayButtons - - Causes the current state of the buttons/LEDs to be returned as a "STAT" message of the following form: - stat/TM1638/RESULT = {"DisplayButtons": {"S1":, "S2":, "S3":, "S4":, "S5":, "S6":, "S7":, "S8":, "Array": [,,,,,,,], "Byte": }} - where , , ... are the states of each of the buttons/LEDs, and is the decimal representation - of the bit-array that constitutes these states. - - For example, if the 5th button is pressed to turn ON LED5, and the "DisplayButtons" command is issued, - the response STAT message will be of the form: - stat/TM1638/RESULT = {"DisplayButtons": {"S1":0, "S2":0, "S3":0, "S4":0, "S5":1, "S6":0, "S7":0, "S8":0, "Array": [0,0,0,0,1,0,0,0], "Byte": 16}} - because 16 => 2^(5-1) - - - - Button Functionality (TM1638 only): -====================================== - When this driver is initialized with "DisplayType 2" (TM1638), the buttons on the TM1638 module can be used - to toggle the corresponding LEDs. - - In addition, for each button press, a STAT message of the following form is sent: - - stat//RESULT = {"TM1638_BUTTON":} - - where = button index (starting at 1) - = state of the corresponding LED. It can be "ON" or "OFF" - - For example, if Button3 is pressed, LED3 would light up and a STAT message is sent as follows: - - stat/TM1638/RESULT = {"TM1638_BUTTON3":"ON"} - - Pressing Button3 again would turn OFF LED3 and a STAT message is sent as follows: - - stat/TM1638/RESULT = {"TM1638_BUTTON3":"OFF"} - \*********************************************************************************************/ @@ -254,31 +191,37 @@ struct { /*********************************************************************************************\ * Init function \*********************************************************************************************/ -bool DriverInit(void) { - if(Settings.display_model == XDSP_15) { - if(TM1637Data.driver_inited) return true; +bool TM1637Init(void) { - if(Settings.display_options.data == 2) { TM1637Data.num_digits = 8; TM1637Data.display_type = TM1638; } - else if(Settings.display_options.data == 1) { TM1637Data.num_digits = 6; TM1637Data.display_type = TM1637; } - else { Settings.display_options.data = 0; TM1637Data.num_digits = 4; TM1637Data.display_type = TM1637; } + if(TM1637Data.driver_inited) return true; - if(TM1637Data.display_type == TM1637) { - strcpy(TM1637Data.model_name, "TM1637"); - tm1637display = new SevenSegmentTM1637(Pin(GPIO_TM1637CLK), Pin(GPIO_TM1637DIO)); - tm1637display->begin(TM1637Data.num_digits, 1); - } else if(TM1637Data.display_type == TM1638) { - strcpy(TM1637Data.model_name, "TM1638"); - tm1638display = new TM1638plus(Pin(GPIO_TM16STB), Pin(GPIO_TM16CLK), Pin(GPIO_TM16DIO), true ); - TM1637Data.num_digits = 8; - tm1638display->displayBegin(); - } - Settings.display_size = TM1637Data.num_digits; // Can use to check current display size - clearDisplay(); - TM1637Data.brightness = (Settings.display_dimmer ? Settings.display_dimmer : TM1637Data.brightness); - setBrightness(TM1637Data.brightness); - TM1637Data.driver_inited = true; - AddLog(LOG_LEVEL_INFO, PSTR("DSP: %s display driver initialized with %d digits (DisplayType %d)"), TM1637Data.model_name, TM1637Data.num_digits, Settings.display_options.data); + if(PinUsed(GPIO_TM16CLK) && PinUsed(GPIO_TM16DIO) && PinUsed(GPIO_TM16STB)) { + TM1637Data.display_type = TM1638; + TM1637Data.num_digits = 8; + } else if(PinUsed(GPIO_TM1637CLK) && PinUsed(GPIO_TM1637DIO)) { + TM1637Data.display_type = TM1637; + if(Settings.display_cols[0] <= 6) TM1637Data.num_digits = Settings.display_cols[0]; + else TM1637Data.num_digits = 4; } + else return false; + + Settings.display_model == XDSP_15; + + if(TM1637Data.display_type == TM1637) { + strcpy(TM1637Data.model_name, "TM1637"); + tm1637display = new SevenSegmentTM1637(Pin(GPIO_TM1637CLK), Pin(GPIO_TM1637DIO)); + tm1637display->begin(TM1637Data.num_digits, 1); + } else if(TM1637Data.display_type == TM1638) { + strcpy(TM1637Data.model_name, "TM1638"); + tm1638display = new TM1638plus(Pin(GPIO_TM16STB), Pin(GPIO_TM16CLK), Pin(GPIO_TM16DIO), true ); + TM1637Data.num_digits = 8; + tm1638display->displayBegin(); + } + TM1637ClearDisplay(); + TM1637Data.brightness = (Settings.display_dimmer ? Settings.display_dimmer : TM1637Data.brightness); + TM1637SetBrightness(TM1637Data.brightness); + TM1637Data.driver_inited = true; + AddLog(LOG_LEVEL_INFO, PSTR("DSP: %s display driver initialized with %d digits"), TM1637Data.model_name, TM1637Data.num_digits); return true; } @@ -289,7 +232,7 @@ bool DriverInit(void) { * commands: DisplayNumber num [,position {0-(TM1637Data.num_digits-1)} [,leading_zeros {0|1} [,length {1 to TM1637Data.num_digits}]]] * DisplayNumberNC num [,position {0-(TM1637Data.num_digits-1)} [,leading_zeros {0|1} [,length {1 to TM1637Data.num_digits}]]] // "NC" --> "No Clear" \*********************************************************************************************/ -bool CmndNumber(bool clear) { +bool CmndTM1637Number(bool clear) { char sNum[CMD_MAX_LEN]; char sLeadingzeros[CMD_MAX_LEN]; char sPosition[CMD_MAX_LEN]; @@ -321,7 +264,7 @@ bool CmndNumber(bool clear) { AddLog(LOG_LEVEL_DEBUG, PSTR("TM7: num %d, pos %d, lead %d, len %d"), num, position, leadingzeros, length); - if(clear) clearDisplay(); + if(clear) TM1637ClearDisplay(); char txt[30]; snprintf_P(txt, sizeof(txt), PSTR("%d"), num); @@ -354,7 +297,7 @@ bool CmndNumber(bool clear) { * commands: DisplayFloat num [,position {0-(TM1637Data.num_digits-1)} [,precision {0-TM1637Data.num_digits} [,length {1 to TM1637Data.num_digits}]]] * DisplayFloatNC num [,position {0-(TM1637Data.num_digits-1)} [,precision {0-TM1637Data.num_digits} [,length {1 to TM1637Data.num_digits}]]] // "NC" --> "No Clear" \*********************************************************************************************/ -bool CmndFloat(bool clear) { +bool CmndTM1637Float(bool clear) { char sNum[CMD_MAX_LEN]; char sPrecision[CMD_MAX_LEN]; @@ -386,7 +329,7 @@ bool CmndFloat(bool clear) { if((position < 0) || (position > (TM1637Data.num_digits-1))) position = 0; if((precision < 0) || (precision > TM1637Data.num_digits)) precision = TM1637Data.num_digits; - if(clear) clearDisplay(); + if(clear) TM1637ClearDisplay(); char txt[30]; ext_snprintf_P(txt, sizeof(txt), PSTR("%*_f"), precision, &fnum); @@ -430,8 +373,8 @@ bool CmndFloat(bool clear) { // * Clears the display // * Command: DisplayClear // \*********************************************************************************************/ -bool CmndClear(void) { - clearDisplay(); +bool CmndTM1637Clear(void) { + TM1637ClearDisplay(); sprintf(TM1637Data.msg, PSTR("Cleared")); XdrvMailbox.data = TM1637Data.msg; return true; @@ -441,7 +384,7 @@ bool CmndClear(void) { // /*********************************************************************************************\ // * Clears the display // \*********************************************************************************************/ -void clearDisplay (void) { +void TM1637ClearDisplay (void) { if(TM1637Data.display_type == TM1637) { unsigned char arr[] = {0}; for(int i=0; iprintRaw(arr, 1, i); @@ -455,7 +398,7 @@ void clearDisplay (void) { * Display scrolling text * Command: DisplayTM1637Data.scroll_text text \*********************************************************************************************/ -bool CmndScrollText(void) { +bool CmndTM1637ScrollText(void) { AddLog(LOG_LEVEL_DEBUG, PSTR("TM7: Text %s"), XdrvMailbox.data); @@ -480,7 +423,7 @@ bool CmndScrollText(void) { * Sets the scroll delay for scrolling text. * Command: DisplayTM1637Data.scroll_delay delay {0-15} // default = 4 \*********************************************************************************************/ -bool CmndScrollDelay(void) { +bool CmndTM1637ScrollDelay(void) { if(ArgC() == 0) { XdrvMailbox.payload = TM1637Data.scroll_delay; return true; @@ -495,7 +438,7 @@ bool CmndScrollDelay(void) { /*********************************************************************************************\ * Scrolls a given string. Called every 50ms \*********************************************************************************************/ -void scrollText(void) { +void TM1637ScrollText(void) { TM1637Data.iteration++; if(TM1637Data.scroll_delay) TM1637Data.iteration = TM1637Data.iteration % TM1637Data.scroll_delay; else TM1637Data.iteration = 0; @@ -538,7 +481,7 @@ void scrollText(void) { * Displays a horizontal bar graph. Takes a percentage number (0-100) as input * Command: DisplayLevel level {0-100} \*********************************************************************************************/ -bool CmndLevel(void) { +bool CmndTM1637Level(void) { uint16_t val = XdrvMailbox.payload; if((val < LEVEL_MIN) || (val > LEVEL_MAX)) { Response_P(PSTR("{\"Error\":\"Level should be a number in the range [%d, %d]\"}"), LEVEL_MIN, LEVEL_MAX); @@ -546,17 +489,17 @@ bool CmndLevel(void) { } uint8_t totalBars = 2*TM1637Data.num_digits; - AddLog(LOG_LEVEL_DEBUG, PSTR("TM7: TM1637Data.model_name %s CmndLevel totalBars=%d"), TM1637Data.model_name, totalBars); + AddLog(LOG_LEVEL_DEBUG, PSTR("TM7: TM1637Data.model_name %s CmndTM1637Level totalBars=%d"), TM1637Data.model_name, totalBars); float barsToDisplay = totalBars * val / 100.0f; char txt[5]; ext_snprintf_P(txt, sizeof(txt), PSTR("%*_f"), 1, &barsToDisplay); - AddLog(LOG_LEVEL_DEBUG, PSTR("TM7: TM1637Data.model_name %s CmndLevel barsToDisplay=%s"), TM1637Data.model_name, txt); + AddLog(LOG_LEVEL_DEBUG, PSTR("TM7: TM1637Data.model_name %s CmndTM1637Level barsToDisplay=%s"), TM1637Data.model_name, txt); char s[4]; ext_snprintf_P(s, sizeof(s), PSTR("%0_f"), &barsToDisplay); uint8_t numBars = atoi(s); AddLog(LOG_LEVEL_DEBUG, PSTR("TM7: CmndTM1637Level numBars %d"), numBars); - clearDisplay(); + TM1637ClearDisplay(); uint8_t rawBytes[1]; for(int i=1; i<=numBars; i++) { uint8_t digit = (i-1) / 2; @@ -580,7 +523,7 @@ bool CmndLevel(void) { * bit 1 is segment B etc. The function may either set the entire display * or any desired part using the length and position parameters. \*********************************************************************************************/ -bool CmndRaw(void) { +bool CmndTM1637Raw(void) { uint8_t DATA[6] = { 0, 0, 0, 0, 0, 0 }; char as[CMD_MAX_LEN]; @@ -656,7 +599,7 @@ bool CmndRaw(void) { * position parameters without affecting the rest of the display. * Command: DisplayText text [, position {0-(TM1637Data.num_digits-1)} [,length {1 to TM1637Data.num_digits}]] \*********************************************************************************************/ -bool CmndText(bool clear) { +bool CmndTM1637Text(bool clear) { char sString[CMD_MAX_LEN + 1]; char sPosition[CMD_MAX_LEN]; char sLength[CMD_MAX_LEN]; @@ -680,7 +623,7 @@ bool CmndText(bool clear) { AddLog(LOG_LEVEL_DEBUG, PSTR("TM7: sString %s, pos %d, len %d"), sString, position, length); - if(clear) clearDisplay(); + if(clear) TM1637ClearDisplay(); if(!length) length = strlen(sString); if((length < 0) || (length > TM1637Data.num_digits)) length = TM1637Data.num_digits; @@ -724,7 +667,7 @@ bool CmndText(bool clear) { * Sets brightness of the display. * Command: DisplayBrightness {1-8} \*********************************************************************************************/ -bool CmndBrightness(void) { +bool CmndTM1637Brightness(void) { uint16_t val = XdrvMailbox.payload; if(ArgC() == 0) { @@ -737,13 +680,13 @@ bool CmndBrightness(void) { return false; } TM1637Data.brightness = val; - setBrightness(TM1637Data.brightness); + TM1637SetBrightness(TM1637Data.brightness); return true; } -void setBrightness(uint8_t val) { +void TM1637SetBrightness(uint8_t val) { if((val < BRIGHTNESS_MIN) || (val > BRIGHTNESS_MAX)) val = 5; Settings.display_dimmer = val; if(TM1637Data.display_type == TM1637) tm1637display->setBacklight(val*10); @@ -760,7 +703,7 @@ void setBrightness(uint8_t val) { * DisplayClock 2 // 24-hour format * DisplayClock 0 // turn off clock and clear \*********************************************************************************************/ -bool CmndClock(void) { +bool CmndTM1637Clock(void) { TM1637Data.show_clock = XdrvMailbox.payload; @@ -770,7 +713,7 @@ bool CmndClock(void) { AddLog(LOG_LEVEL_DEBUG, PSTR("TM7: TM1637Data.show_clock %d, TM1637Data.clock_24 %d"), TM1637Data.show_clock, TM1637Data.clock_24); - clearDisplay(); + TM1637ClearDisplay(); return true; } @@ -778,7 +721,7 @@ bool CmndClock(void) { /*********************************************************************************************\ * refreshes the time if clock is displayed \*********************************************************************************************/ -void showTime() { +void TM1637ShowTime() { uint8_t hr = RtcTime.hour; uint8_t mn = RtcTime.minute; // uint8_t hr = 1; @@ -817,120 +760,10 @@ void showTime() { } - - -/*********************************************************************************************\ -* Sets all LEDs of the display. -* Command: DisplaySetLEDs {0-255} -\*********************************************************************************************/ -bool CmndSetLEDs(void) { - if(TM1637Data.display_type != TM1638) { - Response_P(PSTR("{\"Error\":\"Command not valid for TM1637Data.display_type %d\"}"), TM1637Data.display_type); - return false; - } - if(ArgC() == 0) XdrvMailbox.payload = 0; - uint16_t val = XdrvMailbox.payload; - if((val < LED_MIN) || (val > LED_MAX)) { - Response_P(PSTR("{\"Error\":\"Set LEDs value should be a number in the range [%d, %d]\"}"), LED_MIN, LED_MAX); - return false; - } - for(uint8_t i=0; i<8; i++) TM1637Data.LED[i] = ((val & 2^i) >> i); - tm1638display->setLEDs(val << 8); - return true; -} - - -/*********************************************************************************************\ -* Sets an TM1637Data.LED at specified position. -* Command: DisplaySetLED position {0-7}, value {0|1} -\*********************************************************************************************/ -bool CmndSetLED(void) { - if(TM1637Data.display_type != TM1638) { - Response_P(PSTR("{\"Error\":\"Command not valid for TM1637Data.display_type %d\"}"), TM1637Data.display_type); - return false; - } - if(ArgC() < 2) { - Response_P(PSTR("{\"Error\":\"Set LED requires two comma-separated numbers as arguments\"}")); - return false; - } - - char sVal[CMD_MAX_LEN]; - char sPos[CMD_MAX_LEN]; - uint32_t position = 0; - uint32_t value = 0; - - switch (ArgC()) - { - case 2 : - subStr(sVal, XdrvMailbox.data, ",", 2); - value = atoi(sVal); - case 1 : - subStr(sPos, XdrvMailbox.data, ",", 1); - position = atoi(sPos); - } - - - if((position < POSITION_MIN) || (position > POSITION_MAX)) { - Response_P(PSTR("{\"Error\":\"First argument, position should be in the range [%d, %d]\"}"), POSITION_MIN, POSITION_MAX); - return false; - } - - AddLog(LOG_LEVEL_DEBUG, PSTR("TM7: TM1637Data.model_name TM1638, position=%d, value %d"), position, value); - - TM1637Data.LED[position] = value; - tm1638display->setLED(position, value); - return true; -} - - -/*********************************************************************************************\ -* Reads the button states. Called every 50ms -\*********************************************************************************************/ -bool readButtons(void) { - TM1637Data.buttons = tm1638display->readButtons(); - if(TM1637Data.prev_buttons != TM1637Data.buttons) { - TM1637Data.prev_buttons = TM1637Data.buttons; - if(!TM1637Data.buttons) return true; - if(TM1637Data.buttons) { - for(int i=0; i<8; i++) { - if(TM1637Data.buttons & (1<setLED(i, TM1637Data.LED[i]); - Response_P(PSTR("{\"TM1638_BUTTON%d\":\"%s\"}"), i+1, (TM1637Data.LED[i]?PSTR("ON"):PSTR("OFF"))); - MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR("BUTTONS")); - } - } - } - } - return true; -} - -/*********************************************************************************************\ -* Returns the current state of the buttons as a decimal representation of the button states -* Command: DisplayButtons -\*********************************************************************************************/ -bool CmndButtons(void) { - if(TM1637Data.display_type != TM1638) { - Response_P(PSTR("{\"Error\":\"Command not valid for TM1637Data.display_type %d\"}"), TM1637Data.display_type); - return false; - } - AddLog(LOG_LEVEL_DEBUG, PSTR("TM7: TM1638: buttons=%d"), TM1637Data.buttons); - uint8_t byte = TM1637Data.LED[0]<<0 | TM1637Data.LED[1]<<1 | TM1637Data.LED[2]<<2 | TM1637Data.LED[3]<<3 | TM1637Data.LED[4]<<4 | TM1637Data.LED[5]<<5 | TM1637Data.LED[6]<<6 | TM1637Data.LED[7]<<7; - Response_P(PSTR("{\"DisplayButtons\": {\"S1\":%d, \"S2\":%d, \"S3\":%d, \"S4\":%d, \"S5\":%d, \"S6\":%d, \"S7\":%d, \"S8\":%d, \"Array\": [%d,%d,%d,%d,%d,%d,%d,%d], \"Byte\": %d}}"), - TM1637Data.LED[0], TM1637Data.LED[1], TM1637Data.LED[2], TM1637Data.LED[3], TM1637Data.LED[4], TM1637Data.LED[5], TM1637Data.LED[6], TM1637Data.LED[7], TM1637Data.LED[0], - TM1637Data.LED[1], TM1637Data.LED[2], TM1637Data.LED[3], TM1637Data.LED[4], TM1637Data.LED[5], TM1637Data.LED[6], TM1637Data.LED[7], byte); - return true; -} - - - - - /*********************************************************************************************\ * This function is called for all Display functions. \*********************************************************************************************/ -bool MainFunc(uint8_t fn) { +bool TM1637MainFunc(uint8_t fn) { bool result = false; if(XdrvMailbox.data_len > CMD_MAX_LEN) { @@ -940,52 +773,43 @@ bool MainFunc(uint8_t fn) { switch (fn) { case FUNC_DISPLAY_CLEAR: - result = CmndClear(); + result = CmndTM1637Clear(); break; case FUNC_DISPLAY_NUMBER : - result = CmndNumber(true); + result = CmndTM1637Number(true); break; case FUNC_DISPLAY_NUMBERNC : - result = CmndNumber(false); + result = CmndTM1637Number(false); break; case FUNC_DISPLAY_FLOAT : - result = CmndFloat(true); + result = CmndTM1637Float(true); break; case FUNC_DISPLAY_FLOATNC : - result = CmndFloat(false); + result = CmndTM1637Float(false); break; case FUNC_DISPLAY_BRIGHTNESS: - result = CmndBrightness(); + result = CmndTM1637Brightness(); break; case FUNC_DISPLAY_RAW: - result = CmndRaw(); + result = CmndTM1637Raw(); break; case FUNC_DISPLAY_SEVENSEG_TEXT: - result = CmndText(true); + result = CmndTM1637Text(true); break; case FUNC_DISPLAY_SEVENSEG_TEXTNC: - result = CmndText(false); + result = CmndTM1637Text(false); break; case FUNC_DISPLAY_LEVEL: - result = CmndLevel(); + result = CmndTM1637Level(); break; case FUNC_DISPLAY_SCROLLTEXT: - result = CmndScrollText(); + result = CmndTM1637ScrollText(); break; case FUNC_DISPLAY_SCROLLDELAY: - result = CmndScrollDelay(); + result = CmndTM1637ScrollDelay(); break; - case FUNC_DISPLAY_SETLEDS: - result = CmndSetLEDs(); - break; - case FUNC_DISPLAY_SETLED: - result = CmndSetLED(); - break; - case FUNC_DISPLAY_BUTTONS: - result = CmndButtons(); - break; - case FUNC_DISPLAY_CLOCK: - result = CmndClock(); + case FUNC_DISPLAY_CLOCK: + result = CmndTM1637Clock(); break; } @@ -1007,16 +831,12 @@ bool Xdsp15(uint8_t function) if (Settings.display_model == XDSP_15) { switch (function) { case FUNC_DISPLAY_INIT_DRIVER: - result = DriverInit(); // init + result = TM1637Init(); // init break; case FUNC_DISPLAY_INIT: AddLog(LOG_LEVEL_DEBUG, PSTR("TM7: %s: FUNC_DISPLAY_INIT: Display depends on TM1637Data.display_type, currently %d"), TM1637Data.model_name, Settings.display_options.data); result = true; break; - case FUNC_DISPLAY_TYPE: - AddLog(LOG_LEVEL_DEBUG, PSTR("TM7: %s: FUNC_DISPLAY_TYPE: TM1637Data.display_type set to %d, restarting to take effect ..."), TM1637Data.model_name, Settings.display_options.data); - TasmotaGlobal.restart_flag = 2; - break; case FUNC_DISPLAY_SEVENSEG_TEXT: case FUNC_DISPLAY_CLEAR: case FUNC_DISPLAY_NUMBER: @@ -1031,15 +851,11 @@ bool Xdsp15(uint8_t function) case FUNC_DISPLAY_CLOCK: TM1637Data.show_clock = false; case FUNC_DISPLAY_BRIGHTNESS: - case FUNC_DISPLAY_SETLEDS: - case FUNC_DISPLAY_SETLED: - case FUNC_DISPLAY_BUTTONS: - result = MainFunc(function); + result = TM1637MainFunc(function); break; case FUNC_DISPLAY_EVERY_50_MSECOND: - if(TM1637Data.scroll) scrollText(); - if(TM1637Data.show_clock) showTime(); - if(TM1637Data.display_type == TM1638) readButtons(); + if(TM1637Data.scroll) TM1637ScrollText(); + if(TM1637Data.show_clock) TM1637ShowTime(); break; } }