2021-02-10 16:23:47 +00:00
/*
2021-02-18 17:14:15 +00:00
xdsp_15_tm1637 . ino - Support for TM1637 - and TM1638 - based seven - segment displays for Tasmota
2021-02-10 16:23:47 +00:00
2021-02-17 11:32:36 +00:00
Copyright ( C ) 2021 Ajith Vasudevan
2021-02-10 16:23:47 +00:00
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
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
2021-02-17 11:32:36 +00:00
# ifdef USE_DISPLAY
2022-04-11 13:30:35 +01:00
# if defined(USE_DISPLAY_TM1637) || defined(USE_DISPLAY_MAX7219)
2021-02-17 11:32:36 +00:00
/*********************************************************************************************\
This driver enables the display of numbers ( both integers and floats ) and basic text
2021-03-19 17:00:06 +00:00
on the inexpensive TM1637 - , TM1638 - and MAX7219 - based seven - segment modules .
2021-03-19 09:15:50 +00:00
2021-02-16 12:12:49 +00:00
Raw segments can also be displayed .
2021-03-19 09:15:50 +00:00
In addition , it is also possible to set brightness ( 8 levels ) , clear the display , scroll text ,
2021-02-18 17:14:15 +00:00
display a rudimentary bar graph , and a Clock ( 12 hr and 24 hr ) .
2021-02-17 11:32:36 +00:00
2021-02-14 11:22:08 +00:00
To use , compile Tasmota with USE_DISPLAY and USE_DISPLAY_TM1637 , or build the tasmota - display env .
2021-02-22 06:00:11 +00:00
For TM1637 :
Connect the TM1637 display module ' s pins to any free GPIOs of the ESP8266 module
2021-02-14 11:22:08 +00:00
and assign the pins as follows from Tasmota ' s GUI :
2021-02-22 06:00:11 +00:00
DIO hardware pin - - > " TM1637 DIO "
CLK hardware pin - - > " TM1637 CLK "
2021-02-14 11:22:08 +00:00
2021-02-22 06:00:11 +00:00
For TM1638 :
Connect the TM1638 display module ' s pins to any free GPIOs of the ESP8266 module
and assign the pins as follows from Tasmota ' s GUI :
2021-02-14 11:22:08 +00:00
2021-02-22 06:00:11 +00:00
DIO hardware pin - - > " TM1638 DIO "
CLK hardware pin - - > " TM1638 CLK "
STB hardware pin - - > " TM1638 STB "
2021-02-14 11:22:08 +00:00
2021-03-19 17:00:06 +00:00
For MAX7219 :
Connect the MAX7219 display module ' s pins to any free GPIOs of the ESP8266 module
and assign the pins as follows from Tasmota ' s GUI :
DIN hardware pin - - > " MAX7219 DIN "
CS hardware pin - - > " MAX7219 CS "
CLK hardware pin - - > " MAX7219 CLK "
2021-03-19 09:15:50 +00:00
2021-03-22 11:47:15 +00:00
Once the GPIO configuration is saved and the ESP8266 / ESP32 module restarts ,
2021-03-19 17:00:06 +00:00
set the Display Model to 15 and Display Mode to 0
using the command " Backlog DisplayModel 15 ; DisplayMode 0 "
2021-03-19 09:15:50 +00:00
2021-03-20 03:35:19 +00:00
If your display is a TM1637 with 6 digits , set Display Width to the number of digits your
display has , using the command " DisplayWidth 6 " .
2021-03-19 09:15:50 +00:00
2021-03-20 03:35:19 +00:00
After the ESP8266 / ESP32 module restarts again , turn ON the display with the command " Power 1 "
2021-03-22 11:47:15 +00:00
2021-03-20 03:35:19 +00:00
Now , the following " Display " commands can be used :
2021-03-19 09:15:50 +00:00
2021-02-16 12:12:49 +00:00
2021-02-14 11:22:08 +00:00
DisplayClear
2021-02-17 11:32:36 +00:00
2021-02-16 12:12:49 +00:00
Clears the display , command : " DisplayClear "
2021-02-14 11:22:08 +00:00
2021-06-11 17:14:12 +01:00
DisplayNumber num [ , position { 0 - ( Settings - > display_width - 1 ) ) } [ , leading_zeros { 0 | 1 } [ , length { 1 to Settings - > display_width } ] ] ]
2021-02-17 11:32:36 +00:00
2021-02-16 12:12:49 +00:00
Clears and then displays number without decimal . command e . g . , " DisplayNumber 1234 "
Control ' leading zeros ' , ' length ' and ' position ' with " DisplayNumber 1234, <position>, <leadingZeros>, <length> "
2021-06-11 17:14:12 +01:00
' leading zeros ' can be 1 or 0 ( default ) , ' length ' can be 1 to Settings - > display_width , ' position ' can be 0 ( left - most ) to Settings - > display_width ( right - most ) .
2021-02-16 12:12:49 +00:00
See function description below for more details .
2021-06-11 17:14:12 +01:00
DisplayNumberNC num [ , position { 0 - ( Settings - > display_width - 1 ) ) } [ , leading_zeros { 0 | 1 } [ , length { 1 to Settings - > display_width } ] ] ]
2021-02-16 12:12:49 +00:00
2021-02-14 11:22:08 +00:00
Display integer number as above , but without clearing first . e . g . , " DisplayNumberNC 1234 " . Usage is same as above .
2021-02-16 12:12:49 +00:00
2021-06-11 17:14:12 +01:00
DisplayFloat num [ , position { 0 - ( Settings - > display_width - 1 ) } [ , precision { 0 - Settings - > display_width } [ , length { 1 to Settings - > display_width } ] ] ]
2021-02-16 12:12:49 +00:00
Clears and then displays float ( with decimal point ) command e . g . , " DisplayFloat 12.34 "
2021-02-14 11:22:08 +00:00
See function description below for more details .
2021-02-16 12:12:49 +00:00
2021-06-11 17:14:12 +01:00
DisplayFloatNC num [ , position { 0 - ( Settings - > display_width - 1 ) } [ , precision { 0 - Settings - > display_width } [ , length { 1 to Settings - > display_width } ] ] ]
2021-02-16 12:12:49 +00:00
2021-02-14 11:22:08 +00:00
Displays float ( with decimal point ) as above , but without clearing first . command e . g . , " DisplayFloatNC 12.34 "
See function description below for more details .
2021-02-16 12:12:49 +00:00
2021-06-11 17:14:12 +01:00
DisplayRaw position { 0 - ( Settings - > display_width - 1 ) } , length { 1 to Settings - > display_width } , num1 [ , num2 [ , num3 [ , num4 [ , . . . upto Settings - > display_width numbers ] ] ] ] ]
2021-02-16 12:12:49 +00:00
2021-06-11 17:14:12 +01:00
Takes upto Settings - > display_width comma - separated integers ( 0 - 255 ) and displays raw segments . Each number represents a
2021-02-16 12:12:49 +00:00
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.] "
2021-06-11 17:14:12 +01:00
DisplayText text [ , position { 0 - ( Settings - > display_width - 1 ) } [ , length { 1 to Settings - > display_width } ] ]
2021-02-16 12:12:49 +00:00
2021-02-17 11:32:36 +00:00
Clears and then displays basic text . command e . g . , " DisplayText ajith vasudevan "
2021-02-16 12:12:49 +00:00
Control ' length ' and ' position ' with " DisplayText <text>, <position>, <length> "
2021-06-11 17:14:12 +01:00
' length ' can be 1 to Settings - > display_width , ' position ' can be 0 ( left - most ) to Settings - > display_width - 1 ( right - most )
2021-02-17 10:54:45 +00:00
A caret ( ^ ) symbol in the text input is dispayed as the degrees ( ° ) symbol . This is useful for displaying Temperature !
For example , the command " DisplayText 22.5^ " will display " 22.5° " .
2021-02-16 12:12:49 +00:00
2021-06-11 17:14:12 +01:00
DisplayTextNC text [ , position { 0 - Settings - > display_width - 1 } [ , length { 1 to Settings - > display_width } ] ]
2021-02-16 12:12:49 +00:00
Clears first , then displays text . Usage is same as above .
2021-09-06 14:56:01 +01:00
DisplayScrollText text [ , num_loops ]
2021-02-16 12:12:49 +00:00
2021-09-06 14:56:01 +01:00
Displays scrolling text indefinitely , until another Display - command ( other than DisplayScrollText
or DisplayScrollDelay is issued ) . Optionally , stop scrolling after num_loops iterations .
2021-02-16 12:12:49 +00:00
DisplayScrollDelay delay { 0 - 15 } // default = 4
Sets the speed of text scroll . Smaller delay = faster scrolling .
2021-02-14 11:22:08 +00:00
DisplayLevel num { 0 - 100 }
2021-02-17 11:32:36 +00:00
Display a horizontal bar graph ( 0 - 100 ) command e . g . , " DisplayLevel 50 " will display [ | | | | ]
2021-02-14 11:22:08 +00:00
2021-02-17 11:32:36 +00:00
DisplayClock 1 | 2 | 0
2021-02-16 12:12:49 +00:00
2021-02-17 11:32:36 +00:00
Displays a clock .
2021-02-14 11:22:08 +00:00
Commands " DisplayClock 1 " // 12 hr format
" DisplayClock 2 " // 24 hr format
" DisplayClock 0 " // turn off clock
2021-02-18 17:14:15 +00:00
2021-03-22 11:47:15 +00:00
In addition , setting DisplayMode to 1 shows the time , setting it to 2 shows the date
2021-03-19 17:00:06 +00:00
and setting it to 3 alternates between time and date .
2021-02-18 17:14:15 +00:00
2021-02-10 16:23:47 +00:00
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-03-19 17:00:06 +00:00
# define XDSP_15 15
# define CMD_MAX_LEN 55
# define LEVEL_MIN 0
# define LEVEL_MAX 100
# define SCROLL_MAX_LEN 50
# define POSITION_MIN 0
# define POSITION_MAX 8
# define LED_MIN 0
# define LED_MAX 255
# define MAX7219_ADDR 0
2021-02-16 12:12:49 +00:00
2021-02-10 16:23:47 +00:00
2021-02-21 11:17:39 +00:00
# include "SevenSegmentTM1637.h"
2021-02-22 06:00:11 +00:00
# include <TM1638plus.h>
2021-03-19 17:00:06 +00:00
# include <LedControl.h>
2021-02-22 06:00:11 +00:00
2021-02-21 13:33:51 +00:00
SevenSegmentTM1637 * tm1637display ;
2021-02-22 06:00:11 +00:00
TM1638plus * tm1638display ;
2021-03-19 17:00:06 +00:00
LedControl * max7219display ;
2021-02-22 06:00:11 +00:00
2021-03-19 17:00:06 +00:00
enum display_types
{
TM1637 ,
TM1638 ,
MAX7219
} ;
2021-02-21 11:17:39 +00:00
2021-03-19 17:00:06 +00:00
struct
{
2021-02-21 11:17:39 +00:00
char scroll_text [ CMD_MAX_LEN ] ;
char msg [ 60 ] ;
2021-02-22 06:00:11 +00:00
char model_name [ 8 ] ;
2021-02-21 11:17:39 +00:00
uint8_t scroll_delay = 4 ;
uint8_t scroll_index = 0 ;
uint8_t iteration = 0 ;
2021-09-06 14:56:01 +01:00
uint8_t scroll_counter = 0 ;
uint8_t scroll_counter_max = 3 ;
2021-02-22 06:00:11 +00:00
uint8_t display_type = TM1637 ;
2021-03-22 11:47:15 +00:00
uint8_t digit_order [ 6 ] = { 0 , 1 , 2 , 3 , 4 , 5 } ;
2021-02-21 11:17:39 +00:00
2021-03-19 09:15:50 +00:00
bool init_done = false ;
2021-02-21 11:17:39 +00:00
bool scroll = false ;
bool show_clock = false ;
bool clock_24 = false ;
} TM1637Data ;
2021-02-10 16:23:47 +00:00
/*********************************************************************************************\
* Init function
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-02-22 06:00:11 +00:00
2021-03-19 17:00:06 +00:00
void TM1637Init ( void )
{
if ( PinUsed ( GPIO_TM1638CLK ) & & PinUsed ( GPIO_TM1638DIO ) & & PinUsed ( GPIO_TM1638STB ) )
{
2021-03-18 14:00:50 +00:00
TM1637Data . display_type = TM1638 ;
2021-06-11 17:14:12 +01:00
Settings - > display_width = 8 ;
2021-03-19 09:15:50 +00:00
}
2021-03-19 17:00:06 +00:00
else if ( PinUsed ( GPIO_TM1637CLK ) & & PinUsed ( GPIO_TM1637DIO ) )
{
2021-03-19 09:15:50 +00:00
TM1637Data . display_type = TM1637 ;
2021-06-11 17:14:12 +01:00
if ( ( ! Settings - > display_width | | Settings - > display_width > 6 ) )
2021-03-19 17:00:06 +00:00
{
2021-06-11 17:14:12 +01:00
Settings - > display_width = 4 ;
Settings - > display_options . type = 0 ;
2021-03-19 09:15:50 +00:00
}
2021-03-22 11:47:15 +00:00
TM1637SetDigitOrder ( ) ;
2021-03-19 09:15:50 +00:00
}
2021-03-19 17:00:06 +00:00
else if ( PinUsed ( GPIO_MAX7219DIN ) & & PinUsed ( GPIO_MAX7219CLK ) & & PinUsed ( GPIO_MAX7219CS ) )
{
TM1637Data . display_type = MAX7219 ;
2022-04-10 23:33:47 +01:00
if ( Settings - > display_width )
{
Settings - > display_width = ( Settings - > display_width / 8 ) * 8 ;
}
else
{
Settings - > display_width = 8 ;
}
2021-03-19 17:00:06 +00:00
}
else
{
2021-03-19 09:15:50 +00:00
return ;
2021-02-18 17:14:15 +00:00
}
2021-03-18 14:00:50 +00:00
2021-06-11 17:14:12 +01:00
Settings - > display_model = XDSP_15 ;
Settings - > display_cols [ 0 ] = Settings - > display_width ;
Settings - > display_height = 1 ;
Settings - > display_rows = Settings - > display_height ;
2021-09-14 21:40:26 +01:00
uint8_t dimmer16 = GetDisplayDimmer16 ( ) ;
if ( ! dimmer16 | | dimmer16 < 2 | | dimmer16 > 15 ) SetDisplayDimmer ( 50 ) ;
2021-03-18 14:00:50 +00:00
2021-03-19 17:00:06 +00:00
if ( TM1637 = = TM1637Data . display_type )
{
2021-03-19 09:15:50 +00:00
strcpy_P ( TM1637Data . model_name , PSTR ( " TM1637 " ) ) ;
2021-03-18 14:00:50 +00:00
tm1637display = new SevenSegmentTM1637 ( Pin ( GPIO_TM1637CLK ) , Pin ( GPIO_TM1637DIO ) ) ;
2021-06-11 17:14:12 +01:00
tm1637display - > begin ( Settings - > display_width , 1 ) ;
2021-03-19 09:15:50 +00:00
}
2021-03-19 17:00:06 +00:00
else if ( TM1638 = = TM1637Data . display_type )
{
2021-03-19 09:15:50 +00:00
strcpy_P ( TM1637Data . model_name , PSTR ( " TM1638 " ) ) ;
2021-03-19 17:00:06 +00:00
tm1638display = new TM1638plus ( Pin ( GPIO_TM1638STB ) , Pin ( GPIO_TM1638CLK ) , Pin ( GPIO_TM1638DIO ) , true ) ;
2021-03-18 14:00:50 +00:00
tm1638display - > displayBegin ( ) ;
}
2021-03-19 17:00:06 +00:00
else if ( MAX7219 = = TM1637Data . display_type )
{
strcpy_P ( TM1637Data . model_name , PSTR ( " MAX7219 " ) ) ;
2022-04-10 23:33:47 +01:00
max7219display = new LedControl ( Pin ( GPIO_MAX7219DIN ) , Pin ( GPIO_MAX7219CLK ) , Pin ( GPIO_MAX7219CS ) , Settings - > display_width / 8 ) ;
2022-04-11 11:48:44 +01:00
for ( uint8_t dev_addr = 0 ; dev_addr < Settings - > display_width / 8 ; dev_addr + + )
2022-04-10 23:33:47 +01:00
{
max7219display - > shutdown ( MAX7219_ADDR + dev_addr , false ) ;
}
2021-03-19 17:00:06 +00:00
}
2021-03-18 14:00:50 +00:00
TM1637ClearDisplay ( ) ;
2021-03-19 13:24:26 +00:00
TM1637Dim ( ) ;
2021-03-19 09:15:50 +00:00
TM1637Data . init_done = true ;
2021-06-11 17:14:12 +01:00
AddLog ( LOG_LEVEL_INFO , PSTR ( " DSP: %s with %d digits (type %d) " ) , TM1637Data . model_name , Settings - > display_width , Settings - > display_options . type ) ;
2021-02-10 16:23:47 +00:00
}
2021-03-19 17:00:06 +00:00
// Function to display specified ascii char at specified position for MAX7219
void displayMAX7219ASCII ( uint8_t pos , char c )
{
2022-04-10 23:33:47 +01:00
max7219display - > setChar ( MAX7219_ADDR + ( pos / 8 ) , 7 - ( pos % 8 ) , c , false ) ;
2021-03-19 17:00:06 +00:00
}
// Function to display specified ascii char with dot at specified position for MAX7219
void displayMAX7219ASCIIwDot ( uint8_t pos , char c )
{
2022-04-10 23:33:47 +01:00
max7219display - > setChar ( MAX7219_ADDR + ( pos / 8 ) , 7 - ( pos % 8 ) , c , true ) ;
2021-03-19 17:00:06 +00:00
}
// Function to display raw segments at specified position for MAX7219
void displayMAX72197Seg ( uint8_t pos , uint8_t seg )
{
bool dec_bit = seg & 128 ;
seg = seg < < 1 ;
seg = seg | dec_bit ;
uint8_t NO_OF_BITS = 8 ;
uint8_t reverse_num = 0 ;
for ( uint8_t i = 0 ; i < NO_OF_BITS ; i + + )
{
if ( ( seg & ( 1 < < i ) ) )
reverse_num | = 1 < < ( ( NO_OF_BITS - 1 ) - i ) ;
}
seg = reverse_num ;
2022-04-10 23:33:47 +01:00
max7219display - > setRow ( MAX7219_ADDR + ( pos / 8 ) , 7 - ( pos % 8 ) , seg ) ;
2021-03-19 17:00:06 +00:00
}
2021-03-22 11:47:15 +00:00
// Function to fix order of hardware digits for different TM1637 variants
void TM1637SetDigitOrder ( void ) {
2021-06-11 17:14:12 +01:00
if ( 0 = = Settings - > display_options . type ) {
2021-03-22 11:47:15 +00:00
for ( uint32_t i = 0 ; i < 6 ; i + + ) {
TM1637Data . digit_order [ i ] = i ;
}
}
2021-06-11 17:14:12 +01:00
else if ( 1 = = Settings - > display_options . type ) {
2021-03-22 11:47:15 +00:00
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 ;
}
}
2021-02-10 16:23:47 +00:00
/*********************************************************************************************\
2021-02-16 12:12:49 +00:00
* Displays number without decimal , with / without leading zeros , specifying start - position
* and length , optionally skipping clearing display before displaying the number .
2021-06-11 17:14:12 +01:00
* commands : DisplayNumber num [ , position { 0 - ( Settings - > display_width - 1 ) } [ , leading_zeros { 0 | 1 } [ , length { 1 to Settings - > display_width } ] ] ]
* DisplayNumberNC num [ , position { 0 - ( Settings - > display_width - 1 ) } [ , leading_zeros { 0 | 1 } [ , length { 1 to Settings - > display_width } ] ] ] // "NC" --> "No Clear"
2021-02-10 16:23:47 +00:00
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-03-19 17:00:06 +00:00
bool CmndTM1637Number ( bool clear )
{
2021-02-17 11:32:36 +00:00
char sNum [ CMD_MAX_LEN ] ;
2021-02-16 12:12:49 +00:00
char sLeadingzeros [ CMD_MAX_LEN ] ;
2021-02-17 11:32:36 +00:00
char sPosition [ CMD_MAX_LEN ] ;
2021-02-16 12:12:49 +00:00
char sLength [ CMD_MAX_LEN ] ;
uint8_t length = 0 ;
2021-02-14 11:22:08 +00:00
bool leadingzeros = false ;
2021-02-16 12:12:49 +00:00
uint8_t position = 0 ;
uint32_t num = 0 ;
2021-02-10 16:23:47 +00:00
2021-02-17 11:32:36 +00:00
switch ( ArgC ( ) )
2021-02-10 16:23:47 +00:00
{
2021-03-19 17:00:06 +00:00
case 4 :
subStr ( sLength , XdrvMailbox . data , " , " , 4 ) ;
length = atoi ( sLength ) ;
case 3 :
subStr ( sLeadingzeros , XdrvMailbox . data , " , " , 3 ) ;
leadingzeros = atoi ( sLeadingzeros ) ;
case 2 :
subStr ( sPosition , XdrvMailbox . data , " , " , 2 ) ;
position = atoi ( sPosition ) ;
case 1 :
subStr ( sNum , XdrvMailbox . data , " , " , 1 ) ;
num = atof ( sNum ) ;
2021-02-10 16:23:47 +00:00
}
2021-02-16 12:12:49 +00:00
2021-06-11 17:14:12 +01:00
if ( ( position < 0 ) | | ( position > ( Settings - > display_width - 1 ) ) )
2021-03-19 17:00:06 +00:00
position = 0 ;
2021-02-10 16:23:47 +00:00
2021-02-21 11:17:39 +00:00
AddLog ( LOG_LEVEL_DEBUG , PSTR ( " TM7: num %d, pos %d, lead %d, len %d " ) , num , position , leadingzeros , length ) ;
2021-02-10 16:23:47 +00:00
2021-03-19 17:00:06 +00:00
if ( clear )
TM1637ClearDisplay ( ) ;
2021-02-16 12:12:49 +00:00
char txt [ 30 ] ;
2021-02-17 11:32:36 +00:00
snprintf_P ( txt , sizeof ( txt ) , PSTR ( " %d " ) , num ) ;
2021-03-19 17:00:06 +00:00
if ( ! length )
length = strlen ( txt ) ;
2021-06-11 17:14:12 +01:00
if ( ( length < 0 ) | | ( length > Settings - > display_width ) )
length = Settings - > display_width ;
2021-02-16 12:12:49 +00:00
2021-03-19 17:00:06 +00:00
char pad = ( leadingzeros ? ' 0 ' : ' ' ) ;
2021-02-16 12:12:49 +00:00
uint32_t i = position ;
uint8_t rawBytes [ 1 ] ;
2021-02-18 17:14:15 +00:00
2021-03-19 17:00:06 +00:00
for ( ; i < position + ( length - strlen ( txt ) ) ; i + + )
{
2021-06-11 17:14:12 +01:00
if ( i > Settings - > display_width )
2021-03-19 17:00:06 +00:00
break ;
if ( TM1637 = = TM1637Data . display_type )
{
rawBytes [ 0 ] = tm1637display - > encode ( pad ) ;
2021-03-22 11:47:15 +00:00
tm1637display - > printRaw ( rawBytes , 1 , TM1637Data . digit_order [ i ] ) ;
2021-03-19 17:00:06 +00:00
}
else if ( TM1638 = = TM1637Data . display_type )
tm1638display - > displayASCII ( i , pad ) ;
else if ( MAX7219 = = TM1637Data . display_type )
{
2022-04-10 23:33:47 +01:00
if ( i > Settings - > display_width - 1 )
2021-03-19 17:00:06 +00:00
break ;
displayMAX7219ASCII ( i , pad ) ;
}
2021-02-16 12:12:49 +00:00
}
2021-02-17 11:32:36 +00:00
2021-03-19 17:00:06 +00:00
for ( uint32_t j = 0 ; i < position + length ; i + + , j + + )
{
2021-06-11 17:14:12 +01:00
if ( i > Settings - > display_width )
2021-03-19 17:00:06 +00:00
break ;
if ( txt [ j ] = = 0 )
break ;
if ( TM1637 = = TM1637Data . display_type )
{
rawBytes [ 0 ] = tm1637display - > encode ( txt [ j ] ) ;
2021-03-22 11:47:15 +00:00
tm1637display - > printRaw ( rawBytes , 1 , TM1637Data . digit_order [ i ] ) ;
2021-03-19 17:00:06 +00:00
}
else if ( TM1638 = = TM1637Data . display_type )
tm1638display - > displayASCII ( i , txt [ j ] ) ;
else if ( MAX7219 = = TM1637Data . display_type )
{
2022-04-10 23:33:47 +01:00
if ( i > Settings - > display_width - 1 )
2021-03-19 17:00:06 +00:00
break ;
if ( txt [ j ] = = 0 )
break ;
displayMAX7219ASCII ( i , txt [ j ] ) ;
}
2021-02-16 12:12:49 +00:00
}
2021-02-10 16:23:47 +00:00
return true ;
}
/*********************************************************************************************\
2021-02-16 12:12:49 +00:00
* Displays number with decimal , specifying position , precision and length ,
2021-02-10 16:23:47 +00:00
* optionally skipping clearing display before displaying the number .
2021-06-11 17:14:12 +01:00
* commands : DisplayFloat num [ , position { 0 - ( Settings - > display_width - 1 ) } [ , precision { 0 - Settings - > display_width } [ , length { 1 to Settings - > display_width } ] ] ]
* DisplayFloatNC num [ , position { 0 - ( Settings - > display_width - 1 ) } [ , precision { 0 - Settings - > display_width } [ , length { 1 to Settings - > display_width } ] ] ] // "NC" --> "No Clear"
2021-02-10 16:23:47 +00:00
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-03-19 17:00:06 +00:00
bool CmndTM1637Float ( bool clear )
{
2021-02-10 16:23:47 +00:00
2021-02-17 11:32:36 +00:00
char sNum [ CMD_MAX_LEN ] ;
2021-02-16 12:12:49 +00:00
char sPrecision [ CMD_MAX_LEN ] ;
2021-02-17 11:32:36 +00:00
char sPosition [ CMD_MAX_LEN ] ;
2021-02-14 11:22:08 +00:00
char sLength [ CMD_MAX_LEN ] ;
2021-02-16 12:12:49 +00:00
uint8_t length = 0 ;
2021-06-11 17:14:12 +01:00
uint8_t precision = Settings - > display_width ;
2021-02-16 12:12:49 +00:00
uint8_t position = 0 ;
2021-02-14 11:22:08 +00:00
2021-02-10 16:23:47 +00:00
float fnum = 0.0f ;
2021-02-17 11:32:36 +00:00
switch ( ArgC ( ) )
2021-02-10 16:23:47 +00:00
{
2021-03-19 17:00:06 +00:00
case 4 :
subStr ( sLength , XdrvMailbox . data , " , " , 4 ) ;
length = atoi ( sLength ) ;
case 3 :
subStr ( sPrecision , XdrvMailbox . data , " , " , 3 ) ;
precision = atoi ( sPrecision ) ;
case 2 :
subStr ( sPosition , XdrvMailbox . data , " , " , 2 ) ;
position = atoi ( sPosition ) ;
case 1 :
subStr ( sNum , XdrvMailbox . data , " , " , 1 ) ;
fnum = atof ( sNum ) ;
2021-02-10 16:23:47 +00:00
}
2021-02-16 12:12:49 +00:00
2021-06-11 17:14:12 +01:00
if ( ( position < 0 ) | | ( position > ( Settings - > display_width - 1 ) ) )
2021-03-19 17:00:06 +00:00
position = 0 ;
2021-06-11 17:14:12 +01:00
if ( ( precision < 0 ) | | ( precision > Settings - > display_width ) )
precision = Settings - > display_width ;
2021-02-17 11:32:36 +00:00
2021-03-19 17:00:06 +00:00
if ( clear )
TM1637ClearDisplay ( ) ;
2021-02-16 12:12:49 +00:00
char txt [ 30 ] ;
2021-02-17 11:32:36 +00:00
ext_snprintf_P ( txt , sizeof ( txt ) , PSTR ( " %*_f " ) , precision , & fnum ) ;
2021-03-19 17:00:06 +00:00
if ( ! length )
length = strlen ( txt ) ;
2021-06-11 17:14:12 +01:00
if ( ( length < = 0 ) | | ( length > Settings - > display_width ) )
length = Settings - > display_width ;
2021-02-10 16:23:47 +00:00
2021-02-21 11:17:39 +00:00
AddLog ( LOG_LEVEL_DEBUG , PSTR ( " TM7: num %4_f, prec %d, len %d " ) , & fnum , precision , length ) ;
2021-02-18 17:14:15 +00:00
2021-03-19 17:00:06 +00:00
if ( TM1637 = = TM1637Data . display_type )
{
2021-02-18 17:14:15 +00:00
uint8_t rawBytes [ 1 ] ;
2021-03-19 17:00:06 +00:00
for ( uint32_t i = 0 , j = 0 ; i < length ; i + + , j + + )
{
if ( txt [ i ] = = 0 )
break ;
2021-02-22 06:00:11 +00:00
rawBytes [ 0 ] = tm1637display - > encode ( txt [ i ] ) ;
2021-03-19 17:00:06 +00:00
if ( txt [ i + 1 ] = = ' . ' )
{
2021-02-18 17:14:15 +00:00
rawBytes [ 0 ] = rawBytes [ 0 ] | 128 ;
i + + ;
length + + ;
}
2021-06-11 17:14:12 +01:00
if ( ( j + position ) > Settings - > display_width )
2021-03-19 17:00:06 +00:00
break ;
2021-03-22 11:47:15 +00:00
tm1637display - > printRaw ( rawBytes , 1 , TM1637Data . digit_order [ j + position ] ) ;
2021-03-19 17:00:06 +00:00
}
}
else if ( TM1638 = = TM1637Data . display_type )
{
for ( uint32_t i = 0 , j = 0 ; i < length ; i + + , j + + )
{
if ( ( j + position ) > 7 )
break ;
if ( txt [ i ] = = 0 )
break ;
if ( txt [ i + 1 ] = = ' . ' )
{
tm1638display - > displayASCIIwDot ( j + position , txt [ i ] ) ;
i + + ;
length + + ;
}
else
tm1638display - > displayASCII ( j + position , txt [ i ] ) ;
}
}
else if ( MAX7219 = = TM1637Data . display_type )
{
for ( uint32_t i = 0 , j = 0 ; i < length ; i + + , j + + )
{
2022-04-10 23:33:47 +01:00
if ( ( j + position ) > Settings - > display_width - 1 )
2021-03-19 17:00:06 +00:00
break ;
if ( txt [ i ] = = 0 )
break ;
if ( txt [ i + 1 ] = = ' . ' )
{
displayMAX7219ASCIIwDot ( j + position , txt [ i ] ) ;
2021-02-18 17:14:15 +00:00
i + + ;
length + + ;
}
2021-03-19 17:00:06 +00:00
else
displayMAX7219ASCII ( j + position , txt [ i ] ) ;
2021-02-17 11:32:36 +00:00
}
2021-02-18 17:14:15 +00:00
}
2021-02-10 16:23:47 +00:00
return true ;
}
2021-02-16 12:12:49 +00:00
/ / /*********************************************************************************************\
// * Clears the display
// * Command: DisplayClear
// \*********************************************************************************************/
2021-03-19 17:00:06 +00:00
bool CmndTM1637Clear ( void )
{
2021-03-18 14:00:50 +00:00
TM1637ClearDisplay ( ) ;
2021-02-21 11:17:39 +00:00
sprintf ( TM1637Data . msg , PSTR ( " Cleared " ) ) ;
XdrvMailbox . data = TM1637Data . msg ;
2021-02-10 16:23:47 +00:00
return true ;
}
2021-02-18 17:14:15 +00:00
/ / /*********************************************************************************************\
// * Clears the display
// \*********************************************************************************************/
2021-03-19 17:00:06 +00:00
void TM1637ClearDisplay ( void )
{
if ( TM1637 = = TM1637Data . display_type )
{
unsigned char arr [ ] = { 0 } ;
2021-06-11 17:14:12 +01:00
for ( int i = 0 ; i < Settings - > display_width ; i + + )
2021-03-19 17:00:06 +00:00
tm1637display - > printRaw ( arr , 1 , i ) ;
}
else if ( TM1638 = = TM1637Data . display_type )
{
2021-06-11 17:14:12 +01:00
for ( int i = 0 ; i < Settings - > display_width ; i + + )
2021-03-19 17:00:06 +00:00
tm1638display - > display7Seg ( i , 0 ) ;
}
else if ( MAX7219 = = TM1637Data . display_type )
{
2022-04-11 11:48:44 +01:00
for ( uint8_t dev_addr = 0 ; dev_addr < Settings - > display_width / 8 ; dev_addr + + )
2022-04-10 23:33:47 +01:00
{
max7219display - > clearDisplay ( MAX7219_ADDR + dev_addr ) ;
}
2021-02-18 17:14:15 +00:00
}
2021-02-16 12:12:49 +00:00
}
/*********************************************************************************************\
* Display scrolling text
2021-02-22 06:00:11 +00:00
* Command : DisplayTM1637Data . scroll_text text
2021-02-16 12:12:49 +00:00
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-03-19 17:00:06 +00:00
bool CmndTM1637ScrollText ( void )
{
2021-02-16 12:12:49 +00:00
2021-09-06 14:56:01 +01:00
char sString [ SCROLL_MAX_LEN + 1 ] ;
char sMaxLoopCount [ CMD_MAX_LEN ] ;
uint8_t maxLoopCount = 0 ;
2021-02-16 12:12:49 +00:00
2021-09-06 14:56:01 +01:00
switch ( ArgC ( ) )
{
case 2 :
subStr ( sMaxLoopCount , XdrvMailbox . data , " , " , 2 ) ;
maxLoopCount = atoi ( sMaxLoopCount ) ;
case 1 :
subStr ( sString , XdrvMailbox . data , " , " , 1 ) ;
}
if ( maxLoopCount < 0 )
maxLoopCount = 0 ;
AddLog ( LOG_LEVEL_DEBUG , PSTR ( " TM7: sString %s, maxLoopCount %d " ) , sString , maxLoopCount ) ;
TM1637Data . scroll_counter_max = maxLoopCount ;
if ( strlen ( sString ) > SCROLL_MAX_LEN )
2021-03-19 17:00:06 +00:00
{
2021-02-21 11:17:39 +00:00
snprintf ( TM1637Data . msg , sizeof ( TM1637Data . msg ) , PSTR ( " Text too long. Length should be less than %d " ) , SCROLL_MAX_LEN ) ;
XdrvMailbox . data = TM1637Data . msg ;
2021-02-16 12:12:49 +00:00
return false ;
2021-03-19 17:00:06 +00:00
}
else
{
2021-09-06 14:56:01 +01:00
snprintf ( TM1637Data . scroll_text , sizeof ( TM1637Data . scroll_text ) , PSTR ( " " ) ) ;
snprintf ( TM1637Data . scroll_text , Settings - > display_width + sizeof ( TM1637Data . scroll_text ) , PSTR ( " %s " ) , & sString ) ;
TM1637Data . scroll_text [ strlen ( sString ) + Settings - > display_width ] = 0 ;
2021-02-21 11:17:39 +00:00
TM1637Data . scroll_index = 0 ;
TM1637Data . scroll = true ;
2021-09-06 14:56:01 +01:00
TM1637Data . scroll_counter = 0 ;
2021-02-16 12:12:49 +00:00
return true ;
}
}
/*********************************************************************************************\
* Sets the scroll delay for scrolling text .
2021-02-22 06:00:11 +00:00
* Command : DisplayTM1637Data . scroll_delay delay { 0 - 15 } // default = 4
2021-02-16 12:12:49 +00:00
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-03-19 17:00:06 +00:00
bool CmndTM1637ScrollDelay ( void )
{
if ( ArgC ( ) = = 0 )
{
2021-02-23 07:22:05 +00:00
XdrvMailbox . payload = TM1637Data . scroll_delay ;
return true ;
}
2021-03-19 17:00:06 +00:00
if ( TM1637Data . scroll_delay < 0 )
TM1637Data . scroll_delay = 0 ;
2021-02-21 11:17:39 +00:00
TM1637Data . scroll_delay = XdrvMailbox . payload ;
2021-02-16 12:12:49 +00:00
return true ;
}
/*********************************************************************************************\
* Scrolls a given string . Called every 50 ms
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-03-19 17:00:06 +00:00
void TM1637ScrollText ( void )
{
2021-09-06 14:56:01 +01:00
if ( ! TM1637Data . scroll ) return ;
2021-02-22 06:00:11 +00:00
TM1637Data . iteration + + ;
2021-03-19 17:00:06 +00:00
if ( TM1637Data . scroll_delay )
TM1637Data . iteration = TM1637Data . iteration % TM1637Data . scroll_delay ;
else
TM1637Data . iteration = 0 ;
if ( TM1637Data . iteration )
return ;
2021-02-22 06:00:11 +00:00
2021-03-19 17:00:06 +00:00
if ( TM1637Data . scroll_index > strlen ( TM1637Data . scroll_text ) )
{
2021-02-22 06:00:11 +00:00
TM1637Data . scroll_index = 0 ;
2021-09-06 14:56:01 +01:00
TM1637Data . scroll_counter + + ;
if ( TM1637Data . scroll_counter_max ! = 0 & & ( TM1637Data . scroll_counter > = TM1637Data . scroll_counter_max ) ) {
TM1637Data . scroll = false ;
return ;
}
2021-02-18 17:14:15 +00:00
}
uint8_t rawBytes [ 1 ] ;
2021-03-19 17:00:06 +00:00
for ( uint32_t i = 0 , j = TM1637Data . scroll_index ; i < 1 + strlen ( TM1637Data . scroll_text ) ; i + + , j + + )
{
2021-06-11 17:14:12 +01:00
if ( i > ( Settings - > display_width - 1 ) )
2021-03-19 17:00:06 +00:00
{
break ;
}
2021-02-23 07:22:05 +00:00
rawBytes [ 0 ] = tm1637display - > encode ( TM1637Data . scroll_text [ j ] ) ;
bool dotSkipped = false ;
2021-03-19 17:00:06 +00:00
if ( TM1637Data . scroll_text [ j + 1 ] = = ' . ' )
{
2021-02-23 07:22:05 +00:00
dotSkipped = true ;
rawBytes [ 0 ] = rawBytes [ 0 ] | 128 ;
j + + ;
2021-03-19 17:00:06 +00:00
}
else if ( TM1637Data . scroll_text [ j ] = = ' ^ ' )
{
2021-02-23 07:22:05 +00:00
rawBytes [ 0 ] = 1 | 2 | 32 | 64 ;
}
2021-03-19 17:00:06 +00:00
if ( ! dotSkipped & & TM1637Data . scroll_text [ j ] = = ' . ' )
{
2021-03-19 09:15:50 +00:00
j + + ;
TM1637Data . scroll_index + + ;
2021-02-23 07:22:05 +00:00
rawBytes [ 0 ] = tm1637display - > encode ( TM1637Data . scroll_text [ j ] ) ;
}
2021-03-19 17:00:06 +00:00
if ( TM1637Data . scroll_text [ j + 1 ] = = ' . ' )
{
rawBytes [ 0 ] = rawBytes [ 0 ] | 128 ;
}
if ( TM1637 = = TM1637Data . display_type )
{
2021-03-22 11:47:15 +00:00
tm1637display - > printRaw ( rawBytes , 1 , TM1637Data . digit_order [ i ] ) ;
2021-03-19 17:00:06 +00:00
}
else if ( TM1638 = = TM1637Data . display_type )
{
2021-02-23 07:22:05 +00:00
tm1638display - > display7Seg ( i , rawBytes [ 0 ] ) ;
2021-02-16 12:12:49 +00:00
}
2021-03-19 17:00:06 +00:00
else if ( MAX7219 = = TM1637Data . display_type )
{
displayMAX72197Seg ( i , rawBytes [ 0 ] ) ;
}
2021-02-16 12:12:49 +00:00
}
2021-02-22 06:00:11 +00:00
TM1637Data . scroll_index + + ;
2021-02-16 12:12:49 +00:00
}
2021-02-10 16:23:47 +00:00
/*********************************************************************************************\
* Displays a horizontal bar graph . Takes a percentage number ( 0 - 100 ) as input
* Command : DisplayLevel level { 0 - 100 }
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-03-19 17:00:06 +00:00
bool CmndTM1637Level ( void )
{
2021-02-10 16:23:47 +00:00
uint16_t val = XdrvMailbox . payload ;
2021-03-19 17:00:06 +00:00
if ( ( val < LEVEL_MIN ) | | ( val > LEVEL_MAX ) )
{
2021-02-19 09:58:16 +00:00
Response_P ( PSTR ( " { \" Error \" : \" Level should be a number in the range [%d, %d] \" } " ) , LEVEL_MIN , LEVEL_MAX ) ;
2021-02-17 11:32:36 +00:00
return false ;
}
2021-02-16 12:12:49 +00:00
2021-06-11 17:14:12 +01:00
uint8_t totalBars = 2 * Settings - > display_width ;
2021-03-18 14:00:50 +00:00
AddLog ( LOG_LEVEL_DEBUG , PSTR ( " TM7: TM1637Data.model_name %s CmndTM1637Level totalBars=%d " ) , TM1637Data . model_name , totalBars ) ;
2021-02-16 12:12:49 +00:00
float barsToDisplay = totalBars * val / 100.0f ;
char txt [ 5 ] ;
2021-02-17 11:32:36 +00:00
ext_snprintf_P ( txt , sizeof ( txt ) , PSTR ( " %*_f " ) , 1 , & barsToDisplay ) ;
2021-03-18 14:00:50 +00:00
AddLog ( LOG_LEVEL_DEBUG , PSTR ( " TM7: TM1637Data.model_name %s CmndTM1637Level barsToDisplay=%s " ) , TM1637Data . model_name , txt ) ;
2021-02-16 12:12:49 +00:00
char s [ 4 ] ;
2021-02-21 11:17:39 +00:00
ext_snprintf_P ( s , sizeof ( s ) , PSTR ( " %0_f " ) , & barsToDisplay ) ;
2021-02-16 12:12:49 +00:00
uint8_t numBars = atoi ( s ) ;
2021-02-21 11:17:39 +00:00
AddLog ( LOG_LEVEL_DEBUG , PSTR ( " TM7: CmndTM1637Level numBars %d " ) , numBars ) ;
2021-02-16 12:12:49 +00:00
2021-03-18 14:00:50 +00:00
TM1637ClearDisplay ( ) ;
2021-02-16 12:12:49 +00:00
uint8_t rawBytes [ 1 ] ;
2021-03-19 17:00:06 +00:00
for ( int i = 1 ; i < = numBars ; i + + )
{
uint8_t digit = ( i - 1 ) / 2 ;
uint8_t value = ( ( ( i % 2 ) = = 0 ) ? 54 : 48 ) ;
if ( TM1637 = = TM1637Data . display_type )
{
2021-02-18 17:14:15 +00:00
rawBytes [ 0 ] = value ;
2021-03-22 11:47:15 +00:00
tm1637display - > printRaw ( rawBytes , 1 , TM1637Data . digit_order [ digit ] ) ;
2021-03-19 17:00:06 +00:00
}
else if ( TM1638 = = TM1637Data . display_type )
{
2021-02-22 06:00:11 +00:00
tm1638display - > display7Seg ( digit , value ) ;
2021-02-18 17:14:15 +00:00
}
2021-03-19 17:00:06 +00:00
else if ( MAX7219 = = TM1637Data . display_type )
{
displayMAX72197Seg ( digit , value ) ;
}
2021-02-16 12:12:49 +00:00
}
2021-02-10 16:23:47 +00:00
return true ;
}
/*********************************************************************************************\
* Display arbitrary data on the display module
2021-06-11 17:14:12 +01:00
* Command : DisplayRaw position { 0 - ( Settings - > display_width - 1 ) } , length { 1 to Settings - > display_width } , a [ , b [ , c [ , d [ . . . upto Settings - > display_width ] ] ] ]
* where a , b , c , d . . . are upto Settings - > display_width numbers in the range 0 - 255 , each number ( byte )
2021-02-17 11:32:36 +00:00
* 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
2021-02-16 12:12:49 +00:00
* or any desired part using the length and position parameters .
2021-02-10 16:23:47 +00:00
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-03-19 17:00:06 +00:00
bool CmndTM1637Raw ( void )
{
uint8_t DATA [ 6 ] = { 0 , 0 , 0 , 0 , 0 , 0 } ;
2021-02-10 16:23:47 +00:00
2021-02-17 11:32:36 +00:00
char as [ CMD_MAX_LEN ] ;
char bs [ CMD_MAX_LEN ] ;
char cs [ CMD_MAX_LEN ] ;
char ds [ CMD_MAX_LEN ] ;
char es [ CMD_MAX_LEN ] ;
char fs [ CMD_MAX_LEN ] ;
char sLength [ CMD_MAX_LEN ] ;
char sPos [ CMD_MAX_LEN ] ;
2021-02-16 12:12:49 +00:00
2021-02-10 16:23:47 +00:00
uint32_t position = 0 ;
2021-02-16 12:12:49 +00:00
uint32_t length = 0 ;
2021-02-10 16:23:47 +00:00
2021-02-17 11:32:36 +00:00
switch ( ArgC ( ) )
2021-02-10 16:23:47 +00:00
{
2021-03-19 17:00:06 +00:00
case 8 :
subStr ( fs , XdrvMailbox . data , " , " , 8 ) ;
DATA [ 5 ] = atoi ( fs ) ;
case 7 :
subStr ( es , XdrvMailbox . data , " , " , 7 ) ;
DATA [ 4 ] = atoi ( es ) ;
case 6 :
subStr ( ds , XdrvMailbox . data , " , " , 6 ) ;
DATA [ 3 ] = atoi ( ds ) ;
case 5 :
subStr ( cs , XdrvMailbox . data , " , " , 5 ) ;
DATA [ 2 ] = atoi ( cs ) ;
case 4 :
subStr ( bs , XdrvMailbox . data , " , " , 4 ) ;
DATA [ 1 ] = atoi ( bs ) ;
case 3 :
subStr ( as , XdrvMailbox . data , " , " , 3 ) ;
DATA [ 0 ] = atoi ( as ) ;
case 2 :
subStr ( sLength , XdrvMailbox . data , " , " , 2 ) ;
length = atoi ( sLength ) ;
case 1 :
subStr ( sPos , XdrvMailbox . data , " , " , 1 ) ;
position = atoi ( sPos ) ;
}
if ( ! length )
length = ArgC ( ) - 2 ;
2021-06-11 17:14:12 +01:00
if ( length < 0 | | length > Settings - > display_width )
length = Settings - > display_width ;
if ( position < 0 | | position > ( Settings - > display_width - 1 ) )
2021-03-19 17:00:06 +00:00
position = 0 ;
2021-02-16 12:12:49 +00:00
2021-02-21 11:17:39 +00:00
AddLog ( LOG_LEVEL_DEBUG , PSTR ( " TM7: a %d, b %d, c %d, d %d, e %d, f %d, len %d, pos %d " ) ,
2021-03-19 17:00:06 +00:00
DATA [ 0 ] , DATA [ 1 ] , DATA [ 2 ] , DATA [ 3 ] , DATA [ 4 ] , DATA [ 5 ] , length , position ) ;
2021-02-16 12:12:49 +00:00
2021-03-19 17:00:06 +00:00
if ( TM1637 = = TM1637Data . display_type )
{
2021-02-18 17:14:15 +00:00
uint8_t rawBytes [ 1 ] ;
2021-03-19 17:00:06 +00:00
for ( uint32_t i = position ; i < position + length ; i + + )
{
2021-06-11 17:14:12 +01:00
if ( i > ( Settings - > display_width - 1 ) )
2021-03-19 17:00:06 +00:00
break ;
rawBytes [ 0 ] = DATA [ i - position ] ;
2021-03-22 11:47:15 +00:00
tm1637display - > printRaw ( rawBytes , 1 , TM1637Data . digit_order [ i ] ) ;
2021-03-19 09:15:50 +00:00
}
2021-03-19 17:00:06 +00:00
}
else if ( TM1638 = = TM1637Data . display_type )
{
for ( uint32_t i = position ; i < position + length ; i + + )
{
if ( i > 7 )
break ;
tm1638display - > display7Seg ( i , DATA [ i - position ] ) ;
}
}
else if ( MAX7219 = = TM1637Data . display_type )
{
for ( uint32_t i = position ; i < position + length ; i + + )
{
2022-04-10 23:33:47 +01:00
if ( i > Settings - > display_width - 1 )
2021-03-19 17:00:06 +00:00
break ;
displayMAX72197Seg ( i , DATA [ i - position ] ) ;
2021-02-18 17:14:15 +00:00
}
2021-02-16 12:12:49 +00:00
}
2021-02-10 16:23:47 +00:00
return true ;
}
/*********************************************************************************************\
2021-02-17 11:32:36 +00:00
* Display a given string .
* Text can be placed at arbitrary location on the display using the length and
2021-02-10 16:23:47 +00:00
* position parameters without affecting the rest of the display .
2021-06-11 17:14:12 +01:00
* Command : DisplayText text [ , position { 0 - ( Settings - > display_width - 1 ) } [ , length { 1 to Settings - > display_width } ] ]
2021-02-10 16:23:47 +00:00
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-03-19 17:00:06 +00:00
bool CmndTM1637Text ( bool clear )
{
2021-02-17 11:32:36 +00:00
char sString [ CMD_MAX_LEN + 1 ] ;
char sPosition [ CMD_MAX_LEN ] ;
2021-02-16 12:12:49 +00:00
char sLength [ CMD_MAX_LEN ] ;
uint8_t length = 0 ;
uint8_t position = 0 ;
2021-02-14 11:22:08 +00:00
2021-02-17 11:32:36 +00:00
switch ( ArgC ( ) )
2021-02-10 16:23:47 +00:00
{
2021-03-19 17:00:06 +00:00
case 3 :
subStr ( sLength , XdrvMailbox . data , " , " , 3 ) ;
length = atoi ( sLength ) ;
case 2 :
subStr ( sPosition , XdrvMailbox . data , " , " , 2 ) ;
position = atoi ( sPosition ) ;
case 1 :
subStr ( sString , XdrvMailbox . data , " , " , 1 ) ;
2021-02-10 16:23:47 +00:00
}
2021-06-11 17:14:12 +01:00
if ( ( position < 0 ) | | ( position > ( Settings - > display_width - 1 ) ) )
2021-03-19 17:00:06 +00:00
position = 0 ;
2021-02-16 12:12:49 +00:00
2021-02-21 11:17:39 +00:00
AddLog ( LOG_LEVEL_DEBUG , PSTR ( " TM7: sString %s, pos %d, len %d " ) , sString , position , length ) ;
2021-02-10 16:23:47 +00:00
2021-03-19 17:00:06 +00:00
if ( clear )
TM1637ClearDisplay ( ) ;
2021-02-16 12:12:49 +00:00
2021-03-19 17:00:06 +00:00
if ( ! length )
length = strlen ( sString ) ;
2021-06-11 17:14:12 +01:00
if ( ( length < 0 ) | | ( length > Settings - > display_width ) )
length = Settings - > display_width ;
2021-02-16 12:12:49 +00:00
uint32_t i = position ;
2021-03-19 17:00:06 +00:00
if ( TM1637 = = TM1637Data . display_type )
{
2021-02-18 17:14:15 +00:00
uint8_t rawBytes [ 1 ] ;
2021-03-19 17:00:06 +00:00
for ( uint32_t j = 0 ; i < position + length ; i + + , j + + )
{
2021-06-11 17:14:12 +01:00
if ( i > ( Settings - > display_width - 1 ) )
2021-03-19 17:00:06 +00:00
break ;
if ( sString [ j ] = = 0 )
break ;
2021-02-22 06:00:11 +00:00
rawBytes [ 0 ] = tm1637display - > encode ( sString [ j ] ) ;
2021-02-23 07:22:05 +00:00
bool dotSkipped = false ;
2021-03-19 17:00:06 +00:00
if ( sString [ j + 1 ] = = ' . ' )
{
2021-02-23 07:22:05 +00:00
dotSkipped = true ;
2021-02-18 17:14:15 +00:00
rawBytes [ 0 ] = rawBytes [ 0 ] | 128 ;
j + + ;
2021-03-19 17:00:06 +00:00
}
else if ( sString [ j ] = = ' ^ ' )
{
2021-02-18 17:14:15 +00:00
rawBytes [ 0 ] = 1 | 2 | 32 | 64 ;
}
2021-03-19 17:00:06 +00:00
if ( ! dotSkipped & & sString [ j ] = = ' . ' )
rawBytes [ 0 ] = 128 ;
2021-03-22 11:47:15 +00:00
tm1637display - > printRaw ( rawBytes , 1 , TM1637Data . digit_order [ i ] ) ;
2021-02-17 10:54:45 +00:00
}
2021-03-19 17:00:06 +00:00
}
else if ( TM1638 = = TM1637Data . display_type )
{
for ( uint32_t j = 0 ; i < position + length ; i + + , j + + )
{
if ( i > 7 )
break ;
if ( sString [ j ] = = 0 )
break ;
if ( sString [ j + 1 ] = = ' . ' )
{
2021-02-22 06:00:11 +00:00
tm1638display - > displayASCIIwDot ( i , sString [ j ] ) ;
2021-02-18 17:14:15 +00:00
j + + ;
2021-03-19 17:00:06 +00:00
}
else if ( sString [ j ] = = ' ^ ' )
{
2021-02-22 06:00:11 +00:00
tm1638display - > display7Seg ( i , ( 1 | 2 | 32 | 64 ) ) ;
2021-03-19 17:00:06 +00:00
}
else
tm1638display - > displayASCII ( i , sString [ j ] ) ;
}
}
else if ( MAX7219 = = TM1637Data . display_type )
{
uint8_t rawBytes [ 1 ] ;
for ( uint32_t j = 0 ; i < position + length ; i + + , j + + )
{
2022-04-10 23:33:47 +01:00
if ( i > Settings - > display_width - 1 )
2021-03-19 17:00:06 +00:00
break ;
if ( sString [ j ] = = 0 )
break ;
rawBytes [ 0 ] = tm1637display - > encode ( sString [ j ] ) ;
bool dotSkipped = false ;
if ( sString [ j + 1 ] = = ' . ' )
{
dotSkipped = true ;
rawBytes [ 0 ] = rawBytes [ 0 ] | 128 ;
j + + ;
}
else if ( sString [ j ] = = ' ^ ' )
{
rawBytes [ 0 ] = 1 | 2 | 32 | 64 ;
}
if ( ! dotSkipped & & sString [ j ] = = ' . ' )
rawBytes [ 0 ] = 128 ;
displayMAX72197Seg ( i , rawBytes [ 0 ] ) ;
2021-03-19 09:15:50 +00:00
}
2021-02-10 16:23:47 +00:00
}
return true ;
}
/*********************************************************************************************\
* Displays a clock .
2021-02-14 11:22:08 +00:00
* Command : DisplayClock 1 // 12-hour format
* DisplayClock 2 // 24-hour format
* DisplayClock 0 // turn off clock and clear
2021-02-10 16:23:47 +00:00
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-03-19 17:00:06 +00:00
bool CmndTM1637Clock ( void )
{
2021-02-10 16:23:47 +00:00
2021-02-21 11:17:39 +00:00
TM1637Data . show_clock = XdrvMailbox . payload ;
2021-02-14 11:22:08 +00:00
2021-03-19 17:00:06 +00:00
if ( ArgC ( ) = = 0 )
XdrvMailbox . payload = 1 ;
if ( XdrvMailbox . payload > 1 ) {
TM1637Data . clock_24 = true ;
XdrvMailbox . payload = 2 ;
} else {
TM1637Data . clock_24 = false ;
XdrvMailbox . payload = 1 ;
}
2021-02-14 11:22:08 +00:00
2021-02-22 06:00:11 +00:00
AddLog ( LOG_LEVEL_DEBUG , PSTR ( " TM7: TM1637Data.show_clock %d, TM1637Data.clock_24 %d " ) , TM1637Data . show_clock , TM1637Data . clock_24 ) ;
2021-02-14 11:22:08 +00:00
2021-03-18 14:00:50 +00:00
TM1637ClearDisplay ( ) ;
2021-02-10 16:23:47 +00:00
return true ;
}
/*********************************************************************************************\
2021-02-14 11:22:08 +00:00
* refreshes the time if clock is displayed
2021-02-10 16:23:47 +00:00
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-03-19 17:00:06 +00:00
void TM1637ShowTime ( )
{
2022-10-16 16:56:58 +01:00
struct TIME_T t = RtcTime ;
BreakNanoTime ( Rtc . local_time , Rtc . nanos + ( millis ( ) - Rtc . millis ) * 1000000 , t ) ;
uint8_t hr = t . hour ;
uint8_t mn = t . minute ;
uint8_t sc = t . second ;
uint16_t ms = t . nanos / 1000000 ;
2022-03-10 12:18:10 +00:00
if ( ! TM1637Data . clock_24 )
2021-03-19 17:00:06 +00:00
{
if ( hr > 12 )
hr - = 12 ;
if ( hr = = 0 )
hr = 12 ;
2021-02-10 16:23:47 +00:00
}
2021-02-14 11:22:08 +00:00
2022-03-10 12:18:10 +00:00
char tm [ 7 ] ;
snprintf_P ( tm , sizeof ( tm ) , PSTR ( " %02d%02d%02d " ) , hr , mn , sc ) ;
if ( ! TM1637Data . clock_24 & & tm [ 0 ] = = ' 0 ' )
{
tm [ 0 ] = ' ' ;
}
2022-02-04 19:22:29 +00:00
2021-03-19 17:00:06 +00:00
if ( TM1637 = = TM1637Data . display_type )
{
2022-10-16 16:56:58 +01:00
uint8_t colon = ms > 500 ? 0 : 128 ;
2021-02-18 17:14:15 +00:00
uint8_t rawBytes [ 1 ] ;
2022-10-16 16:56:58 +01:00
uint8_t width = Settings - > display_width > = 6 ? 6 : 4 ;
for ( uint32_t i = 0 ; i < width ; i + + )
2021-03-19 17:00:06 +00:00
{
2021-02-22 06:00:11 +00:00
rawBytes [ 0 ] = tm1637display - > encode ( tm [ i ] ) ;
2022-10-16 16:56:58 +01:00
if ( i = = 1 | | ( i = = 3 & & width > 4 ) )
rawBytes [ 0 ] = rawBytes [ 0 ] | colon ;
2021-03-22 11:47:15 +00:00
tm1637display - > printRaw ( rawBytes , 1 , TM1637Data . digit_order [ i ] ) ;
2021-02-18 17:14:15 +00:00
}
2021-03-19 17:00:06 +00:00
}
else if ( TM1638 = = TM1637Data . display_type )
{
for ( uint32_t i = 0 ; i < 4 ; i + + )
{
if ( ( millis ( ) % 1000 ) > 500 & & ( i = = 1 ) )
tm1638display - > displayASCIIwDot ( i , tm [ i ] ) ;
else
tm1638display - > displayASCII ( i , tm [ i ] ) ;
}
}
else if ( MAX7219 = = TM1637Data . display_type )
{
2022-03-04 19:35:29 +00:00
for ( uint32_t i = 0 ; i < 6 ; i + + )
2021-03-19 17:00:06 +00:00
{
2022-02-03 21:20:43 +00:00
//if ((millis() % 1000) > 500 && (i == 3))
if ( ( i = = 1 ) | | ( i = = 3 ) )
2021-03-19 17:00:06 +00:00
displayMAX7219ASCIIwDot ( i , tm [ i ] ) ;
else
displayMAX7219ASCII ( i , tm [ i ] ) ;
2021-02-18 17:14:15 +00:00
}
2021-02-16 12:12:49 +00:00
}
2021-02-10 16:23:47 +00:00
}
2021-02-18 17:14:15 +00:00
/*********************************************************************************************\
* This function is called for all Display functions .
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-03-19 17:00:06 +00:00
bool TM1637MainFunc ( uint8_t fn )
{
2021-02-18 17:14:15 +00:00
bool result = false ;
2021-09-06 14:56:01 +01:00
if ( fn ! = FUNC_DISPLAY_SCROLLDELAY ) TM1637Data . scroll = false ;
2021-03-19 17:00:06 +00:00
if ( XdrvMailbox . data_len > CMD_MAX_LEN )
{
2021-03-19 09:15:50 +00:00
Response_P ( PSTR ( " { \" Error \" : \" Command text too long. Please limit it to %d characters \" } " ) , CMD_MAX_LEN ) ;
return false ;
2021-02-14 11:22:08 +00:00
}
2021-03-19 17:00:06 +00:00
switch ( fn )
{
case FUNC_DISPLAY_CLEAR :
result = CmndTM1637Clear ( ) ;
break ;
case FUNC_DISPLAY_NUMBER :
result = CmndTM1637Number ( true ) ;
break ;
case FUNC_DISPLAY_NUMBERNC :
result = CmndTM1637Number ( false ) ;
break ;
case FUNC_DISPLAY_FLOAT :
result = CmndTM1637Float ( true ) ;
break ;
case FUNC_DISPLAY_FLOATNC :
result = CmndTM1637Float ( false ) ;
break ;
case FUNC_DISPLAY_RAW :
result = CmndTM1637Raw ( ) ;
break ;
case FUNC_DISPLAY_SEVENSEG_TEXT :
result = CmndTM1637Text ( true ) ;
break ;
case FUNC_DISPLAY_SEVENSEG_TEXTNC :
result = CmndTM1637Text ( false ) ;
break ;
case FUNC_DISPLAY_LEVEL :
result = CmndTM1637Level ( ) ;
break ;
case FUNC_DISPLAY_SCROLLTEXT :
result = CmndTM1637ScrollText ( ) ;
break ;
case FUNC_DISPLAY_SCROLLDELAY :
result = CmndTM1637ScrollDelay ( ) ;
break ;
case FUNC_DISPLAY_CLOCK :
result = CmndTM1637Clock ( ) ;
break ;
2021-02-10 16:23:47 +00:00
}
return result ;
2021-02-17 11:32:36 +00:00
}
2021-02-10 16:23:47 +00:00
2021-03-19 17:00:06 +00:00
void TM1637Dim ( void )
{
2021-09-14 21:40:26 +01:00
// GetDisplayDimmer16() = 0 - 15
uint8_t brightness = GetDisplayDimmer16 ( ) > > 1 ; // 0 - 7
2021-03-19 13:24:26 +00:00
2021-03-19 17:00:06 +00:00
if ( TM1637 = = TM1637Data . display_type )
{
tm1637display - > setBacklight ( brightness * 12 ) ; // 0 - 84
}
else if ( TM1638 = = TM1637Data . display_type )
{
tm1638display - > brightness ( brightness ) ; // 0 - 7
2021-03-19 13:24:26 +00:00
}
2021-03-19 17:00:06 +00:00
else if ( MAX7219 = = TM1637Data . display_type )
{
2022-04-11 11:48:44 +01:00
for ( uint8_t dev_addr = 0 ; dev_addr < Settings - > display_width / 8 ; dev_addr + + )
2022-04-10 23:33:47 +01:00
{
max7219display - > setIntensity ( MAX7219_ADDR , brightness ) ; // 0 - 7
}
2021-03-19 13:24:26 +00:00
}
}
2021-02-10 16:23:47 +00:00
2021-03-19 11:02:01 +00:00
/*********************************************************************************************/
# ifdef USE_DISPLAY_MODES1TO5
2021-03-19 17:00:06 +00:00
void TM1637Print ( char * txt )
{
2021-06-11 17:14:12 +01:00
for ( uint32_t i = 0 ; i < Settings - > display_cols [ 0 ] ; i + + )
2021-03-19 17:00:06 +00:00
{
if ( TM1637 = = TM1637Data . display_type )
{
2021-03-19 11:02:01 +00:00
uint8_t rawBytes [ 1 ] ;
rawBytes [ 0 ] = tm1637display - > encode ( txt [ i ] ) ;
2021-03-19 17:00:06 +00:00
// if ((millis() % 1000) > 500 && (i == 1)) { rawBytes[0] = rawBytes[0] | 128; }
2021-03-22 11:47:15 +00:00
tm1637display - > printRaw ( rawBytes , 1 , TM1637Data . digit_order [ i ] ) ;
2021-03-19 11:02:01 +00:00
}
2021-03-19 17:00:06 +00:00
else if ( TM1638 = = TM1637Data . display_type )
{
// if ((millis() % 1000) > 500 && (i == 1)) { tm1638display->displayASCIIwDot(i, txt[i]); }
2021-03-19 11:02:01 +00:00
tm1638display - > displayASCII ( i , txt [ i ] ) ;
}
2021-03-19 17:00:06 +00:00
else if ( MAX7219 = = TM1637Data . display_type )
{
// if ((millis() % 1000) > 500 && (i == 1)) { tm1638display->displayASCIIwDot(i, txt[i]); }
displayMAX7219ASCII ( i , txt [ i ] ) ;
}
2021-03-19 11:02:01 +00:00
}
}
2021-03-19 17:00:06 +00:00
void TM1637Center ( char * txt )
{
2021-06-11 17:14:12 +01:00
char line [ Settings - > display_cols [ 0 ] + 2 ] ;
2021-03-19 11:02:01 +00:00
int len = strlen ( txt ) ;
int offset = 0 ;
2021-06-11 17:14:12 +01:00
if ( len > = Settings - > display_cols [ 0 ] )
2021-03-19 17:00:06 +00:00
{
2021-06-11 17:14:12 +01:00
len = Settings - > display_cols [ 0 ] ;
2021-03-19 17:00:06 +00:00
}
else
{
2021-06-11 17:14:12 +01:00
offset = ( Settings - > display_cols [ 0 ] - len ) / 2 ;
2021-03-19 11:02:01 +00:00
}
2021-06-11 17:14:12 +01:00
memset ( line , 0x20 , Settings - > display_cols [ 0 ] ) ;
line [ Settings - > display_cols [ 0 ] ] = 0 ;
2021-03-19 17:00:06 +00:00
for ( uint32_t i = 0 ; i < len ; i + + )
{
line [ offset + i ] = txt [ i ] ;
2021-03-19 11:02:01 +00:00
}
TM1637Print ( line ) ;
}
/*
bool TM1637PrintLog ( void ) {
bool result = false ;
disp_refresh - - ;
if ( ! disp_refresh ) {
2021-06-11 17:14:12 +01:00
disp_refresh = Settings - > display_refresh ;
2021-03-19 11:02:01 +00:00
if ( ! disp_screen_buffer_cols ) { DisplayAllocScreenBuffer ( ) ; }
char * txt = DisplayLogBuffer ( ' \337 ' ) ;
if ( txt ! = nullptr ) {
2021-06-11 17:14:12 +01:00
uint8_t last_row = Settings - > display_rows - 1 ;
2021-03-19 11:02:01 +00:00
strlcpy ( disp_screen_buffer [ last_row ] , txt , disp_screen_buffer_cols ) ;
DisplayFillScreen ( last_row ) ;
AddLog ( LOG_LEVEL_DEBUG , PSTR ( D_LOG_DEBUG " [%s] " ) , disp_screen_buffer [ last_row ] ) ;
2021-03-19 11:22:53 +00:00
TM1637Print ( disp_screen_buffer [ last_row ] ) ;
2021-03-19 11:02:01 +00:00
result = true ;
}
}
return result ;
}
*/
2021-03-19 11:22:53 +00:00
2021-03-19 17:00:06 +00:00
void TM1637Time ( void )
{
2021-06-11 17:14:12 +01:00
char line [ Settings - > display_cols [ 0 ] + 1 ] ;
2021-03-19 11:02:01 +00:00
2021-06-11 17:14:12 +01:00
if ( Settings - > display_cols [ 0 ] > = 8 )
2021-03-19 17:00:06 +00:00
{
2021-03-19 11:02:01 +00:00
snprintf_P ( line , sizeof ( line ) , PSTR ( " %02d %02d %02d " ) , RtcTime . hour , RtcTime . minute , RtcTime . second ) ;
}
2021-06-11 17:14:12 +01:00
else if ( Settings - > display_cols [ 0 ] > = 6 )
2021-03-19 17:00:06 +00:00
{
2021-03-19 11:02:01 +00:00
snprintf_P ( line , sizeof ( line ) , PSTR ( " %02d%02d%02d " ) , RtcTime . hour , RtcTime . minute , RtcTime . second ) ;
}
2021-03-19 17:00:06 +00:00
else
{
2021-03-19 11:02:01 +00:00
snprintf_P ( line , sizeof ( line ) , PSTR ( " %02d%02d " ) , RtcTime . hour , RtcTime . minute ) ;
}
TM1637Center ( line ) ;
}
2021-03-19 17:00:06 +00:00
void TM1637Date ( void )
{
2021-06-11 17:14:12 +01:00
char line [ Settings - > display_cols [ 0 ] + 1 ] ;
2021-03-19 11:22:53 +00:00
2021-06-11 17:14:12 +01:00
if ( Settings - > display_cols [ 0 ] > = 8 )
2021-03-19 17:00:06 +00:00
{
snprintf_P ( line , sizeof ( line ) , PSTR ( " %02d-%02d-%02d " ) , RtcTime . day_of_month , RtcTime . month , RtcTime . year - 2000 ) ;
2021-03-19 11:22:53 +00:00
}
2021-06-11 17:14:12 +01:00
else if ( Settings - > display_cols [ 0 ] > = 6 )
2021-03-19 17:00:06 +00:00
{
snprintf_P ( line , sizeof ( line ) , PSTR ( " %02d%02d%02d " ) , RtcTime . day_of_month , RtcTime . month , RtcTime . year - 2000 ) ;
2021-03-19 11:22:53 +00:00
}
2021-03-19 17:00:06 +00:00
else
{
2021-03-19 11:22:53 +00:00
snprintf_P ( line , sizeof ( line ) , PSTR ( " %02d%02d " ) , RtcTime . day_of_month , RtcTime . month ) ;
}
TM1637Center ( line ) ;
}
2021-03-19 17:00:06 +00:00
void TM1637Refresh ( void )
{ // Every second
2021-06-11 17:14:12 +01:00
if ( ! disp_power | | ! Settings - > display_mode )
2021-03-19 17:00:06 +00:00
{
return ;
} // Mode 0 is User text
2021-03-19 13:24:26 +00:00
2021-06-11 17:14:12 +01:00
switch ( Settings - > display_mode )
2021-03-19 17:00:06 +00:00
{
case 1 : // Time
TM1637Time ( ) ;
break ;
case 2 : // Date
TM1637Date ( ) ;
break ;
case 3 : // Time
2021-06-11 17:14:12 +01:00
if ( TasmotaGlobal . uptime % Settings - > display_refresh )
2021-03-19 17:00:06 +00:00
{
2021-03-19 13:24:26 +00:00
TM1637Time ( ) ;
2021-03-19 17:00:06 +00:00
}
else
{
2021-03-19 13:24:26 +00:00
TM1637Date ( ) ;
2021-03-19 17:00:06 +00:00
}
break ;
/*
2021-03-19 13:24:26 +00:00
case 4 : // Mqtt
TM1637PrintLog ( ) ;
break ;
case 5 : { // Mqtt
if ( ! TM1637PrintLog ( ) ) { TM1637Time ( ) ; }
break ;
2021-03-19 11:02:01 +00:00
}
2021-03-19 13:24:26 +00:00
*/
2021-03-19 11:02:01 +00:00
}
}
2021-03-19 17:00:06 +00:00
# endif // USE_DISPLAY_MODES1TO5
2021-03-19 11:02:01 +00:00
2021-02-10 16:23:47 +00:00
/*********************************************************************************************\
* Interface
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-03-19 11:02:01 +00:00
2021-03-19 17:00:06 +00:00
bool Xdsp15 ( uint8_t function )
{
2021-02-10 16:23:47 +00:00
bool result = false ;
2021-03-19 17:00:06 +00:00
if ( FUNC_DISPLAY_INIT_DRIVER = = function )
{
2021-03-19 09:15:50 +00:00
TM1637Init ( ) ;
2021-02-10 16:23:47 +00:00
}
2021-06-11 17:14:12 +01:00
else if ( TM1637Data . init_done & & ( XDSP_15 = = Settings - > display_model ) )
2021-03-19 17:00:06 +00:00
{
switch ( function )
{
case FUNC_DISPLAY_EVERY_50_MSECOND :
2021-06-11 17:14:12 +01:00
if ( disp_power & & ! Settings - > display_mode )
2021-03-19 17:00:06 +00:00
{
if ( TM1637Data . scroll )
{
TM1637ScrollText ( ) ;
2021-03-19 10:13:08 +00:00
}
2021-03-19 17:00:06 +00:00
if ( TM1637Data . show_clock )
{
TM1637ShowTime ( ) ;
2021-03-19 10:13:08 +00:00
}
2021-03-19 17:00:06 +00:00
}
break ;
# ifdef USE_DISPLAY_MODES1TO5
case FUNC_DISPLAY_EVERY_SECOND :
TM1637Refresh ( ) ;
break ;
# endif // USE_DISPLAY_MODES1TO5
case FUNC_DISPLAY_MODEL :
result = true ;
break ;
case FUNC_DISPLAY_SEVENSEG_TEXT :
case FUNC_DISPLAY_CLEAR :
case FUNC_DISPLAY_NUMBER :
case FUNC_DISPLAY_FLOAT :
case FUNC_DISPLAY_NUMBERNC :
case FUNC_DISPLAY_FLOATNC :
case FUNC_DISPLAY_RAW :
case FUNC_DISPLAY_LEVEL :
case FUNC_DISPLAY_SEVENSEG_TEXTNC :
case FUNC_DISPLAY_SCROLLTEXT :
case FUNC_DISPLAY_SCROLLDELAY :
case FUNC_DISPLAY_CLOCK :
2021-06-11 17:14:12 +01:00
if ( disp_power & & ! Settings - > display_mode )
2021-03-19 17:00:06 +00:00
{
TM1637Data . show_clock = false ;
result = TM1637MainFunc ( function ) ;
}
break ;
case FUNC_DISPLAY_DIM :
TM1637Dim ( ) ;
break ;
case FUNC_DISPLAY_POWER :
if ( ! disp_power )
{
TM1637ClearDisplay ( ) ;
}
break ;
2021-02-10 16:23:47 +00:00
}
}
return result ;
}
2021-03-19 17:00:06 +00:00
# endif // USE_DISPLAY_TM1637
# endif // USE_DISPLAY