Add support for TM1637 seven segment display by Ajith Vasudevan (#10889)

This commit is contained in:
Theo Arends 2021-02-17 12:32:36 +01:00
parent a1a731001b
commit 14206e46a1
8 changed files with 109 additions and 112 deletions

View File

@ -210,6 +210,7 @@
| USE_DISPLAY_SSD1351 | - | - | - | - | - | - | x | | USE_DISPLAY_SSD1351 | - | - | - | - | - | - | x |
| USE_DISPLAY_RA8876 | - | - | - | - | - | - | x | | USE_DISPLAY_RA8876 | - | - | - | - | - | - | x |
| USE_DISPLAY_ST7789 | - | - | - | - | - | - | x | | USE_DISPLAY_ST7789 | - | - | - | - | - | - | x |
| USE_DISPLAY_TM1637 | - | - | - | - | - | - | x |
| | | | | | | | | | | | | | | | | |
| USE_FT5206 | - | - | - | - | - | - | - | | USE_FT5206 | - | - | - | - | - | - | - |
| USE_FTC532 | - | - | - | - | - | - | - | | USE_FTC532 | - | - | - | - | - | - | - |

View File

@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file.
- Berry file system support - Berry file system support
- Filesystem commands ``Ufs``, ``UfsType``, ``UfsSize``, ``UfsFree``, ``UfsDelete``, ``UfsRename`` and ``UfsRun`` - Filesystem commands ``Ufs``, ``UfsType``, ``UfsSize``, ``UfsFree``, ``UfsDelete``, ``UfsRename`` and ``UfsRun``
- Support for filesystem ``autoexec.bat`` to execute sequential commands like backlog - Support for filesystem ``autoexec.bat`` to execute sequential commands like backlog
- Support for TM1637 seven segment display by Ajith Vasudevan (#10889)
### Changed ### Changed
- IRremoteESP8266 library from v2.7.14 to v2.7.15 - IRremoteESP8266 library from v2.7.14 to v2.7.15

View File

@ -112,6 +112,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota
- Support for IR inverted leds using ``#define IR_SEND_INVERTED true`` [#10301](https://github.com/arendst/Tasmota/issues/10301) - Support for IR inverted leds using ``#define IR_SEND_INVERTED true`` [#10301](https://github.com/arendst/Tasmota/issues/10301)
- Support for disabling 38kHz IR modulation using ``#define IR_SEND_USE_MODULATION false`` [#10301](https://github.com/arendst/Tasmota/issues/10301) - Support for disabling 38kHz IR modulation using ``#define IR_SEND_USE_MODULATION false`` [#10301](https://github.com/arendst/Tasmota/issues/10301)
- Support for SPI display driver for ST7789 TFT by Gerhard Mutz [#9037](https://github.com/arendst/Tasmota/issues/9037) - Support for SPI display driver for ST7789 TFT by Gerhard Mutz [#9037](https://github.com/arendst/Tasmota/issues/9037)
- Support for TM1637 seven segment display by Ajith Vasudevan [#10889](https://github.com/arendst/Tasmota/issues/10889)
- Support for time proportioned (``#define USE_TIMEPROP``) and optional PID (``#define USE_PID``) relay control [#10412](https://github.com/arendst/Tasmota/issues/10412) - Support for time proportioned (``#define USE_TIMEPROP``) and optional PID (``#define USE_PID``) relay control [#10412](https://github.com/arendst/Tasmota/issues/10412)
- Support for 24/26/32/34 bit RFID Wiegand interface (D0/D1) by Sigurd Leuther [#3647](https://github.com/arendst/Tasmota/issues/3647) - Support for 24/26/32/34 bit RFID Wiegand interface (D0/D1) by Sigurd Leuther [#3647](https://github.com/arendst/Tasmota/issues/3647)
- Support for SM2135 current selection using GPIO ``SM2135 DAT`` index [#10634](https://github.com/arendst/Tasmota/issues/10634) - Support for SM2135 current selection using GPIO ``SM2135 DAT`` index [#10634](https://github.com/arendst/Tasmota/issues/10634)

View File

@ -635,13 +635,15 @@
// #define USE_DISPLAY_RA8876 // [DisplayModel 10] [I2cDriver39] (Touch) // #define USE_DISPLAY_RA8876 // [DisplayModel 10] [I2cDriver39] (Touch)
// #define USE_DISPLAY_ST7789 // [DisplayModel 12] Enable ST7789 module // #define USE_DISPLAY_ST7789 // [DisplayModel 12] Enable ST7789 module
// #define USE_DISPLAY_SSD1331 // [DisplayModel 14] Enable SSD1331 module // #define USE_DISPLAY_SSD1331 // [DisplayModel 14] Enable SSD1331 module
// #define USE_DISPLAY_TM1637 // [DisplayModel 15] Enable TM1637 module
// #define USE_RC522 // Add support for MFRC522 13.56Mhz Rfid reader (+6k code) // #define USE_RC522 // Add support for MFRC522 13.56Mhz Rfid reader (+6k code)
// #define USE_RC522_DATA_FUNCTION // Add support for reading data block content (+0k4 code) // #define USE_RC522_DATA_FUNCTION // Add support for reading data block content (+0k4 code)
// #define USE_RC522_TYPE_INFORMATION // Add support for showing card type (+0k4 code) // #define USE_RC522_TYPE_INFORMATION // Add support for showing card type (+0k4 code)
#endif // USE_SPI #endif // USE_SPI
//#define USE_DISPLAY // Add Display support
// #define USE_DISPLAY_TM1637 // [DisplayModel 15] Enable TM1637 module
// -- Serial sensors ------------------------------ // -- Serial sensors ------------------------------
//#define USE_MHZ19 // Add support for MH-Z19 CO2 sensor (+2k code) //#define USE_MHZ19 // Add support for MH-Z19 CO2 sensor (+2k code)
//#define USE_SENSEAIR // Add support for SenseAir K30, K70 and S8 CO2 sensor (+2k3 code) //#define USE_SENSEAIR // Add support for SenseAir K30, K70 and S8 CO2 sensor (+2k3 code)

View File

@ -715,7 +715,9 @@ void ResponseAppendFeatures(void)
#if defined(USE_ENERGY_SENSOR) && defined(USE_SDM72) #if defined(USE_ENERGY_SENSOR) && defined(USE_SDM72)
feature7 |= 0x20000000; // xnrg_18_sdm72.ino feature7 |= 0x20000000; // xnrg_18_sdm72.ino
#endif #endif
// feature7 |= 0x40000000; #if defined(USE_DISPLAY) && defined(USE_DISPLAY_TM1637)
feature7 |= 0x40000000;
#endif
// feature7 |= 0x80000000; // feature7 |= 0x80000000;
} }

View File

@ -301,26 +301,26 @@
#undef USE_BLE_ESP32 // (ESP32 only) Disable support for native BLE on ESP32 - use new driver #undef USE_BLE_ESP32 // (ESP32 only) Disable support for native BLE on ESP32 - use new driver
#undef USE_MI_ESP32 // (ESP32 only) Disable support for ESP32 as a BLE-bridge (+9k2 mem, +292k flash) #undef USE_MI_ESP32 // (ESP32 only) Disable support for ESP32 as a BLE-bridge (+9k2 mem, +292k flash)
#define USE_DISPLAY // Add Display Support (+2k code)
#define USE_DISPLAY_TM1637 // [DisplayModel 15] Enable TM1637 module
#define USE_I2C // I2C using library wire (+10k code, 0k2 mem, 124 iram) #define USE_I2C // I2C using library wire (+10k code, 0k2 mem, 124 iram)
#define USE_DISPLAY // Add I2C Display Support (+2k code) #define USE_DISPLAY_MODES1TO5 // Enable display mode 1 to 5 in addition to mode 0
#define USE_DISPLAY_MODES1TO5 // Enable display mode 1 to 5 in addition to mode 0 #define USE_DISPLAY_LCD // [DisplayModel 1] Enable Lcd display (I2C addresses 0x27 and 0x3F) (+6k code)
#define USE_DISPLAY_LCD // [DisplayModel 1] Enable Lcd display (I2C addresses 0x27 and 0x3F) (+6k code) #define USE_DISPLAY_SSD1306 // [DisplayModel 2] Enable SSD1306 Oled 128x64 display (I2C addresses 0x3C and 0x3D) (+16k code)
#define USE_DISPLAY_SSD1306 // [DisplayModel 2] Enable SSD1306 Oled 128x64 display (I2C addresses 0x3C and 0x3D) (+16k code) #define USE_DISPLAY_MATRIX // [DisplayModel 3] Enable 8x8 Matrix display (I2C adresseses see below) (+11k code)
#define USE_DISPLAY_MATRIX // [DisplayModel 3] Enable 8x8 Matrix display (I2C adresseses see below) (+11k code) #define USE_DISPLAY_SEVENSEG // [DisplayModel 11] [I2cDriver47] Enable sevenseg display (I2C addresses 0x70 - 0x77) (<+11k code)
#define USE_DISPLAY_SEVENSEG // [DisplayModel 11] [I2cDriver47] Enable sevenseg display (I2C addresses 0x70 - 0x77) (<+11k code) #define USE_DISPLAY_SH1106 // [DisplayModel 7] Enable SH1106 Oled 128x64 display (I2C addresses 0x3C and 0x3D)
#define USE_DISPLAY_SH1106 // [DisplayModel 7] Enable SH1106 Oled 128x64 display (I2C addresses 0x3C and 0x3D)
#define USE_SPI // Hardware SPI using GPIO12(MISO), GPIO13(MOSI) and GPIO14(CLK) in addition to two user selectable GPIOs(CS and DC) #define USE_SPI // Hardware SPI using GPIO12(MISO), GPIO13(MOSI) and GPIO14(CLK) in addition to two user selectable GPIOs(CS and DC)
#define USE_DISPLAY_ILI9341 // [DisplayModel 4] Enable ILI9341 Tft 480x320 display (+19k code) #define USE_DISPLAY_ILI9341 // [DisplayModel 4] Enable ILI9341 Tft 480x320 display (+19k code)
#define USE_DISPLAY_EPAPER_29 // [DisplayModel 5] Enable e-paper 2.9 inch display (+19k code) #define USE_DISPLAY_EPAPER_29 // [DisplayModel 5] Enable e-paper 2.9 inch display (+19k code)
#define USE_DISPLAY_EPAPER_42 // [DisplayModel 6] Enable e-paper 4.2 inch display #define USE_DISPLAY_EPAPER_42 // [DisplayModel 6] Enable e-paper 4.2 inch display
#define USE_DISPLAY_ILI9488 // [DisplayModel 8] #define USE_DISPLAY_ILI9488 // [DisplayModel 8]
#define USE_DISPLAY_SSD1351 // [DisplayModel 9] #define USE_DISPLAY_SSD1351 // [DisplayModel 9]
#define USE_DISPLAY_RA8876 // [DisplayModel 10] #define USE_DISPLAY_RA8876 // [DisplayModel 10]
#define USE_DISPLAY_ST7789 // [DisplayModel 12] Enable ST7789 module #define USE_DISPLAY_ST7789 // [DisplayModel 12] Enable ST7789 module
#define USE_DISPLAY_SSD1331 // [DisplayModel 14] Enable SSD1331 module #define USE_DISPLAY_SSD1331 // [DisplayModel 14] Enable SSD1331 module
#define USE_DISPLAY_TM1637 // [DisplayModel 15] Enable TM1637 module
#undef DEBUG_THEO // Disable debug code #undef DEBUG_THEO // Disable debug code
#undef USE_DEBUG_DRIVER // Disable debug code #undef USE_DEBUG_DRIVER // Disable debug code

View File

@ -1,7 +1,7 @@
/* /*
xdsp_15_tm1637.ino - Support for TM1637 seven-segment display (upto 6 digits) for Tasmota xdsp_15_tm1637.ino - Support for TM1637 seven-segment display (upto 6 digits) for Tasmota
Copyright (C) 2020 Ajith Vasudevan Copyright (C) 2021 Ajith Vasudevan
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -17,15 +17,15 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifdef USE_DISPLAY
/* #ifdef USE_DISPLAY_TM1637
/*********************************************************************************************\
This driver enables the display of numbers (both integers and floats) and basic text This driver enables the display of numbers (both integers and floats) and basic text
on the inexpensive TM1637-based seven-segment modules (tested on both 4- and 6-digit variants). on the inexpensive TM1637-based seven-segment modules (tested on both 4- and 6-digit variants).
Raw segments can also be displayed. Raw segments can also be displayed.
In addition, it is also possible to set brightness (8 levels), clear the display, scroll text, display In addition, it is also possible to set brightness (8 levels), clear the display, scroll text, display
a rudimentary bar graph, and a Clock (12 hr and 24 hr). a rudimentary bar graph, and a Clock (12 hr and 24 hr).
To use, compile Tasmota with USE_DISPLAY and USE_DISPLAY_TM1637, or build the tasmota-display env. To use, compile Tasmota with USE_DISPLAY and USE_DISPLAY_TM1637, or build the tasmota-display env.
The pins to use are "SSPI MOSI" and "SSPI SCLK". The pins to use are "SSPI MOSI" and "SSPI SCLK".
@ -43,16 +43,16 @@
DisplaySize size {1-6} DisplaySize size {1-6}
Sets the number of digits to use. This is typically set to the actual number of digits available Sets the number of digits to use. This is typically set to the actual number of digits available
in the display module. command e.g., "DisplaySize 6" in the display module. command e.g., "DisplaySize 6"
DisplayClear DisplayClear
Clears the display, command: "DisplayClear" Clears the display, command: "DisplayClear"
DisplayNumber num [,position {0-(NUM_DIGITS-1))} [,leading_zeros {0|1} [,length {1 to NUM_DIGITS}]]] DisplayNumber num [,position {0-(NUM_DIGITS-1))} [,leading_zeros {0|1} [,length {1 to NUM_DIGITS}]]]
Clears and then displays number without decimal. command e.g., "DisplayNumber 1234" Clears and then displays number without decimal. command e.g., "DisplayNumber 1234"
Control 'leading zeros', 'length' and 'position' with "DisplayNumber 1234, <position>, <leadingZeros>, <length>" Control 'leading zeros', 'length' and 'position' with "DisplayNumber 1234, <position>, <leadingZeros>, <length>"
'leading zeros' can be 1 or 0 (default), 'length' can be 1 to NUM_DIGITS, 'position' can be 0 (left-most) to NUM_DIGITS (right-most). 'leading zeros' can be 1 or 0 (default), 'length' can be 1 to NUM_DIGITS, 'position' can be 0 (left-most) to NUM_DIGITS (right-most).
@ -80,13 +80,13 @@
DisplayBrightness num {0-8} DisplayBrightness num {0-8}
Set brightness (0 (off) to 8) command e.g., "DisplayBrightness 2" Set brightness (0 (off) to 8) command e.g., "DisplayBrightness 2"
DisplayRaw position {0-(NUM_DIGITS-1)},length {1 to NUM_DIGITS}, num1 [, num2[, num3[, num4[, ...upto NUM_DIGITS numbers]]]]] DisplayRaw position {0-(NUM_DIGITS-1)},length {1 to NUM_DIGITS}, num1 [, num2[, num3[, num4[, ...upto NUM_DIGITS numbers]]]]]
Takes upto NUM_DIGITS comma-separated integers (0-255) and displays raw segments. Each number represents a Takes upto NUM_DIGITS comma-separated integers (0-255) and displays raw segments. Each number represents a
7-segment digit. Each 8-bit number represents individual segments of a digit. 7-segment digit. Each 8-bit number represents individual segments of a digit.
For example, the command "DisplayRaw 0, 4, 255, 255, 255, 255" would display "[8.8.8.8.]" For example, the command "DisplayRaw 0, 4, 255, 255, 255, 255" would display "[8.8.8.8.]"
@ -94,7 +94,7 @@
DisplayText text [, position {0-(NUM_DIGITS-1)} [,length {1 to NUM_DIGITS}]] DisplayText text [, position {0-(NUM_DIGITS-1)} [,length {1 to NUM_DIGITS}]]
Clears and then displays basic text. command e.g., "DisplayText ajith vasudevan" Clears and then displays basic text. command e.g., "DisplayText ajith vasudevan"
Control 'length' and 'position' with "DisplayText <text>, <position>, <length>" Control 'length' and 'position' with "DisplayText <text>, <position>, <length>"
'length' can be 1 to NUM_DIGITS, 'position' can be 0 (left-most) to NUM_DIGITS-1 (right-most) 'length' can be 1 to NUM_DIGITS, 'position' can be 0 (left-most) to NUM_DIGITS-1 (right-most)
A caret(^) symbol in the text input is dispayed as the degrees(°) symbol. This is useful for displaying Temperature! A caret(^) symbol in the text input is dispayed as the degrees(°) symbol. This is useful for displaying Temperature!
@ -109,7 +109,7 @@
DisplayScrollText text DisplayScrollText text
Displays scrolling text. Displays scrolling text.
@ -121,27 +121,17 @@
DisplayLevel num {0-100} DisplayLevel num {0-100}
Display a horizontal bar graph (0-100) command e.g., "DisplayLevel 50" will display [|||| ] Display a horizontal bar graph (0-100) command e.g., "DisplayLevel 50" will display [|||| ]
DisplayClock 1|2|0 DisplayClock 1|2|0
Displays a clock. Displays a clock.
Commands "DisplayClock 1" // 12 hr format Commands "DisplayClock 1" // 12 hr format
"DisplayClock 2" // 24 hr format "DisplayClock 2" // 24 hr format
"DisplayClock 0" // turn off clock "DisplayClock 0" // turn off clock
*/
#ifdef USE_DISPLAY
#ifdef USE_DISPLAY_TM1637
/*********************************************************************************************\
* TM1637 support
\*********************************************************************************************/ \*********************************************************************************************/
#define XDSP_15 15 #define XDSP_15 15
@ -189,13 +179,13 @@ bool TM1637Init(void) {
/*********************************************************************************************\ /*********************************************************************************************\
* Displays number without decimal, with/without leading zeros, specifying start-position * Displays number without decimal, with/without leading zeros, specifying start-position
* and length, optionally skipping clearing display before displaying the number. * and length, optionally skipping clearing display before displaying the number.
* commands: DisplayNumber num [,position {0-(NUM_DIGITS-1)} [,leading_zeros {0|1} [,length {1 to NUM_DIGITS}]]] * commands: DisplayNumber num [,position {0-(NUM_DIGITS-1)} [,leading_zeros {0|1} [,length {1 to NUM_DIGITS}]]]
* DisplayNumberNC num [,position {0-(NUM_DIGITS-1)} [,leading_zeros {0|1} [,length {1 to NUM_DIGITS}]]] // "NC" --> "No Clear" * DisplayNumberNC num [,position {0-(NUM_DIGITS-1)} [,leading_zeros {0|1} [,length {1 to NUM_DIGITS}]]] // "NC" --> "No Clear"
\*********************************************************************************************/ \*********************************************************************************************/
bool CmndTM1637Number(bool clear) { bool CmndTM1637Number(bool clear) {
char sNum[CMD_MAX_LEN]; char sNum[CMD_MAX_LEN];
char sLeadingzeros[CMD_MAX_LEN]; char sLeadingzeros[CMD_MAX_LEN];
char sPosition[CMD_MAX_LEN]; char sPosition[CMD_MAX_LEN];
char sLength[CMD_MAX_LEN]; char sLength[CMD_MAX_LEN];
uint8_t length = 0; uint8_t length = 0;
bool leadingzeros = false; bool leadingzeros = false;
@ -203,7 +193,7 @@ bool CmndTM1637Number(bool clear) {
uint32_t num = 0; uint32_t num = 0;
switch (ArgC()) switch (ArgC())
{ {
case 4 : case 4 :
subStr(sLength, XdrvMailbox.data, ",", 4); subStr(sLength, XdrvMailbox.data, ",", 4);
@ -227,10 +217,10 @@ bool CmndTM1637Number(bool clear) {
AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: leadingzeros=%d"), leadingzeros); AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: leadingzeros=%d"), leadingzeros);
AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: length=%d"), length); AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: length=%d"), length);
if(clear) clearDisplay(); if(clear) clearDisplay();
char txt[30]; char txt[30];
snprintf_P(txt, sizeof(txt), PSTR("%d"), num); snprintf_P(txt, sizeof(txt), PSTR("%d"), num);
if(!length) length = strlen(txt); if(!length) length = strlen(txt);
if((length < 0) || (length > NUM_DIGITS)) length = NUM_DIGITS; if((length < 0) || (length > NUM_DIGITS)) length = NUM_DIGITS;
@ -242,7 +232,7 @@ bool CmndTM1637Number(bool clear) {
if(i>NUM_DIGITS) break; if(i>NUM_DIGITS) break;
display->printRaw(rawBytes, 1, i); display->printRaw(rawBytes, 1, i);
} }
for(uint32_t j = 0; i< position + length; i++, j++) { for(uint32_t j = 0; i< position + length; i++, j++) {
if(txt[j] == 0) break; if(txt[j] == 0) break;
rawBytes[0] = display->encode(txt[j]); rawBytes[0] = display->encode(txt[j]);
@ -258,14 +248,14 @@ bool CmndTM1637Number(bool clear) {
/*********************************************************************************************\ /*********************************************************************************************\
* Displays number with decimal, specifying position, precision and length, * Displays number with decimal, specifying position, precision and length,
* optionally skipping clearing display before displaying the number. * optionally skipping clearing display before displaying the number.
* commands: DisplayFloat num [,position {0-(NUM_DIGITS-1)} [,precision {0-NUM_DIGITS} [,length {1 to NUM_DIGITS}]]] * commands: DisplayFloat num [,position {0-(NUM_DIGITS-1)} [,precision {0-NUM_DIGITS} [,length {1 to NUM_DIGITS}]]]
* DisplayFloatNC num [,position {0-(NUM_DIGITS-1)} [,precision {0-NUM_DIGITS} [,length {1 to NUM_DIGITS}]]] // "NC" --> "No Clear" * DisplayFloatNC num [,position {0-(NUM_DIGITS-1)} [,precision {0-NUM_DIGITS} [,length {1 to NUM_DIGITS}]]] // "NC" --> "No Clear"
\*********************************************************************************************/ \*********************************************************************************************/
bool CmndTM1637Float(bool clear) { bool CmndTM1637Float(bool clear) {
char sNum[CMD_MAX_LEN]; char sNum[CMD_MAX_LEN];
char sPrecision[CMD_MAX_LEN]; char sPrecision[CMD_MAX_LEN];
char sPosition[CMD_MAX_LEN]; char sPosition[CMD_MAX_LEN];
char sLength[CMD_MAX_LEN]; char sLength[CMD_MAX_LEN];
uint8_t length = 0; uint8_t length = 0;
uint8_t precision = NUM_DIGITS; uint8_t precision = NUM_DIGITS;
@ -273,7 +263,7 @@ bool CmndTM1637Float(bool clear) {
float fnum = 0.0f; float fnum = 0.0f;
switch (ArgC()) switch (ArgC())
{ {
case 4 : case 4 :
subStr(sLength, XdrvMailbox.data, ",", 4); subStr(sLength, XdrvMailbox.data, ",", 4);
@ -289,32 +279,32 @@ bool CmndTM1637Float(bool clear) {
fnum = atof(sNum); fnum = atof(sNum);
} }
if((position < 0) || (position > (NUM_DIGITS-1))) position = 0; if((position < 0) || (position > (NUM_DIGITS-1))) position = 0;
if((precision < 0) || (precision > NUM_DIGITS)) precision = NUM_DIGITS; if((precision < 0) || (precision > NUM_DIGITS)) precision = NUM_DIGITS;
if(clear) clearDisplay(); if(clear) clearDisplay();
char txt[30]; char txt[30];
ext_snprintf_P(txt, sizeof(txt), PSTR("%*_f"), precision, &fnum); ext_snprintf_P(txt, sizeof(txt), PSTR("%*_f"), precision, &fnum);
if(!length) length = strlen(txt); if(!length) length = strlen(txt);
if((length <= 0) || (length > NUM_DIGITS)) length = NUM_DIGITS; if((length <= 0) || (length > NUM_DIGITS)) length = NUM_DIGITS;
char s[30]; char s[30];
ext_snprintf_P(s, sizeof(s), PSTR("LOG: TM1637: num=%*_f"), 4, &fnum); ext_snprintf_P(s, sizeof(s), PSTR("LOG: TM1637: num=%*_f"), 4, &fnum);
AddLog(LOG_LEVEL_DEBUG, PSTR("%s"), s); AddLog(LOG_LEVEL_DEBUG, PSTR("%s"), s);
AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: precision=%d"), precision); AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: precision=%d"), precision);
AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: length=%d"), length); AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: length=%d"), length);
uint8_t rawBytes[1]; uint8_t rawBytes[1];
for(uint32_t i=0, j=0; i<length; i++, j++) { for(uint32_t i=0, j=0; i<length; i++, j++) {
if(txt[i] == 0) break; if(txt[i] == 0) break;
rawBytes[0] = display->encode(txt[i]); rawBytes[0] = display->encode(txt[i]);
if(txt[i+1] == '.') { if(txt[i+1] == '.') {
rawBytes[0] = rawBytes[0] | 128; rawBytes[0] = rawBytes[0] | 128;
i++; i++;
length++; length++;
} }
if((j+position) > NUM_DIGITS) break; if((j+position) > NUM_DIGITS) break;
display->printRaw(rawBytes, 1, j+position); display->printRaw(rawBytes, 1, j+position);
} }
@ -330,7 +320,7 @@ bool CmndTM1637Float(bool clear) {
bool CmndTM1637Clear(void) { bool CmndTM1637Clear(void) {
clearDisplay(); clearDisplay();
sprintf(msg, PSTR("Cleared")); sprintf(msg, PSTR("Cleared"));
XdrvMailbox.data = msg; XdrvMailbox.data = msg;
return true; return true;
} }
@ -344,7 +334,7 @@ void clearDisplay (void) {
/*********************************************************************************************\ /*********************************************************************************************\
* Display scrolling text * Display scrolling text
* Command: DisplayScrollText text * Command: DisplayScrollText text
\*********************************************************************************************/ \*********************************************************************************************/
bool CmndTM1637ScrollText(void) { bool CmndTM1637ScrollText(void) {
@ -372,7 +362,7 @@ bool CmndTM1637ScrollText(void) {
\*********************************************************************************************/ \*********************************************************************************************/
bool CmndTM1637ScrollDelay(void) { bool CmndTM1637ScrollDelay(void) {
if(scrolldelay<0) scrolldelay=0; if(scrolldelay<0) scrolldelay=0;
scrolldelay = XdrvMailbox.payload; scrolldelay = XdrvMailbox.payload;
return true; return true;
} }
@ -419,18 +409,18 @@ bool CmndTM1637Level(void) {
uint16_t val = XdrvMailbox.payload; uint16_t val = XdrvMailbox.payload;
if((val < LEVEL_MIN) || (val > LEVEL_MAX)) { if((val < LEVEL_MIN) || (val > LEVEL_MAX)) {
sprintf(msg, PSTR("Level should be a number in the range [%d, %d]"), LEVEL_MIN, LEVEL_MAX); sprintf(msg, PSTR("Level should be a number in the range [%d, %d]"), LEVEL_MIN, LEVEL_MAX);
XdrvMailbox.data = msg; XdrvMailbox.data = msg;
return false; return false;
} }
uint8_t totalBars = 2*NUM_DIGITS; uint8_t totalBars = 2*NUM_DIGITS;
AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: CmndTM1637Level totalBars=%d"), totalBars); AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: CmndTM1637Level totalBars=%d"), totalBars);
float barsToDisplay = totalBars * val / 100.0f; float barsToDisplay = totalBars * val / 100.0f;
char txt[5]; char txt[5];
ext_snprintf_P(txt, sizeof(txt), PSTR("%*_f"), 1, &barsToDisplay); ext_snprintf_P(txt, sizeof(txt), PSTR("%*_f"), 1, &barsToDisplay);
AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: CmndTM1637Level barsToDisplay=%s"), txt); AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: CmndTM1637Level barsToDisplay=%s"), txt);
char s[4]; char s[4];
ext_snprintf_P(s, sizeof(s), PSTR("%*_f"), 0, &barsToDisplay); ext_snprintf_P(s, sizeof(s), PSTR("%*_f"), 0, &barsToDisplay);
uint8_t numBars = atoi(s); uint8_t numBars = atoi(s);
AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: CmndTM1637Level numBars=%d"), numBars); AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: CmndTM1637Level numBars=%d"), numBars);
@ -452,28 +442,28 @@ bool CmndTM1637Level(void) {
* Display arbitrary data on the display module * Display arbitrary data on the display module
* Command: DisplayRaw position {0-(NUM_DIGITS-1)},length {1 to NUM_DIGITS}, a [, b[, c[, d[...upto NUM_DIGITS]]]] * Command: DisplayRaw position {0-(NUM_DIGITS-1)},length {1 to NUM_DIGITS}, a [, b[, c[, d[...upto NUM_DIGITS]]]]
* where a,b,c,d... are upto NUM_DIGITS numbers in the range 0-255, each number (byte) * where a,b,c,d... are upto NUM_DIGITS numbers in the range 0-255, each number (byte)
* corresponding to a single 7-segment digit. Within each byte, bit 0 is segment A, * corresponding to a single 7-segment digit. Within each byte, bit 0 is segment A,
* bit 1 is segment B etc. The function may either set the entire display * bit 1 is segment B etc. The function may either set the entire display
* or any desired part using the length and position parameters. * or any desired part using the length and position parameters.
\*********************************************************************************************/ \*********************************************************************************************/
bool CmndTM1637Raw(void) { bool CmndTM1637Raw(void) {
uint8_t DATA[6] = { 0, 0, 0, 0, 0, 0 }; uint8_t DATA[6] = { 0, 0, 0, 0, 0, 0 };
char as[CMD_MAX_LEN]; char as[CMD_MAX_LEN];
char bs[CMD_MAX_LEN]; char bs[CMD_MAX_LEN];
char cs[CMD_MAX_LEN]; char cs[CMD_MAX_LEN];
char ds[CMD_MAX_LEN]; char ds[CMD_MAX_LEN];
char es[CMD_MAX_LEN]; char es[CMD_MAX_LEN];
char fs[CMD_MAX_LEN]; char fs[CMD_MAX_LEN];
char sLength[CMD_MAX_LEN];
char sPos[CMD_MAX_LEN];
char sLength[CMD_MAX_LEN];
char sPos[CMD_MAX_LEN];
uint32_t position = 0; uint32_t position = 0;
uint32_t length = 0; uint32_t length = 0;
switch (ArgC()) switch (ArgC())
{ {
case 8 : case 8 :
subStr(fs, XdrvMailbox.data, ",", 8); subStr(fs, XdrvMailbox.data, ",", 8);
@ -519,7 +509,7 @@ bool CmndTM1637Raw(void) {
uint8_t rawBytes[1]; uint8_t rawBytes[1];
for(uint32_t i=position; i<position+length; i++ ) { for(uint32_t i=position; i<position+length; i++ ) {
if(i>(NUM_DIGITS-1)) break; if(i>(NUM_DIGITS-1)) break;
rawBytes[0] = DATA[i-position]; rawBytes[0] = DATA[i-position];
display->printRaw(rawBytes, 1, i); display->printRaw(rawBytes, 1, i);
} }
@ -529,19 +519,19 @@ bool CmndTM1637Raw(void) {
/*********************************************************************************************\ /*********************************************************************************************\
* Display a given string. * Display a given string.
* Text can be placed at arbitrary location on the display using the length and * Text can be placed at arbitrary location on the display using the length and
* position parameters without affecting the rest of the display. * position parameters without affecting the rest of the display.
* Command: DisplayText text [, position {0-(NUM_DIGITS-1)} [,length {1 to NUM_DIGITS}]] * Command: DisplayText text [, position {0-(NUM_DIGITS-1)} [,length {1 to NUM_DIGITS}]]
\*********************************************************************************************/ \*********************************************************************************************/
bool CmndTM1637Text(bool clear) { bool CmndTM1637Text(bool clear) {
char sString[CMD_MAX_LEN + 1]; char sString[CMD_MAX_LEN + 1];
char sPosition[CMD_MAX_LEN]; char sPosition[CMD_MAX_LEN];
char sLength[CMD_MAX_LEN]; char sLength[CMD_MAX_LEN];
uint8_t length = 0; uint8_t length = 0;
uint8_t position = 0; uint8_t position = 0;
switch (ArgC()) switch (ArgC())
{ {
case 3 : case 3 :
subStr(sLength, XdrvMailbox.data, ",", 3); subStr(sLength, XdrvMailbox.data, ",", 3);
@ -560,17 +550,17 @@ bool CmndTM1637Text(bool clear) {
AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: position=%d"), position); AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: position=%d"), position);
AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: length=%d"), length); AddLog(LOG_LEVEL_DEBUG, PSTR("LOG: TM1637: length=%d"), length);
if(clear) clearDisplay(); if(clear) clearDisplay();
if(!length) length = strlen(sString); if(!length) length = strlen(sString);
if((length < 0) || (length > NUM_DIGITS)) length = NUM_DIGITS; if((length < 0) || (length > NUM_DIGITS)) length = NUM_DIGITS;
uint32_t i = position; uint32_t i = position;
uint8_t rawBytes[1]; uint8_t rawBytes[1];
for(uint32_t j = 0; i< position + length; i++, j++) { for(uint32_t j = 0; i< position + length; i++, j++) {
if(i > (NUM_DIGITS-1)) break; if(i > (NUM_DIGITS-1)) break;
if(sString[j] == 0) break; if(sString[j] == 0) break;
rawBytes[0] = display->encode(sString[j]); rawBytes[0] = display->encode(sString[j]);
if(sString[j+1] == '.') { if(sString[j+1] == '.') {
rawBytes[0] = rawBytes[0] | 128; rawBytes[0] = rawBytes[0] | 128;
j++; j++;
@ -585,12 +575,12 @@ bool CmndTM1637Text(bool clear) {
/*********************************************************************************************\ /*********************************************************************************************\
* Sets brightness of the display. * Sets brightness of the display.
* Command: DisplayBrightness {0-8} // 0 => off * Command: DisplayBrightness {0-8} // 0 => off
\*********************************************************************************************/ \*********************************************************************************************/
bool CmndTM1637Brightness(void) { bool CmndTM1637Brightness(void) {
uint16_t val = XdrvMailbox.payload; uint16_t val = XdrvMailbox.payload;
if(ArgC() == 0) { if(ArgC() == 0) {
XdrvMailbox.payload = brightness; XdrvMailbox.payload = brightness;
return true; return true;
@ -599,10 +589,10 @@ bool CmndTM1637Brightness(void) {
if((val < BRIGHTNESS_MIN) || (val > BRIGHTNESS_MAX)) { if((val < BRIGHTNESS_MIN) || (val > BRIGHTNESS_MAX)) {
sprintf(msg, PSTR("Brightness should be a number in the range [%d, %d]"), BRIGHTNESS_MIN, BRIGHTNESS_MAX); sprintf(msg, PSTR("Brightness should be a number in the range [%d, %d]"), BRIGHTNESS_MIN, BRIGHTNESS_MAX);
XdrvMailbox.data = msg; XdrvMailbox.data = msg;
return false; return false;
} }
brightness = val; brightness = val;
display->setBacklight(brightness*10); display->setBacklight(brightness*10);
return true; return true;
} }
@ -656,9 +646,9 @@ void showTime() {
if(mn < 10) snprintf(tm, sizeof(tm), PSTR("%d0%d"), hr, mn); if(mn < 10) snprintf(tm, sizeof(tm), PSTR("%d0%d"), hr, mn);
else snprintf(tm, sizeof(tm), PSTR("%d%d"), hr, mn); else snprintf(tm, sizeof(tm), PSTR("%d%d"), hr, mn);
} }
uint8_t rawBytes[1]; uint8_t rawBytes[1];
for(uint32_t i = 0; i< 4; i++) { for(uint32_t i = 0; i< 4; i++) {
rawBytes[0] = display->encode(tm[i]); rawBytes[0] = display->encode(tm[i]);
if((millis() % 1000) > 500 && (i == 1)) rawBytes[0] = rawBytes[0] | 128; if((millis() % 1000) > 500 && (i == 1)) rawBytes[0] = rawBytes[0] | 128;
display->printRaw(rawBytes, 1, i); display->printRaw(rawBytes, 1, i);
} }
@ -682,8 +672,8 @@ bool TM1637Cmd(uint8_t fn) {
if(XdrvMailbox.data_len > CMD_MAX_LEN) { if(XdrvMailbox.data_len > CMD_MAX_LEN) {
sprintf(msg, PSTR("Command text too long. Please limit it to %d characters"), CMD_MAX_LEN); sprintf(msg, PSTR("Command text too long. Please limit it to %d characters"), CMD_MAX_LEN);
XdrvMailbox.data = msg; XdrvMailbox.data = msg;
return result; return result;
} }
switch (fn) { switch (fn) {
@ -691,16 +681,16 @@ bool TM1637Cmd(uint8_t fn) {
result = CmndTM1637Clear(); result = CmndTM1637Clear();
break; break;
case FUNC_DISPLAY_NUMBER : case FUNC_DISPLAY_NUMBER :
result = CmndTM1637Number(true); result = CmndTM1637Number(true);
break; break;
case FUNC_DISPLAY_NUMBERNC : case FUNC_DISPLAY_NUMBERNC :
result = CmndTM1637Number(false); result = CmndTM1637Number(false);
break; break;
case FUNC_DISPLAY_FLOAT : case FUNC_DISPLAY_FLOAT :
result = CmndTM1637Float(true); result = CmndTM1637Float(true);
break; break;
case FUNC_DISPLAY_FLOATNC : case FUNC_DISPLAY_FLOATNC :
result = CmndTM1637Float(false); result = CmndTM1637Float(false);
break; break;
case FUNC_DISPLAY_BRIGHTNESS: case FUNC_DISPLAY_BRIGHTNESS:
result = CmndTM1637Brightness(); result = CmndTM1637Brightness();
@ -719,7 +709,7 @@ bool TM1637Cmd(uint8_t fn) {
break; break;
case FUNC_DISPLAY_SCROLLTEXT: case FUNC_DISPLAY_SCROLLTEXT:
result = CmndTM1637ScrollText(); result = CmndTM1637ScrollText();
break; break;
case FUNC_DISPLAY_SCROLLDELAY: case FUNC_DISPLAY_SCROLLDELAY:
result = CmndTM1637ScrollDelay(); result = CmndTM1637ScrollDelay();
break; break;
@ -729,7 +719,7 @@ bool TM1637Cmd(uint8_t fn) {
} }
return result; return result;
} }
/*********************************************************************************************\ /*********************************************************************************************\
@ -741,7 +731,7 @@ bool Xdsp15(uint8_t function)
bool result = false; bool result = false;
if (FUNC_DISPLAY_INIT_DRIVER == function) { if (FUNC_DISPLAY_INIT_DRIVER == function) {
result = TM1637Init(); // init result = TM1637Init(); // init
} }
else if (XDSP_15 == Settings.display_model) { else if (XDSP_15 == Settings.display_model) {
switch (function) { switch (function) {
@ -773,7 +763,7 @@ bool Xdsp15(uint8_t function)
if(showClock) { if(showClock) {
showTime(); showTime();
} }
break; break;
} }
} }
return result; return result;

View File

@ -245,7 +245,7 @@ a_features = [[
"USE_DISPLAY_ILI9488","USE_DISPLAY_SSD1351","USE_DISPLAY_RA8876","USE_DISPLAY_ST7789", "USE_DISPLAY_ILI9488","USE_DISPLAY_SSD1351","USE_DISPLAY_RA8876","USE_DISPLAY_ST7789",
"USE_DISPLAY_SSD1331","USE_UFILESYS","USE_TIMEPROP","USE_PID", "USE_DISPLAY_SSD1331","USE_UFILESYS","USE_TIMEPROP","USE_PID",
"USE_BS814A2","USE_SEESAW_SOIL","USE_WIEGAND","USE_NEOPOOL", "USE_BS814A2","USE_SEESAW_SOIL","USE_WIEGAND","USE_NEOPOOL",
"USE_TOF10120","USE_SDM72","","" "USE_TOF10120","USE_SDM72","USE_DISPLAY_TM1637",""
],[ ],[
"","","","", "","","","",
"","","","", "","","","",
@ -282,7 +282,7 @@ else:
obj = json.load(fp) obj = json.load(fp)
def StartDecode(): def StartDecode():
print ("\n*** decode-status.py v20210122 by Theo Arends and Jacek Ziolkowski ***") print ("\n*** decode-status.py v20210217 by Theo Arends and Jacek Ziolkowski ***")
# print("Decoding\n{}".format(obj)) # print("Decoding\n{}".format(obj))