2018-08-28 17:13:14 +01:00
/*
2019-10-27 10:13:24 +00:00
xdrv_13_display . ino - Display support for Tasmota
2018-08-28 17:13:14 +01:00
2021-01-01 12:44:04 +00:00
Copyright ( C ) 2021 Theo Arends
2018-08-28 17:13:14 +01: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/>.
*/
# ifdef USE_DISPLAY
2019-08-19 12:21:54 +01:00
# define XDRV_13 13
# include <renderer.h>
Renderer * renderer ;
2019-08-19 17:17:44 +01:00
enum ColorType { COLOR_BW , COLOR_COLOR } ;
2019-08-19 12:21:54 +01:00
2021-05-01 08:54:05 +01:00
# ifndef DISP_BATCH_FILE
# define DISP_BATCH_FILE " / display.bat"
# endif
2019-08-19 12:21:54 +01:00
2021-04-21 10:01:40 +01:00
# ifdef USE_UFILESYS
extern FS * ufsp ;
extern FS * ffsp ;
# endif
2021-05-25 17:53:10 +01:00
# ifdef USE_TOUCH_BUTTONS
extern VButton * buttons [ MAX_TOUCH_BUTTONS ] ;
# endif
2019-08-19 12:21:54 +01:00
// drawing color is WHITE
// on epaper the whole display buffer is transfered inverted this results in white paper
uint16_t fg_color = 1 ;
uint16_t bg_color = 0 ;
uint8_t color_type = COLOR_BW ;
2021-01-17 17:52:16 +00:00
uint8_t auto_draw = 1 ;
2021-04-21 10:01:40 +01:00
int16_t disp_xpos = 0 ;
int16_t disp_ypos = 0 ;
# ifdef USE_MULTI_DISPLAY
2021-09-23 08:51:51 +01:00
# ifndef MAX_MULTI_DISPLAYS
# define MAX_MULTI_DISPLAYS 3
# endif
2021-04-21 10:01:40 +01:00
struct MULTI_DISP {
Renderer * display ;
uint16_t fg_color ;
uint16_t bg_color ;
int16_t disp_xpos ;
int16_t disp_ypos ;
uint8_t color_type ;
uint8_t auto_draw ;
2021-09-30 18:09:38 +01:00
uint8_t model ;
uint8_t used ;
2021-09-23 08:51:51 +01:00
} displays [ MAX_MULTI_DISPLAYS ] ;
2021-04-21 10:01:40 +01:00
uint8_t cur_display ;
2021-11-17 21:48:48 +00:00
Renderer * Init_uDisplay ( const char * desc ) ;
2021-04-21 10:01:40 +01:00
void Set_display ( uint8_t index ) {
displays [ index ] . display = renderer ;
displays [ index ] . fg_color = fg_color ;
displays [ index ] . bg_color = bg_color ;
displays [ index ] . color_type = color_type ;
displays [ index ] . auto_draw = auto_draw ;
displays [ index ] . disp_xpos = disp_xpos ;
displays [ index ] . disp_ypos = disp_ypos ;
2021-09-30 18:09:38 +01:00
displays [ index ] . model = Settings - > display_model ;
displays [ index ] . used = 1 ;
2021-04-21 10:01:40 +01:00
cur_display = index ;
}
void Get_display ( uint8_t index ) {
renderer = displays [ index ] . display ;
fg_color = displays [ index ] . fg_color ;
bg_color = displays [ index ] . bg_color ;
color_type = displays [ index ] . color_type ;
auto_draw = displays [ index ] . auto_draw ;
disp_xpos = displays [ index ] . disp_xpos ;
disp_ypos = displays [ index ] . disp_ypos ;
if ( renderer ) renderer - > setDrawMode ( auto_draw > > 1 ) ;
2021-09-30 18:09:38 +01:00
//Settings->display_model = displays[index].model;
2021-04-21 10:01:40 +01:00
cur_display = index ;
}
# endif // USE_MULTI_DISPLAY
2019-08-19 12:21:54 +01:00
2021-12-08 15:32:02 +00:00
# ifndef TXT_MAX_SFAC
# define TXT_MAX_SFAC 4
# endif // TXT_MAX_SFAC
2021-03-19 14:42:24 +00:00
const uint8_t DISPLAY_MAX_DRIVERS = 32 ; // Max number of display drivers/models supported by xdsp_interface.ino
2020-06-21 11:11:40 +01:00
const uint8_t DISPLAY_MAX_COLS = 64 ; // Max number of columns allowed with command DisplayCols
const uint8_t DISPLAY_MAX_ROWS = 64 ; // Max number of lines allowed with command DisplayRows
2018-08-28 17:13:14 +01:00
2019-03-31 10:59:04 +01:00
const uint8_t DISPLAY_LOG_ROWS = 32 ; // Number of lines in display log buffer
2018-08-28 17:13:14 +01:00
2019-08-11 17:12:18 +01:00
# define D_PRFX_DISPLAY "Display"
2018-08-28 17:13:14 +01:00
# define D_CMND_DISP_ADDRESS "Address"
# define D_CMND_DISP_COLS "Cols"
# define D_CMND_DISP_DIMMER "Dimmer"
# define D_CMND_DISP_MODE "Mode"
# define D_CMND_DISP_MODEL "Model"
2021-03-22 11:34:52 +00:00
# define D_CMND_DISP_TYPE "Type"
2018-08-28 17:13:14 +01:00
# define D_CMND_DISP_REFRESH "Refresh"
# define D_CMND_DISP_ROWS "Rows"
# define D_CMND_DISP_SIZE "Size"
# define D_CMND_DISP_FONT "Font"
# define D_CMND_DISP_ROTATE "Rotate"
2021-03-22 11:34:52 +00:00
# define D_CMND_DISP_INVERT "Invert"
2019-07-23 13:05:42 +01:00
# define D_CMND_DISP_WIDTH "Width"
# define D_CMND_DISP_HEIGHT "Height"
2021-01-01 17:17:55 +00:00
# define D_CMND_DISP_BLINKRATE "Blinkrate"
2021-02-14 14:00:57 +00:00
# define D_CMND_DISP_BATCH "Batch"
2021-03-22 11:34:52 +00:00
# define D_CMND_DISP_TEXT "Text"
2021-02-10 16:23:47 +00:00
# define D_CMND_DISP_CLEAR "Clear"
# define D_CMND_DISP_NUMBER "Number"
# define D_CMND_DISP_FLOAT "Float"
2021-03-22 11:34:52 +00:00
# define D_CMND_DISP_NUMBERNC "NumberNC" // NC - "No Clear"
# define D_CMND_DISP_FLOATNC "FloatNC" // NC - "No Clear"
2021-02-10 16:23:47 +00:00
# define D_CMND_DISP_RAW "Raw"
# define D_CMND_DISP_LEVEL "Level"
# define D_CMND_DISP_SEVENSEG_TEXT "SevensegText"
# define D_CMND_DISP_SEVENSEG_TEXTNC "SevensegTextNC" // NC - "No Clear"
# define D_CMND_DISP_SCROLLDELAY "ScrollDelay"
# define D_CMND_DISP_CLOCK "Clock"
2021-02-14 11:22:08 +00:00
# define D_CMND_DISP_TEXTNC "TextNC" // NC - "No Clear"
2021-02-16 12:12:49 +00:00
# define D_CMND_DISP_SCROLLTEXT "ScrollText"
2021-04-11 11:32:02 +01:00
# define D_CMND_DISP_REINIT "reinit"
2018-08-28 17:13:14 +01:00
enum XdspFunctions { FUNC_DISPLAY_INIT_DRIVER , FUNC_DISPLAY_INIT , FUNC_DISPLAY_EVERY_50_MSECOND , FUNC_DISPLAY_EVERY_SECOND ,
FUNC_DISPLAY_MODEL , FUNC_DISPLAY_MODE , FUNC_DISPLAY_POWER ,
FUNC_DISPLAY_CLEAR , FUNC_DISPLAY_DRAW_FRAME ,
FUNC_DISPLAY_DRAW_HLINE , FUNC_DISPLAY_DRAW_VLINE , FUNC_DISPLAY_DRAW_LINE ,
FUNC_DISPLAY_DRAW_CIRCLE , FUNC_DISPLAY_FILL_CIRCLE ,
FUNC_DISPLAY_DRAW_RECTANGLE , FUNC_DISPLAY_FILL_RECTANGLE ,
2021-01-01 17:17:55 +00:00
FUNC_DISPLAY_TEXT_SIZE , FUNC_DISPLAY_FONT_SIZE , FUNC_DISPLAY_ROTATION , FUNC_DISPLAY_DRAW_STRING ,
2021-03-19 13:24:26 +00:00
FUNC_DISPLAY_DIM , FUNC_DISPLAY_BLINKRATE ,
2021-02-14 14:00:57 +00:00
# ifdef USE_UFILESYS
2021-03-19 13:24:26 +00:00
FUNC_DISPLAY_BATCH ,
2021-02-14 14:00:57 +00:00
# endif
2021-03-19 13:24:26 +00:00
FUNC_DISPLAY_NUMBER , FUNC_DISPLAY_FLOAT , FUNC_DISPLAY_NUMBERNC , FUNC_DISPLAY_FLOATNC ,
FUNC_DISPLAY_RAW , FUNC_DISPLAY_LEVEL , FUNC_DISPLAY_SEVENSEG_TEXT , FUNC_DISPLAY_SEVENSEG_TEXTNC ,
2021-03-18 14:00:50 +00:00
FUNC_DISPLAY_SCROLLDELAY , FUNC_DISPLAY_CLOCK , FUNC_DISPLAY_SCROLLTEXT
2021-02-14 14:00:57 +00:00
} ;
2018-08-28 17:13:14 +01:00
enum DisplayInitModes { DISPLAY_INIT_MODE , DISPLAY_INIT_PARTIAL , DISPLAY_INIT_FULL } ;
2019-08-11 17:12:18 +01:00
const char kDisplayCommands [ ] PROGMEM = D_PRFX_DISPLAY " | " // Prefix
2021-03-22 11:34:52 +00:00
" | " D_CMND_DISP_MODEL " | " D_CMND_DISP_TYPE " | " D_CMND_DISP_WIDTH " | " D_CMND_DISP_HEIGHT " | " D_CMND_DISP_MODE " | "
D_CMND_DISP_INVERT " | " D_CMND_DISP_REFRESH " | " D_CMND_DISP_DIMMER " | " D_CMND_DISP_COLS " | " D_CMND_DISP_ROWS " | "
D_CMND_DISP_SIZE " | " D_CMND_DISP_FONT " | " D_CMND_DISP_ROTATE " | " D_CMND_DISP_TEXT " | " D_CMND_DISP_ADDRESS " | " D_CMND_DISP_BLINKRATE " | "
2021-02-14 14:00:57 +00:00
# ifdef USE_UFILESYS
2021-03-19 13:24:26 +00:00
D_CMND_DISP_BATCH " | "
2021-02-14 14:00:57 +00:00
# endif
2021-03-19 13:24:26 +00:00
D_CMND_DISP_CLEAR " | " D_CMND_DISP_NUMBER " | " D_CMND_DISP_FLOAT " | " D_CMND_DISP_NUMBERNC " | " D_CMND_DISP_FLOATNC " | "
D_CMND_DISP_RAW " | " D_CMND_DISP_LEVEL " | " D_CMND_DISP_SEVENSEG_TEXT " | " D_CMND_DISP_SEVENSEG_TEXTNC " | "
2021-04-11 11:32:02 +01:00
D_CMND_DISP_SCROLLDELAY " | " D_CMND_DISP_CLOCK " | " D_CMND_DISP_TEXTNC " | " D_CMND_DISP_SCROLLTEXT " | " D_CMND_DISP_REINIT
2021-02-14 14:00:57 +00:00
;
2019-08-02 16:22:38 +01:00
void ( * const DisplayCommand [ ] ) ( void ) PROGMEM = {
2021-03-22 11:34:52 +00:00
& CmndDisplay , & CmndDisplayModel , & CmndDisplayType , & CmndDisplayWidth , & CmndDisplayHeight , & CmndDisplayMode ,
& CmndDisplayInvert , & CmndDisplayRefresh , & CmndDisplayDimmer , & CmndDisplayColumns , & CmndDisplayRows ,
& CmndDisplaySize , & CmndDisplayFont , & CmndDisplayRotate , & CmndDisplayText , & CmndDisplayAddress , & CmndDisplayBlinkrate ,
2021-02-14 14:00:57 +00:00
# ifdef USE_UFILESYS
2021-03-19 13:24:26 +00:00
& CmndDisplayBatch ,
2021-02-14 14:00:57 +00:00
# endif
2021-03-19 13:24:26 +00:00
& CmndDisplayClear , & CmndDisplayNumber , & CmndDisplayFloat , & CmndDisplayNumberNC , & CmndDisplayFloatNC ,
& CmndDisplayRaw , & CmndDisplayLevel , & CmndDisplaySevensegText , & CmndDisplaySevensegTextNC ,
2021-04-11 11:32:02 +01:00
& CmndDisplayScrollDelay , & CmndDisplayClock , & CmndDisplayTextNC , & CmndDisplayScrollText , & DisplayReInitDriver
2021-02-14 14:00:57 +00:00
} ;
2018-08-28 17:13:14 +01:00
2021-03-22 14:39:08 +00:00
# ifdef USE_GRAPH
typedef union {
uint8_t data ;
struct {
uint8_t overlay : 1 ;
uint8_t draw : 1 ;
uint8_t nu3 : 1 ;
uint8_t nu4 : 1 ;
uint8_t nu5 : 1 ;
uint8_t nu6 : 1 ;
uint8_t nu7 : 1 ;
uint8_t nu8 : 1 ;
} ;
} GFLAGS ;
struct GRAPH {
uint16_t xp ;
uint16_t yp ;
uint16_t xs ;
uint16_t ys ;
float ymin ;
float ymax ;
float range ;
uint32_t x_time ; // time per x slice in milliseconds
uint32_t last_ms ;
uint32_t last_ms_redrawn ;
int16_t decimation ; // decimation or graph duration in minutes
uint16_t dcnt ;
uint32_t summ ;
uint16_t xcnt ;
uint8_t * values ;
uint8_t xticks ;
uint8_t yticks ;
uint8_t last_val ;
uint8_t color_index ;
2021-09-23 08:51:51 +01:00
uint16_t bg_color ;
uint16_t fg_color ;
2021-03-22 14:39:08 +00:00
GFLAGS flags ;
} ;
struct GRAPH * graph [ NUM_GRAPHS ] ;
# endif // USE_GRAPH
2019-07-01 11:54:26 +01:00
char * dsp_str ;
2018-08-28 17:13:14 +01:00
uint16_t dsp_x ;
uint16_t dsp_y ;
uint16_t dsp_x2 ;
uint16_t dsp_y2 ;
uint16_t dsp_rad ;
uint16_t dsp_color ;
int16_t dsp_len ;
2019-07-01 11:54:26 +01:00
2023-02-05 15:54:25 +00:00
bool disp_apply_display_dimmer_request = false ;
2023-02-05 11:52:21 +00:00
int8_t disp_power = - 1 ;
2019-07-01 11:54:26 +01:00
uint8_t disp_device = 0 ;
uint8_t disp_refresh = 1 ;
uint8_t disp_autodraw = 1 ;
uint8_t dsp_init ;
uint8_t dsp_font ;
uint8_t dsp_flag ;
uint8_t dsp_on ;
2018-08-28 17:13:14 +01:00
2021-02-18 09:57:12 +00:00
# define PREDEF_INDEXCOLORS 19
uint16_t index_colors [ MAX_INDEXCOLORS - PREDEF_INDEXCOLORS ] ;
2021-02-14 14:00:57 +00:00
2018-08-28 17:13:14 +01:00
# ifdef USE_DISPLAY_MODES1TO5
2019-07-01 11:54:26 +01:00
char * * disp_log_buffer ;
char * * disp_screen_buffer ;
2018-08-28 17:13:14 +01:00
char disp_temp [ 2 ] ; // C or F
2019-10-18 17:06:17 +01:00
char disp_pres [ 5 ] ; // hPa or mmHg
2018-08-28 17:13:14 +01:00
uint8_t disp_log_buffer_cols = 0 ;
uint8_t disp_log_buffer_idx = 0 ;
uint8_t disp_log_buffer_ptr = 0 ;
uint8_t disp_screen_buffer_cols = 0 ;
uint8_t disp_screen_buffer_rows = 0 ;
2019-07-01 11:54:26 +01:00
bool disp_subscribed = false ;
2018-08-28 17:13:14 +01:00
# endif // USE_DISPLAY_MODES1TO5
/*********************************************************************************************/
2019-08-19 12:21:54 +01:00
void DisplayInit ( uint8_t mode )
2018-08-28 17:13:14 +01:00
{
2019-08-19 12:21:54 +01:00
if ( renderer ) {
2021-06-11 17:14:12 +01:00
renderer - > DisplayInit ( mode , Settings - > display_size , Settings - > display_rotate , Settings - > display_font ) ;
2019-08-19 12:21:54 +01:00
}
else {
dsp_init = mode ;
XdspCall ( FUNC_DISPLAY_INIT ) ;
}
2018-08-28 17:13:14 +01:00
}
2018-11-14 13:32:09 +00:00
void DisplayClear ( void )
2018-08-28 17:13:14 +01:00
{
XdspCall ( FUNC_DISPLAY_CLEAR ) ;
}
2019-08-19 12:21:54 +01:00
void DisplayDrawStringAt ( uint16_t x , uint16_t y , char * str , uint16_t color , uint8_t flag )
2018-08-28 17:13:14 +01:00
{
dsp_x = x ;
dsp_y = y ;
dsp_str = str ;
dsp_color = color ;
dsp_flag = flag ;
XdspCall ( FUNC_DISPLAY_DRAW_STRING ) ;
}
2023-02-05 11:52:21 +00:00
void DisplayOnOff ( uint8_t on ) {
if ( disp_device ) {
ExecuteCommandPower ( disp_device , on , SRC_DISPLAY ) ;
}
2018-08-28 17:13:14 +01:00
}
/*-------------------------------------------------------------------------------------------*/
2019-08-19 12:21:54 +01:00
// get asci float number
uint8_t fatoiv ( char * cp , float * res ) {
uint8_t index = 0 ;
* res = CharToFloat ( cp ) ;
while ( * cp ) {
if ( ( * cp > = ' 0 ' & & * cp < = ' 9 ' ) | | ( * cp = = ' - ' ) | | ( * cp = = ' . ' ) ) {
cp + + ;
index + + ;
} else {
break ;
}
}
return index ;
}
2018-08-28 17:13:14 +01:00
// get asci number until delimiter and return asci number lenght and value
uint8_t atoiv ( char * cp , int16_t * res )
{
uint8_t index = 0 ;
* res = atoi ( cp ) ;
while ( * cp ) {
if ( ( * cp > = ' 0 ' & & * cp < = ' 9 ' ) | | ( * cp = = ' - ' ) ) {
cp + + ;
index + + ;
} else {
break ;
}
}
return index ;
}
// get asci number until delimiter and return asci number lenght and value
uint8_t atoiV ( char * cp , uint16_t * res )
{
uint8_t index = 0 ;
* res = atoi ( cp ) ;
while ( * cp ) {
if ( * cp > = ' 0 ' & & * cp < = ' 9 ' ) {
cp + + ;
index + + ;
} else {
break ;
}
}
return index ;
}
2019-08-19 12:21:54 +01:00
// right align string
void alignright ( char * string ) {
uint16_t slen = strlen ( string ) ;
uint16_t len = slen ;
while ( len ) {
// count spaces to the right
if ( string [ len - 1 ] ! = ' ' ) {
break ;
}
len - - ;
}
uint16_t diff = slen - len ;
if ( diff > 0 ) {
// move string
memmove ( & string [ diff ] , string , len ) ;
memset ( string , ' ' , diff ) ;
}
}
char * get_string ( char * buff , uint8_t len , char * cp ) {
uint8_t index = 0 ;
while ( * cp ! = ' : ' ) {
buff [ index ] = * cp + + ;
index + + ;
if ( index > = len ) break ;
}
buff [ index ] = 0 ;
cp + + ;
return cp ;
}
# define ESCAPE_CHAR '~'
// decode text escapes, 1 hexbyte assumed
2020-01-01 14:13:58 +00:00
uint32_t decode_te ( char * line ) {
uint32_t skip = 0 ;
2019-08-19 12:21:54 +01:00
char sbuf [ 3 ] , * cp ;
while ( * line ) {
if ( * line = = ESCAPE_CHAR ) {
cp = line + 1 ;
if ( * cp ! = 0 & & * cp = = ESCAPE_CHAR ) {
// escape escape, discard one
memmove ( cp , cp + 1 , strlen ( cp ) ) ;
2020-01-01 14:13:58 +00:00
skip + + ;
2019-08-19 12:21:54 +01:00
} else {
// escape HH
if ( strlen ( cp ) < 2 ) {
// illegal lenght, ignore
2020-01-01 14:13:58 +00:00
return skip ;
2019-08-19 12:21:54 +01:00
}
// take 2 hex chars
sbuf [ 0 ] = * ( cp ) ;
sbuf [ 1 ] = * ( cp + 1 ) ;
sbuf [ 2 ] = 0 ;
* line = strtol ( sbuf , 0 , 16 ) ;
// must shift string 2 bytes shift zero also
memmove ( cp , cp + 2 , strlen ( cp ) - 1 ) ;
2020-01-01 14:13:58 +00:00
skip + = 2 ;
2019-08-19 12:21:54 +01:00
}
}
line + + ;
}
2020-01-01 14:13:58 +00:00
return skip ;
2019-08-19 12:21:54 +01:00
}
2021-09-14 21:40:26 +01:00
/*-------------------------------------------------------------------------------------------*/
// Getter and Setter for DisplayDimer
// Original encoding is range 0..15
// New encoding is range 0..100 using negative numbers, i.e. 0..-100
uint8_t GetDisplayDimmer ( void ) {
if ( Settings - > display_dimmer_protected > 0 ) {
return changeUIntScale ( Settings - > display_dimmer_protected , 0 , 15 , 0 , 100 ) ;
} else {
if ( Settings - > display_dimmer_protected < - 100 ) { Settings - > display_dimmer_protected = - 100 ; }
return - Settings - > display_dimmer_protected ;
}
}
// retro-compatible call to get range 0..15
uint8_t GetDisplayDimmer16 ( void ) {
return changeUIntScale ( GetDisplayDimmer ( ) , 0 , 100 , 0 , 15 ) ;
}
// In: 0..100
void SetDisplayDimmer ( uint8_t dimmer ) {
if ( dimmer > 100 ) { dimmer = 100 ; }
Settings - > display_dimmer_protected = - dimmer ;
}
2018-08-28 17:13:14 +01:00
/*-------------------------------------------------------------------------------------------*/
# define DISPLAY_BUFFER_COLS 128 // Max number of characters in linebuf
2021-02-14 14:00:57 +00:00
uint16_t GetColorFromIndex ( uint32_t index ) {
if ( index > = MAX_INDEXCOLORS ) index = 0 ;
2021-02-18 09:57:12 +00:00
if ( index < PREDEF_INDEXCOLORS ) {
return renderer - > GetColorFromIndex ( index ) ;
} else {
return index_colors [ index - PREDEF_INDEXCOLORS ] ;
}
2021-02-14 14:00:57 +00:00
}
2018-11-14 13:32:09 +00:00
void DisplayText ( void )
2018-08-28 17:13:14 +01:00
{
uint8_t lpos ;
uint8_t escape = 0 ;
uint8_t var ;
int16_t lin = 0 ;
int16_t col = 0 ;
int16_t fill = 0 ;
int16_t temp ;
int16_t temp1 ;
2019-08-19 12:21:54 +01:00
float ftemp ;
2018-08-28 17:13:14 +01:00
char linebuf [ DISPLAY_BUFFER_COLS ] ;
char * dp = linebuf ;
char * cp = XdrvMailbox . data ;
memset ( linebuf , ' ' , sizeof ( linebuf ) ) ;
linebuf [ sizeof ( linebuf ) - 1 ] = 0 ;
* dp = 0 ;
while ( * cp ) {
if ( ! escape ) {
// check for escape
if ( * cp = = ' [ ' ) {
escape = 1 ;
cp + + ;
// if string in buffer print it
2022-12-09 08:32:14 +00:00
dp - = decode_te ( linebuf ) ;
2018-08-28 17:13:14 +01:00
if ( ( uint32_t ) dp - ( uint32_t ) linebuf ) {
if ( ! fill ) { * dp = 0 ; }
if ( col > 0 & & lin > 0 ) {
// use col and lin
2019-08-19 12:21:54 +01:00
if ( ! renderer ) DisplayDrawStringAt ( col , lin , linebuf , fg_color , 1 ) ;
else renderer - > DrawStringAt ( col , lin , linebuf , fg_color , 1 ) ;
2018-08-28 17:13:14 +01:00
} else {
// use disp_xpos, disp_ypos
2019-08-19 12:21:54 +01:00
if ( ! renderer ) DisplayDrawStringAt ( disp_xpos , disp_ypos , linebuf , fg_color , 0 ) ;
else renderer - > DrawStringAt ( disp_xpos , disp_ypos , linebuf , fg_color , 0 ) ;
2018-08-28 17:13:14 +01:00
}
memset ( linebuf , ' ' , sizeof ( linebuf ) ) ;
linebuf [ sizeof ( linebuf ) - 1 ] = 0 ;
dp = linebuf ;
}
} else {
// copy chars
if ( dp < ( linebuf + DISPLAY_BUFFER_COLS ) ) { * dp + + = * cp + + ; }
}
} else {
// check escapes
if ( * cp = = ' ] ' ) {
escape = 0 ;
cp + + ;
} else {
// analyze escapes
switch ( * cp + + ) {
case ' z ' :
// clear display
2019-08-19 12:21:54 +01:00
if ( ! renderer ) DisplayClear ( ) ;
else renderer - > fillScreen ( bg_color ) ;
2018-08-28 17:13:14 +01:00
disp_xpos = 0 ;
disp_ypos = 0 ;
col = 0 ;
lin = 0 ;
break ;
case ' i ' :
// init display with partial update
DisplayInit ( DISPLAY_INIT_PARTIAL ) ;
break ;
case ' I ' :
// init display with full refresh
DisplayInit ( DISPLAY_INIT_FULL ) ;
break ;
case ' o ' :
2020-08-17 13:49:24 +01:00
DisplayOnOff ( 0 ) ;
2018-08-28 17:13:14 +01:00
break ;
case ' O ' :
2020-08-17 13:49:24 +01:00
DisplayOnOff ( 1 ) ;
2018-08-28 17:13:14 +01:00
break ;
case ' x ' :
// set disp_xpos
var = atoiv ( cp , & disp_xpos ) ;
cp + = var ;
break ;
case ' y ' :
// set disp_ypos
var = atoiv ( cp , & disp_ypos ) ;
cp + = var ;
break ;
case ' l ' :
// text line lxx
var = atoiv ( cp , & lin ) ;
cp + = var ;
//display.setCursor(display.getCursorX(),(lin-1)*font_y*txtsize);
break ;
case ' c ' :
// text column cxx
var = atoiv ( cp , & col ) ;
cp + = var ;
//display.setCursor((col-1)*font_x*txtsize,display.getCursorY());
break ;
case ' C ' :
// text color cxx
2019-08-19 12:21:54 +01:00
if ( * cp = = ' i ' ) {
// color index 0-18
cp + + ;
var = atoiv ( cp , & temp ) ;
2021-02-14 14:00:57 +00:00
if ( renderer ) ftemp = GetColorFromIndex ( temp ) ;
2019-08-19 12:21:54 +01:00
} else {
// float because it must handle unsigned 16 bit
var = fatoiv ( cp , & ftemp ) ;
}
fg_color = ftemp ;
cp + = var ;
if ( renderer ) renderer - > setTextColor ( fg_color , bg_color ) ;
break ;
case ' B ' :
// bg color Bxx
if ( * cp = = ' i ' ) {
// color index 0-18
cp + + ;
var = atoiv ( cp , & temp ) ;
2021-02-14 14:00:57 +00:00
if ( renderer ) ftemp = GetColorFromIndex ( temp ) ;
2019-08-19 12:21:54 +01:00
} else {
var = fatoiv ( cp , & ftemp ) ;
}
bg_color = ftemp ;
2018-08-28 17:13:14 +01:00
cp + = var ;
2019-08-19 12:21:54 +01:00
if ( renderer ) renderer - > setTextColor ( fg_color , bg_color ) ;
2018-08-28 17:13:14 +01:00
break ;
case ' p ' :
// pad field with spaces fxx
var = atoiv ( cp , & fill ) ;
cp + = var ;
break ;
2021-02-14 11:22:08 +00:00
# ifdef USE_UFILESYS
2019-08-19 12:21:54 +01:00
case ' P ' :
2022-12-09 08:32:14 +00:00
{ char * ep = strchr ( cp , ' : ' ) ;
2019-08-19 12:21:54 +01:00
if ( ep ) {
2022-12-09 08:32:14 +00:00
* ep = 0 ;
2019-08-19 12:21:54 +01:00
ep + + ;
2022-12-09 08:32:14 +00:00
int16_t scale = 0 ;
if ( isdigit ( * ep ) ) {
var = atoiv ( ep , & scale ) ;
ep + = var ;
}
Draw_RGB_Bitmap ( cp , disp_xpos , disp_ypos , scale , false ) ;
cp = ep ;
2019-08-19 12:21:54 +01:00
}
}
break ;
2021-04-21 10:01:40 +01:00
# ifdef USE_MULTI_DISPLAY
case ' S ' :
2021-09-30 18:09:38 +01:00
{ int16_t rot = - 1 , srot , model ;
2021-04-21 10:01:40 +01:00
var = atoiv ( cp , & temp ) ;
cp + = var ;
2021-09-23 08:51:51 +01:00
if ( temp < 1 | | temp > MAX_MULTI_DISPLAYS ) {
2021-04-21 10:01:40 +01:00
temp = 1 ;
}
temp - - ;
2021-09-30 18:09:38 +01:00
if ( * cp = = ' r ' ) {
cp + + ;
var = atoiv ( cp , & rot ) ;
cp + = var ;
}
2021-04-21 10:01:40 +01:00
if ( * cp = = ' : ' ) {
cp + + ;
2021-09-30 18:09:38 +01:00
if ( displays [ temp ] . used ) {
2021-04-21 10:01:40 +01:00
Set_display ( cur_display ) ;
Get_display ( temp ) ;
}
} else {
char * ep = strchr ( cp , ' : ' ) ;
if ( ep ) {
* ep = 0 ;
ep + + ;
File fp ;
if ( ffsp ) {
AddLog ( LOG_LEVEL_INFO , PSTR ( " DSP: File: %s " ) , cp ) ;
fp = ffsp - > open ( cp , " r " ) ;
if ( fp > 0 ) {
uint32_t size = fp . size ( ) ;
char * fdesc = ( char * ) calloc ( size + 4 , 1 ) ;
if ( fdesc ) {
2021-09-30 18:09:38 +01:00
model = Settings - > display_model ;
2021-04-21 10:01:40 +01:00
fp . read ( ( uint8_t * ) fdesc , size ) ;
fp . close ( ) ;
2024-03-31 07:16:15 +01:00
if ( renderer ) {
// save ptr
Set_display ( temp ) ;
renderer = nullptr ;
} else {
Renderer * svptr = renderer ;
Get_display ( temp ) ;
renderer = svptr ;
if ( rot > = 0 ) {
srot = Settings - > display_rotate ;
Settings - > display_rotate = rot ;
}
2021-09-30 18:09:38 +01:00
}
2024-03-31 07:16:15 +01:00
renderer = Init_uDisplay ( fdesc ) ;
2021-09-30 18:09:38 +01:00
if ( rot > = 0 ) {
Settings - > display_rotate = srot ;
}
2021-04-21 10:01:40 +01:00
Set_display ( temp ) ;
2023-01-22 09:56:06 +00:00
AddLog ( LOG_LEVEL_INFO , PSTR ( " DSP: File descriptor loaded " ) ) ;
2021-09-23 08:51:51 +01:00
free ( fdesc ) ;
2021-09-30 18:09:38 +01:00
Settings - > display_model = model ;
2021-04-21 10:01:40 +01:00
}
}
}
}
cp = ep ;
}
}
break ;
# endif // USE_MULTI_DISPLAY
2021-02-14 11:22:08 +00:00
# endif // USE_UFILESYS
2018-08-28 17:13:14 +01:00
case ' h ' :
// hor line to
var = atoiv ( cp , & temp ) ;
cp + = var ;
if ( temp < 0 ) {
2019-08-19 12:21:54 +01:00
if ( renderer ) renderer - > writeFastHLine ( disp_xpos + temp , disp_ypos , - temp , fg_color ) ;
2021-02-15 16:22:06 +00:00
//else DisplayDrawHLine(disp_xpos + temp, disp_ypos, -temp, fg_color);
2018-08-28 17:13:14 +01:00
} else {
2019-08-19 12:21:54 +01:00
if ( renderer ) renderer - > writeFastHLine ( disp_xpos , disp_ypos , temp , fg_color ) ;
2021-02-15 16:22:06 +00:00
//else DisplayDrawHLine(disp_xpos, disp_ypos, temp, fg_color);
2018-08-28 17:13:14 +01:00
}
disp_xpos + = temp ;
break ;
case ' v ' :
// vert line to
var = atoiv ( cp , & temp ) ;
cp + = var ;
if ( temp < 0 ) {
2019-08-19 12:21:54 +01:00
if ( renderer ) renderer - > writeFastVLine ( disp_xpos , disp_ypos + temp , - temp , fg_color ) ;
2021-02-15 16:22:06 +00:00
//else DisplayDrawVLine(disp_xpos, disp_ypos + temp, -temp, fg_color);
2018-08-28 17:13:14 +01:00
} else {
2019-08-19 12:21:54 +01:00
if ( renderer ) renderer - > writeFastVLine ( disp_xpos , disp_ypos , temp , fg_color ) ;
2021-02-15 16:22:06 +00:00
//else DisplayDrawVLine(disp_xpos, disp_ypos, temp, fg_color);
2018-08-28 17:13:14 +01:00
}
disp_ypos + = temp ;
break ;
case ' L ' :
// any line to
var = atoiv ( cp , & temp ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & temp1 ) ;
cp + = var ;
2019-08-19 12:21:54 +01:00
if ( renderer ) renderer - > writeLine ( disp_xpos , disp_ypos , temp , temp1 , fg_color ) ;
2021-02-15 16:22:06 +00:00
//else DisplayDrawLine(disp_xpos, disp_ypos, temp, temp1, fg_color);
2018-08-28 17:13:14 +01:00
disp_xpos + = temp ;
disp_ypos + = temp1 ;
break ;
case ' k ' :
// circle
var = atoiv ( cp , & temp ) ;
cp + = var ;
2019-08-19 12:21:54 +01:00
if ( renderer ) renderer - > drawCircle ( disp_xpos , disp_ypos , temp , fg_color ) ;
2021-02-15 16:22:06 +00:00
//else DisplayDrawCircle(disp_xpos, disp_ypos, temp, fg_color);
2018-08-28 17:13:14 +01:00
break ;
case ' K ' :
// filled circle
var = atoiv ( cp , & temp ) ;
cp + = var ;
2019-08-19 12:21:54 +01:00
if ( renderer ) renderer - > fillCircle ( disp_xpos , disp_ypos , temp , fg_color ) ;
2021-02-15 16:22:06 +00:00
//else DisplayDrawFilledCircle(disp_xpos, disp_ypos, temp, fg_color);
2018-08-28 17:13:14 +01:00
break ;
2021-11-16 07:12:23 +00:00
case ' m ' :
// epaper draw mode currently only for 4,7 inch displays
var = atoiv ( cp , & temp ) ;
cp + = var ;
if ( renderer ) renderer - > ep_update_mode ( temp ) ;
break ;
2018-08-28 17:13:14 +01:00
case ' r ' :
// rectangle
var = atoiv ( cp , & temp ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & temp1 ) ;
cp + = var ;
2019-08-19 12:21:54 +01:00
if ( renderer ) renderer - > drawRect ( disp_xpos , disp_ypos , temp , temp1 , fg_color ) ;
2021-02-15 16:22:06 +00:00
//else DisplayDrawRectangle(disp_xpos, disp_ypos, temp, temp1, fg_color);
2018-08-28 17:13:14 +01:00
break ;
case ' R ' :
// filled rectangle
var = atoiv ( cp , & temp ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & temp1 ) ;
cp + = var ;
2019-08-19 12:21:54 +01:00
if ( renderer ) renderer - > fillRect ( disp_xpos , disp_ypos , temp , temp1 , fg_color ) ;
2021-02-15 16:22:06 +00:00
//else DisplayDrawFilledRectangle(disp_xpos, disp_ypos, temp, temp1, fg_color);
2019-08-19 12:21:54 +01:00
break ;
case ' u ' :
// rounded rectangle
2021-11-16 07:12:23 +00:00
{ int16_t rad , xp , yp , width , height ;
if ( * cp = = ' p ' ) {
// update epaper display
cp + + ;
var = atoiv ( cp , & xp ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & yp ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & width ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & height ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & temp ) ;
cp + = var ;
if ( renderer ) renderer - > ep_update_area ( xp , yp , width , height , temp ) ;
break ;
}
2019-08-19 12:21:54 +01:00
var = atoiv ( cp , & temp ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & temp1 ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & rad ) ;
cp + = var ;
if ( renderer ) renderer - > drawRoundRect ( disp_xpos , disp_ypos , temp , temp1 , rad , fg_color ) ;
//else DisplayDrawFilledRectangle(disp_xpos, disp_ypos, temp, temp1, fg_color);
}
break ;
case ' U ' :
// rounded rectangle
{ int16_t rad ;
var = atoiv ( cp , & temp ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & temp1 ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & rad ) ;
cp + = var ;
if ( renderer ) renderer - > fillRoundRect ( disp_xpos , disp_ypos , temp , temp1 , rad , fg_color ) ;
//else DisplayDrawFilledRectangle(disp_xpos, disp_ypos, temp, temp1, fg_color);
}
2018-08-28 17:13:14 +01:00
break ;
2019-08-19 12:21:54 +01:00
2019-01-09 13:14:55 +00:00
case ' t ' :
2019-08-19 12:21:54 +01:00
if ( * cp = = ' S ' ) {
cp + + ;
if ( dp < ( linebuf + DISPLAY_BUFFER_COLS ) - 8 ) {
snprintf_P ( dp , 9 , PSTR ( " %02d " D_HOUR_MINUTE_SEPARATOR " %02d " D_MINUTE_SECOND_SEPARATOR " %02d " ) , RtcTime . hour , RtcTime . minute , RtcTime . second ) ;
dp + = 8 ;
}
} else {
if ( dp < ( linebuf + DISPLAY_BUFFER_COLS ) - 5 ) {
snprintf_P ( dp , 6 , PSTR ( " %02d " D_HOUR_MINUTE_SEPARATOR " %02d " ) , RtcTime . hour , RtcTime . minute ) ;
dp + = 5 ;
}
2018-08-28 17:13:14 +01:00
}
break ;
2020-09-15 11:02:27 +01:00
case ' T ' : {
uint8_t param1 = RtcTime . day_of_month ;
uint8_t param2 = RtcTime . month ;
if ( * cp = = ' U ' ) {
cp + + ;
param1 = RtcTime . month ;
param2 = RtcTime . day_of_month ;
}
2019-01-09 13:14:55 +00:00
if ( dp < ( linebuf + DISPLAY_BUFFER_COLS ) - 8 ) {
2020-09-15 11:02:27 +01:00
snprintf_P ( dp , 9 , PSTR ( " %02d " D_MONTH_DAY_SEPARATOR " %02d " D_YEAR_MONTH_SEPARATOR " %02d " ) , param1 , param2 , RtcTime . year % 2000 ) ;
2019-01-09 13:14:55 +00:00
dp + = 8 ;
}
2020-09-15 11:02:27 +01:00
break ; }
2018-08-28 17:13:14 +01:00
case ' d ' :
2021-02-14 14:00:57 +00:00
if ( * cp = = ' c ' ) {
cp + + ;
// define index colo
var = atoiv ( cp , & temp ) ;
cp + = var ;
cp + + ;
var = fatoiv ( cp , & ftemp ) ;
cp + = var ;
2021-02-18 09:57:12 +00:00
if ( temp > = MAX_INDEXCOLORS ) temp = PREDEF_INDEXCOLORS ;
if ( temp < PREDEF_INDEXCOLORS ) temp = PREDEF_INDEXCOLORS ;
index_colors [ temp - PREDEF_INDEXCOLORS ] = ftemp ;
2021-02-14 14:00:57 +00:00
break ;
}
2021-02-15 16:22:06 +00:00
# ifdef USE_DT_VARS
2021-02-18 09:57:12 +00:00
if ( * cp = = ' v ' ) {
cp + + ;
{ int16_t num , gxp , gyp , textbcol , textfcol , font , textsize , txlen , dp , time ;
var = atoiv ( cp , & num ) ;
cp + = var ;
2021-02-15 16:22:06 +00:00
cp + + ;
2021-02-18 09:57:12 +00:00
var = atoiv ( cp , & gxp ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & gyp ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & textbcol ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & textfcol ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & font ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & textsize ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & txlen ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & dp ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & time ) ;
cp + = var ;
cp + + ;
// text itself
char bbuff [ 32 ] ;
cp = get_string ( bbuff , sizeof ( bbuff ) , cp ) ;
char unit [ 4 ] ;
cp = get_string ( unit , sizeof ( unit ) , cp ) ;
2022-12-09 08:32:14 +00:00
decode_te ( unit ) ;
2021-02-18 09:57:12 +00:00
define_dt_var ( num , gxp , gyp , textbcol , textfcol , font , textsize , txlen , time , dp , bbuff , unit ) ;
2021-02-15 16:22:06 +00:00
}
2021-02-18 09:57:12 +00:00
}
2021-02-15 16:22:06 +00:00
# endif // USE_DT_VARS
2018-08-28 17:13:14 +01:00
// force draw grafics buffer
2019-08-19 12:21:54 +01:00
if ( renderer ) renderer - > Updateframe ( ) ;
2021-02-15 16:22:06 +00:00
//else DisplayDrawFrame();
2018-08-28 17:13:14 +01:00
break ;
case ' D ' :
// set auto draw mode
2019-08-19 12:21:54 +01:00
auto_draw = * cp & 3 ;
if ( renderer ) renderer - > setDrawMode ( auto_draw > > 1 ) ;
2018-08-28 17:13:14 +01:00
cp + = 1 ;
break ;
case ' s ' :
// size sx
2021-12-08 15:32:02 +00:00
var = atoiv ( cp , & temp ) ;
if ( temp > TXT_MAX_SFAC ) temp = TXT_MAX_SFAC ;
if ( renderer ) renderer - > setTextSize ( temp ) ;
2021-02-15 16:22:06 +00:00
//else DisplaySetSize(*cp&3);
2021-12-08 15:32:02 +00:00
cp + = var ;
2018-08-28 17:13:14 +01:00
break ;
case ' f ' :
// font sx
2021-02-13 06:43:59 +00:00
{ uint8_t font = * cp & 7 ;
if ( renderer ) renderer - > setTextFont ( font ) ;
2021-02-15 16:22:06 +00:00
//else DisplaySetFont(font);
2021-02-13 06:43:59 +00:00
if ( font ) {
// for backward compatibility set size to 1 on non GFX fonts
if ( renderer ) renderer - > setTextSize ( 1 ) ;
2021-02-15 16:22:06 +00:00
//else DisplaySetSize(1);
2021-02-13 06:43:59 +00:00
}
cp + = 1 ;
}
2018-08-28 17:13:14 +01:00
break ;
2021-04-18 08:20:54 +01:00
# ifdef USE_UFILESYS
# ifdef USE_RAMFONT
extern FS * ffsp ;
case ' F ' :
{ char * ep = strchr ( cp , ' : ' ) ;
if ( ep ) {
static uint8_t * ram_font ;
2021-04-21 10:01:40 +01:00
char fname [ 32 ] ;
2021-04-18 08:20:54 +01:00
* ep = 0 ;
ep + + ;
2021-04-24 11:31:14 +01:00
if ( * cp = = ' - ' & & * ( cp + 1 ) = = 0 ) {
if ( ram_font ) {
free ( ram_font ) ;
ram_font = 0 ;
if ( renderer ) renderer - > SetRamfont ( 0 ) ;
}
cp = ep ;
2021-04-19 16:01:33 +01:00
} else {
2021-04-24 11:31:14 +01:00
if ( * cp ! = ' / ' ) {
fname [ 0 ] = ' / ' ;
fname [ 1 ] = 0 ;
} else {
fname [ 0 ] = 0 ;
}
strlcat ( fname , cp , sizeof ( fname ) ) ;
if ( ! strstr ( cp , " .fnt " ) ) {
strlcat ( fname , " .fnt " , sizeof ( fname ) ) ;
}
if ( ffsp ) {
File fp ;
fp = ffsp - > open ( fname , " r " ) ;
if ( fp > 0 ) {
uint32_t size = fp . size ( ) ;
if ( ram_font ) free ( ram_font ) ;
ram_font = ( uint8_t * ) special_malloc ( size + 4 ) ;
fp . read ( ( uint8_t * ) ram_font , size ) ;
fp . close ( ) ;
if ( renderer ) renderer - > SetRamfont ( ram_font ) ;
//Serial.printf("Font loaded: %s\n",fname );
}
2021-04-18 08:20:54 +01:00
}
}
cp = ep ;
}
}
break ;
# endif // USE_RAMFONT
# endif // USE_UFILESYS
2018-08-28 17:13:14 +01:00
case ' a ' :
// rotation angle
2019-08-19 12:21:54 +01:00
if ( renderer ) renderer - > setRotation ( * cp & 3 ) ;
2021-02-15 16:22:06 +00:00
//else DisplaySetRotation(*cp&3);
2018-08-28 17:13:14 +01:00
cp + = 1 ;
break ;
2019-08-19 12:21:54 +01:00
# ifdef USE_GRAPH
case ' G ' :
// define graph
if ( * cp = = ' d ' ) {
cp + + ;
var = atoiv ( cp , & temp ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & temp1 ) ;
cp + = var ;
RedrawGraph ( temp , temp1 ) ;
break ;
}
2021-01-20 14:06:34 +00:00
# if (defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT)) || defined(USE_UFILESYS)
2019-08-19 12:21:54 +01:00
if ( * cp = = ' s ' ) {
cp + + ;
var = atoiv ( cp , & temp ) ;
cp + = var ;
cp + + ;
// path
char bbuff [ 128 ] ;
cp = get_string ( bbuff , sizeof ( bbuff ) , cp ) ;
Save_graph ( temp , bbuff ) ;
break ;
}
if ( * cp = = ' r ' ) {
cp + + ;
var = atoiv ( cp , & temp ) ;
cp + = var ;
cp + + ;
// path
char bbuff [ 128 ] ;
cp = get_string ( bbuff , sizeof ( bbuff ) , cp ) ;
Restore_graph ( temp , bbuff ) ;
break ;
}
2020-09-11 14:45:21 +01:00
# endif // USE_SCRIPT_FATFS
2019-08-19 12:21:54 +01:00
{ int16_t num , gxp , gyp , gxs , gys , dec , icol ;
float ymin , ymax ;
var = atoiv ( cp , & num ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & gxp ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & gyp ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & gxs ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & gys ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & dec ) ;
cp + = var ;
cp + + ;
var = fatoiv ( cp , & ymin ) ;
cp + = var ;
cp + + ;
var = fatoiv ( cp , & ymax ) ;
cp + = var ;
if ( color_type = = COLOR_COLOR ) {
// color graph requires channel color
cp + + ;
var = atoiv ( cp , & icol ) ;
cp + = var ;
} else {
icol = 0 ;
}
DefineGraph ( num , gxp , gyp , gxs , gys , dec , ymin , ymax , icol ) ;
}
break ;
case ' g ' :
{ float temp ;
int16_t num ;
var = atoiv ( cp , & num ) ;
cp + = var ;
cp + + ;
var = fatoiv ( cp , & temp ) ;
cp + = var ;
AddValue ( num , temp ) ;
}
break ;
2020-09-11 14:45:21 +01:00
# endif // USE_GRAPH
2019-08-19 12:21:54 +01:00
# ifdef USE_AWATCH
case ' w ' :
var = atoiv ( cp , & temp ) ;
cp + = var ;
DrawAClock ( temp ) ;
break ;
2020-09-11 14:45:21 +01:00
# endif // USE_AWATCH
2019-08-19 12:21:54 +01:00
# ifdef USE_TOUCH_BUTTONS
case ' b ' :
2021-02-14 11:22:08 +00:00
{ int16_t num , gxp , gyp , gxs , gys , outline , fill , textcolor , textsize ; uint8_t dflg = 1 , sbt = 0 ;
if ( * cp = = ' e ' | | * cp = = ' d ' ) {
2020-09-03 11:26:03 +01:00
// enable disable
2021-02-14 11:22:08 +00:00
uint8_t dis = 0 ;
if ( * cp = = ' d ' ) dis = 1 ;
2020-09-03 11:26:03 +01:00
cp + + ;
2021-02-14 11:22:08 +00:00
var = atoiv ( cp , & num ) ;
num = num % MAX_TOUCH_BUTTONS ;
cp + = var ;
2020-09-03 11:26:03 +01:00
if ( buttons [ num ] ) {
2021-02-14 11:22:08 +00:00
buttons [ num ] - > vpower . disable = dis ;
2020-09-03 11:26:03 +01:00
if ( ! dis ) {
if ( buttons [ num ] - > vpower . is_virtual ) buttons [ num ] - > xdrawButton ( buttons [ num ] - > vpower . on_off ) ;
2020-10-28 18:03:39 +00:00
else buttons [ num ] - > xdrawButton ( bitRead ( TasmotaGlobal . power , num ) ) ;
2020-09-03 11:26:03 +01:00
}
}
break ;
}
2021-02-14 11:22:08 +00:00
if ( * cp = = ' - ' ) {
2020-09-03 11:26:03 +01:00
cp + + ;
2021-02-14 11:22:08 +00:00
dflg = 0 ;
}
if ( * cp = = ' s ' ) {
cp + + ;
sbt = 1 ;
2020-09-03 11:26:03 +01:00
}
2019-08-19 12:21:54 +01:00
var = atoiv ( cp , & num ) ;
cp + = var ;
uint8_t bflags = num > > 8 ;
2021-01-20 14:12:41 +00:00
num = num % MAX_TOUCH_BUTTONS ;
2021-02-14 11:22:08 +00:00
if ( * cp = = ' s ' ) {
cp + + ;
var = atoiv ( cp , & gxp ) ;
if ( buttons [ num ] ) {
// set slider or button
if ( buttons [ num ] - > vpower . slider ) {
buttons [ num ] - > UpdateSlider ( - gxp , - gxp ) ;
} else {
buttons [ num ] - > vpower . on_off = gxp ;
buttons [ num ] - > xdrawButton ( buttons [ num ] - > vpower . on_off ) ;
}
}
break ;
}
cp + + ;
2019-08-19 12:21:54 +01:00
var = atoiv ( cp , & gxp ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & gyp ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & gxs ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & gys ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & outline ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & fill ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & textcolor ) ;
cp + = var ;
cp + + ;
var = atoiv ( cp , & textsize ) ;
cp + = var ;
cp + + ;
// text itself
char bbuff [ 32 ] ;
2021-02-14 11:22:08 +00:00
if ( ! sbt ) {
// text itself
cp = get_string ( bbuff , sizeof ( bbuff ) , cp ) ;
}
2019-08-19 12:21:54 +01:00
if ( buttons [ num ] ) {
delete buttons [ num ] ;
}
if ( renderer ) {
buttons [ num ] = new VButton ( ) ;
if ( buttons [ num ] ) {
2021-02-14 11:22:08 +00:00
if ( ! sbt ) {
buttons [ num ] - > vpower . slider = 0 ;
2021-11-16 07:12:23 +00:00
buttons [ num ] - > xinitButtonUL ( renderer , gxp , gyp , gxs , gys , GetColorFromIndex ( outline ) , \
2021-02-14 14:00:57 +00:00
GetColorFromIndex ( fill ) , GetColorFromIndex ( textcolor ) , bbuff , textsize ) ;
2021-02-14 11:22:08 +00:00
if ( ! bflags ) {
// power button
if ( dflg ) buttons [ num ] - > xdrawButton ( bitRead ( TasmotaGlobal . power , num ) ) ;
buttons [ num ] - > vpower . is_virtual = 0 ;
2020-09-03 11:26:03 +01:00
} else {
2021-02-14 11:22:08 +00:00
// virtual button
buttons [ num ] - > vpower . is_virtual = 1 ;
if ( bflags = = 2 ) {
// push
buttons [ num ] - > vpower . is_pushbutton = 1 ;
} else {
// toggle
buttons [ num ] - > vpower . is_pushbutton = 0 ;
}
if ( dflg ) buttons [ num ] - > xdrawButton ( buttons [ num ] - > vpower . on_off ) ;
buttons [ num ] - > vpower . disable = ! dflg ;
2020-09-03 11:26:03 +01:00
}
2021-02-14 11:22:08 +00:00
} else {
// slider
buttons [ num ] - > vpower . slider = 1 ;
2021-02-14 14:00:57 +00:00
buttons [ num ] - > SliderInit ( renderer , gxp , gyp , gxs , gys , outline , GetColorFromIndex ( fill ) , \
GetColorFromIndex ( textcolor ) , GetColorFromIndex ( textsize ) ) ;
2019-08-19 12:21:54 +01:00
}
}
}
}
break ;
2020-09-11 14:45:21 +01:00
# endif // USE_TOUCH_BUTTONS
2018-08-28 17:13:14 +01:00
default :
// unknown escape
2019-03-23 16:00:59 +00:00
Response_P ( PSTR ( " Unknown Escape " ) ) ;
2018-08-28 17:13:14 +01:00
goto exit ;
break ;
}
}
2019-01-09 13:56:16 +00:00
}
2018-08-28 17:13:14 +01:00
}
exit :
// now draw buffer
2020-01-01 14:13:58 +00:00
dp - = decode_te ( linebuf ) ;
2019-08-19 12:21:54 +01:00
if ( ( uint32_t ) dp - ( uint32_t ) linebuf ) {
2020-01-01 14:13:58 +00:00
if ( ! fill ) {
* dp = 0 ;
} else {
2020-04-10 17:24:08 +01:00
linebuf [ abs ( int ( fill ) ) ] = 0 ;
2020-01-01 14:13:58 +00:00
}
2019-08-19 12:21:54 +01:00
if ( fill < 0 ) {
// right align
alignright ( linebuf ) ;
}
if ( col > 0 & & lin > 0 ) {
// use col and lin
if ( ! renderer ) DisplayDrawStringAt ( col , lin , linebuf , fg_color , 1 ) ;
else renderer - > DrawStringAt ( col , lin , linebuf , fg_color , 1 ) ;
} else {
// use disp_xpos, disp_ypos
if ( ! renderer ) DisplayDrawStringAt ( disp_xpos , disp_ypos , linebuf , fg_color , 0 ) ;
else renderer - > DrawStringAt ( disp_xpos , disp_ypos , linebuf , fg_color , 0 ) ;
}
}
// draw buffer
if ( auto_draw & 1 ) {
if ( renderer ) renderer - > Updateframe ( ) ;
2021-02-15 16:22:06 +00:00
//else DisplayDrawFrame();
2018-08-28 17:13:14 +01:00
}
}
2021-05-01 08:54:05 +01:00
2021-02-14 14:00:57 +00:00
# ifdef USE_UFILESYS
void Display_Text_From_File ( const char * file ) {
File fp ;
2021-02-25 13:36:07 +00:00
if ( ! ufsp ) return ;
2021-02-14 14:00:57 +00:00
fp = ufsp - > open ( file , FS_FILE_READ ) ;
2021-04-11 11:32:02 +01:00
if ( fp > 0 ) {
2021-02-14 14:00:57 +00:00
char * savptr = XdrvMailbox . data ;
char linebuff [ 128 ] ;
while ( fp . available ( ) ) {
uint16_t index = 0 ;
while ( fp . available ( ) ) {
uint8_t buf [ 1 ] ;
fp . read ( buf , 1 ) ;
if ( buf [ 0 ] = = ' \n ' | | buf [ 0 ] = = ' \r ' ) {
break ;
} else {
linebuff [ index ] = buf [ 0 ] ;
index + + ;
if ( index > = sizeof ( linebuff ) - 1 ) {
break ;
}
}
}
linebuff [ index ] = 0 ;
char * cp = linebuff ;
while ( * cp = = ' ' ) cp + + ;
if ( * cp = = ' ; ' ) continue ;
//AddLog(LOG_LEVEL_INFO, PSTR("displaytext %s"), cp);
// execute display text here
XdrvMailbox . data = cp ;
XdrvMailbox . data_len = 0 ;
DisplayText ( ) ;
}
XdrvMailbox . data = savptr ;
fp . close ( ) ;
}
}
2021-04-11 11:32:02 +01:00
# endif // USE_UFILESYS
2021-02-14 14:00:57 +00:00
2021-02-15 16:22:06 +00:00
# ifdef USE_DT_VARS
2021-02-15 16:32:15 +00:00
# ifndef MAX_DT_VARS
2021-02-15 16:22:06 +00:00
# define MAX_DT_VARS 8
2021-02-15 16:32:15 +00:00
# endif // MAX_DT_VARS
2021-02-15 16:22:06 +00:00
# define MAX_DVTSIZE 24
typedef struct {
uint16_t xp ;
uint16_t yp ;
uint8_t txtbcol ;
uint8_t txtfcol ;
int8_t txtsiz ;
int8_t txtlen ;
int8_t dp ;
int8_t font ;
2021-02-18 09:57:12 +00:00
int8_t time ;
int8_t timer ;
2021-02-15 16:22:06 +00:00
char unit [ 6 ] ;
char * jstrbuf ;
char rstr [ 32 ] ;
} DT_VARS ;
DT_VARS * dt_vars [ MAX_DT_VARS ] ;
2021-02-18 09:57:12 +00:00
void define_dt_var ( uint32_t num , uint32_t xp , uint32_t yp , uint32_t txtbcol , uint32_t txtfcol , int32_t font , int32_t txtsiz , int32_t txtlen , int32_t time , int32_t dp , char * jstr , char * unit ) {
2021-02-15 16:22:06 +00:00
if ( num > = MAX_DT_VARS ) return ;
if ( dt_vars [ num ] ) {
if ( dt_vars [ num ] - > jstrbuf ) free ( dt_vars [ num ] - > jstrbuf ) ;
free ( dt_vars [ num ] ) ;
}
//dt [dv0:100:100:0:3:2:1:10:2:WLAN#ID:uV:]
DT_VARS * dtp = ( DT_VARS * ) malloc ( sizeof ( DT_VARS ) ) ;
if ( ! dtp ) return ;
dt_vars [ num ] = dtp ;
dtp - > xp = xp ;
dtp - > yp = yp ;
dtp - > txtbcol = txtbcol ;
dtp - > txtfcol = txtfcol ;
dtp - > font = font ;
dtp - > txtsiz = txtsiz ;
2021-02-18 09:57:12 +00:00
dtp - > time = time ;
2021-02-15 16:22:06 +00:00
if ( txtlen > MAX_DVTSIZE ) { txtlen = MAX_DVTSIZE ; }
dtp - > txtlen = txtlen ;
dtp - > dp = dp ;
2021-02-18 09:57:12 +00:00
uint8_t jlen = strlen ( jstr ) ;
dtp - > jstrbuf = ( char * ) calloc ( jlen + 2 , 1 ) ;
2021-02-15 16:22:06 +00:00
if ( ! dtp - > jstrbuf ) {
free ( dtp ) ;
return ;
}
2021-02-18 09:57:12 +00:00
dtp - > rstr [ 0 ] = 0 ;
strcpy ( dtp - > unit , unit ) ;
2021-02-15 16:22:06 +00:00
strcpy ( dtp - > jstrbuf , jstr ) ;
2021-02-18 09:57:12 +00:00
if ( ! time ) time = 1 ;
dtp - > timer = time ;
2021-02-15 16:22:06 +00:00
}
void draw_dt_vars ( void ) {
if ( ! renderer ) return ;
for ( uint32_t cnt = 0 ; cnt < MAX_DT_VARS ; cnt + + ) {
2021-02-18 09:57:12 +00:00
DT_VARS * dtp = dt_vars [ cnt ] ;
if ( dtp ) {
if ( dtp - > jstrbuf ) {
2021-02-15 16:22:06 +00:00
// draw
2021-02-18 09:57:12 +00:00
dtp - > timer - - ;
if ( ! dtp - > timer ) {
dtp - > timer = dtp - > time ;
char vstr [ MAX_DVTSIZE + 7 ] ;
memset ( vstr , ' ' , sizeof ( vstr ) ) ;
strcpy ( vstr , dtp - > rstr ) ;
strcat ( vstr , " " ) ;
strcat ( vstr , dtp - > unit ) ;
uint16_t slen = strlen ( vstr ) ;
vstr [ slen ] = ' ' ;
if ( ! dtp - > txtlen ) {
2021-02-15 16:22:06 +00:00
vstr [ slen ] = 0 ;
2021-02-18 09:57:12 +00:00
} else {
vstr [ abs ( int ( dtp - > txtlen ) ) ] = 0 ;
}
if ( dtp - > txtlen < 0 ) {
// right align
alignright ( vstr ) ;
}
2021-02-15 16:22:06 +00:00
2021-02-18 09:57:12 +00:00
if ( dtp - > txtsiz > 0 ) {
renderer - > setDrawMode ( 0 ) ;
} else {
renderer - > setDrawMode ( 2 ) ;
}
renderer - > setTextColor ( GetColorFromIndex ( dtp - > txtfcol ) , GetColorFromIndex ( dtp - > txtbcol ) ) ;
renderer - > setTextFont ( dtp - > font ) ;
renderer - > setTextSize ( abs ( dtp - > txtsiz ) ) ;
if ( dtp - > jstrbuf [ 0 ] = = ' [ ' ) {
uint16_t s_disp_xpos = disp_xpos ;
uint16_t s_disp_ypos = disp_ypos ;
uint16_t s_bg_color = bg_color ;
uint16_t s_fg_color = fg_color ;
disp_xpos = dtp - > xp ;
disp_ypos = dtp - > yp ;
bg_color = GetColorFromIndex ( dtp - > txtbcol ) ;
fg_color = GetColorFromIndex ( dtp - > txtfcol ) ;
char * savmbd = XdrvMailbox . data ;
XdrvMailbox . data = dtp - > jstrbuf ;
DisplayText ( ) ;
XdrvMailbox . data = savmbd ;
disp_xpos = s_disp_xpos ;
disp_ypos = s_disp_ypos ;
bg_color = s_bg_color ;
fg_color = s_fg_color ;
} else {
renderer - > DrawStringAt ( dtp - > xp , dtp - > yp , vstr , GetColorFromIndex ( dtp - > txtfcol ) , 0 ) ;
}
// restore display vars
renderer - > setTextColor ( fg_color , bg_color ) ;
2021-04-21 10:01:40 +01:00
renderer - > setDrawMode ( auto_draw > > 1 ) ;
2021-02-15 16:22:06 +00:00
}
}
}
}
}
# define DTV_JSON_SIZE 1024
2021-04-05 12:33:00 +01:00
void DisplayDTVarsTeleperiod ( void ) {
ResponseClear ( ) ;
MqttShowState ( ) ;
2021-05-24 15:52:59 +01:00
uint32_t jlen = ResponseLength ( ) ;
2021-04-05 12:33:00 +01:00
if ( jlen < DTV_JSON_SIZE ) {
char * json = ( char * ) malloc ( jlen + 2 ) ;
if ( json ) {
2021-08-15 16:08:31 +01:00
strlcpy ( json , ResponseData ( ) , jlen + 1 ) ;
2021-04-05 12:33:00 +01:00
get_dt_vars ( json ) ;
free ( json ) ;
2021-02-18 09:57:12 +00:00
}
2021-02-15 16:22:06 +00:00
}
}
void get_dt_mqtt ( void ) {
2021-04-05 12:33:00 +01:00
static uint8_t xsns_index = 0 ;
2021-02-15 16:22:06 +00:00
ResponseClear ( ) ;
uint16_t script_tele_period_save = TasmotaGlobal . tele_period ;
TasmotaGlobal . tele_period = 2 ;
2021-04-05 12:33:00 +01:00
XsnsNextCall ( FUNC_JSON_APPEND , xsns_index ) ;
2021-02-15 16:22:06 +00:00
TasmotaGlobal . tele_period = script_tele_period_save ;
2021-05-23 13:42:27 +01:00
if ( ResponseLength ( ) ) {
ResponseJsonStart ( ) ;
ResponseJsonEnd ( ) ;
2021-02-15 16:22:06 +00:00
}
2021-08-15 16:08:31 +01:00
get_dt_vars ( ResponseData ( ) ) ;
2021-02-15 16:22:06 +00:00
}
void get_dt_vars ( char * json ) {
if ( strlen ( json ) ) {
JsonParser parser ( json ) ;
JsonParserObject obj = parser . getRootObject ( ) ;
for ( uint32_t cnt = 0 ; cnt < MAX_DT_VARS ; cnt + + ) {
if ( dt_vars [ cnt ] ) {
2021-02-18 09:57:12 +00:00
if ( dt_vars [ cnt ] - > jstrbuf & & dt_vars [ cnt ] - > jstrbuf [ 0 ] ! = ' [ ' ) {
2021-02-15 16:22:06 +00:00
char sbuf [ 32 ] ;
uint32_t res = JsonParsePath ( & obj , dt_vars [ cnt ] - > jstrbuf , ' # ' , NULL , sbuf , sizeof ( sbuf ) ) ;
if ( res ) {
if ( dt_vars [ cnt ] - > dp < 0 ) {
// use string
strcpy ( dt_vars [ cnt ] - > rstr , sbuf ) ;
} else {
// convert back and forth
dtostrfd ( CharToFloat ( sbuf ) , dt_vars [ cnt ] - > dp , dt_vars [ cnt ] - > rstr ) ;
}
}
}
}
}
}
}
void free_dt_vars ( void ) {
for ( uint32_t cnt = 0 ; cnt < MAX_DT_VARS ; cnt + + ) {
if ( dt_vars [ cnt ] ) {
if ( dt_vars [ cnt ] - > jstrbuf ) free ( dt_vars [ cnt ] - > jstrbuf ) ;
free ( dt_vars [ cnt ] ) ;
dt_vars [ cnt ] = 0 ;
}
}
}
# endif // USE_DT_VARS
2018-08-28 17:13:14 +01:00
/*********************************************************************************************/
# ifdef USE_DISPLAY_MODES1TO5
2018-11-14 13:32:09 +00:00
void DisplayClearScreenBuffer ( void )
2018-08-28 17:13:14 +01:00
{
if ( disp_screen_buffer_cols ) {
2019-06-30 15:44:36 +01:00
for ( uint32_t i = 0 ; i < disp_screen_buffer_rows ; i + + ) {
2018-08-28 17:13:14 +01:00
memset ( disp_screen_buffer [ i ] , 0 , disp_screen_buffer_cols ) ;
}
}
}
2018-11-14 13:32:09 +00:00
void DisplayFreeScreenBuffer ( void )
2018-08-28 17:13:14 +01:00
{
2019-03-26 17:26:50 +00:00
if ( disp_screen_buffer ! = nullptr ) {
2019-06-30 15:44:36 +01:00
for ( uint32_t i = 0 ; i < disp_screen_buffer_rows ; i + + ) {
2019-03-26 17:26:50 +00:00
if ( disp_screen_buffer [ i ] ! = nullptr ) { free ( disp_screen_buffer [ i ] ) ; }
2018-08-28 17:13:14 +01:00
}
free ( disp_screen_buffer ) ;
disp_screen_buffer_cols = 0 ;
disp_screen_buffer_rows = 0 ;
}
}
2018-11-14 13:32:09 +00:00
void DisplayAllocScreenBuffer ( void )
2018-08-28 17:13:14 +01:00
{
if ( ! disp_screen_buffer_cols ) {
2021-06-11 17:14:12 +01:00
disp_screen_buffer_rows = Settings - > display_rows ;
2018-08-28 17:13:14 +01:00
disp_screen_buffer = ( char * * ) malloc ( sizeof ( * disp_screen_buffer ) * disp_screen_buffer_rows ) ;
2019-03-26 17:26:50 +00:00
if ( disp_screen_buffer ! = nullptr ) {
2019-06-30 15:44:36 +01:00
for ( uint32_t i = 0 ; i < disp_screen_buffer_rows ; i + + ) {
2021-06-11 17:14:12 +01:00
disp_screen_buffer [ i ] = ( char * ) malloc ( sizeof ( * disp_screen_buffer [ i ] ) * ( Settings - > display_cols [ 0 ] + 1 ) ) ;
2019-03-26 17:26:50 +00:00
if ( disp_screen_buffer [ i ] = = nullptr ) {
2018-08-28 17:13:14 +01:00
DisplayFreeScreenBuffer ( ) ;
break ;
}
}
}
2019-03-26 17:26:50 +00:00
if ( disp_screen_buffer ! = nullptr ) {
2021-06-11 17:14:12 +01:00
disp_screen_buffer_cols = Settings - > display_cols [ 0 ] + 1 ;
2018-08-28 17:13:14 +01:00
DisplayClearScreenBuffer ( ) ;
}
}
}
2018-11-14 13:32:09 +00:00
void DisplayReAllocScreenBuffer ( void )
2018-08-28 17:13:14 +01:00
{
DisplayFreeScreenBuffer ( ) ;
DisplayAllocScreenBuffer ( ) ;
}
2019-08-02 16:22:38 +01:00
void DisplayFillScreen ( uint32_t line )
2018-08-31 11:17:09 +01:00
{
2019-08-02 16:22:38 +01:00
uint32_t len = disp_screen_buffer_cols - strlen ( disp_screen_buffer [ line ] ) ;
2018-08-31 11:17:09 +01:00
if ( len ) {
memset ( disp_screen_buffer [ line ] + strlen ( disp_screen_buffer [ line ] ) , 0x20 , len ) ;
disp_screen_buffer [ line ] [ disp_screen_buffer_cols - 1 ] = 0 ;
}
}
2018-08-28 17:13:14 +01:00
/*-------------------------------------------------------------------------------------------*/
2018-11-14 13:32:09 +00:00
void DisplayClearLogBuffer ( void )
2018-08-28 17:13:14 +01:00
{
if ( disp_log_buffer_cols ) {
2019-06-30 15:44:36 +01:00
for ( uint32_t i = 0 ; i < DISPLAY_LOG_ROWS ; i + + ) {
2018-08-28 17:13:14 +01:00
memset ( disp_log_buffer [ i ] , 0 , disp_log_buffer_cols ) ;
}
}
}
2018-11-14 13:32:09 +00:00
void DisplayFreeLogBuffer ( void )
2018-08-28 17:13:14 +01:00
{
2019-03-26 17:26:50 +00:00
if ( disp_log_buffer ! = nullptr ) {
2019-06-30 15:44:36 +01:00
for ( uint32_t i = 0 ; i < DISPLAY_LOG_ROWS ; i + + ) {
2019-03-26 17:26:50 +00:00
if ( disp_log_buffer [ i ] ! = nullptr ) { free ( disp_log_buffer [ i ] ) ; }
2018-08-28 17:13:14 +01:00
}
free ( disp_log_buffer ) ;
disp_log_buffer_cols = 0 ;
}
}
2018-11-14 13:32:09 +00:00
void DisplayAllocLogBuffer ( void )
2018-08-28 17:13:14 +01:00
{
if ( ! disp_log_buffer_cols ) {
disp_log_buffer = ( char * * ) malloc ( sizeof ( * disp_log_buffer ) * DISPLAY_LOG_ROWS ) ;
2019-03-26 17:26:50 +00:00
if ( disp_log_buffer ! = nullptr ) {
2019-06-30 15:44:36 +01:00
for ( uint32_t i = 0 ; i < DISPLAY_LOG_ROWS ; i + + ) {
2021-06-11 17:14:12 +01:00
disp_log_buffer [ i ] = ( char * ) malloc ( sizeof ( * disp_log_buffer [ i ] ) * ( Settings - > display_cols [ 0 ] + 1 ) ) ;
2019-03-26 17:26:50 +00:00
if ( disp_log_buffer [ i ] = = nullptr ) {
2018-08-28 17:13:14 +01:00
DisplayFreeLogBuffer ( ) ;
break ;
}
}
}
2019-03-26 17:26:50 +00:00
if ( disp_log_buffer ! = nullptr ) {
2021-06-11 17:14:12 +01:00
disp_log_buffer_cols = Settings - > display_cols [ 0 ] + 1 ;
2018-08-28 17:13:14 +01:00
DisplayClearLogBuffer ( ) ;
}
}
}
2018-11-14 13:32:09 +00:00
void DisplayReAllocLogBuffer ( void )
2018-08-28 17:13:14 +01:00
{
DisplayFreeLogBuffer ( ) ;
DisplayAllocLogBuffer ( ) ;
}
2018-08-31 11:17:09 +01:00
void DisplayLogBufferAdd ( char * txt )
2018-08-28 17:13:14 +01:00
{
2018-08-31 11:17:09 +01:00
if ( disp_log_buffer_cols ) {
strlcpy ( disp_log_buffer [ disp_log_buffer_idx ] , txt , disp_log_buffer_cols ) ; // This preserves the % sign where printf won't
disp_log_buffer_idx + + ;
if ( DISPLAY_LOG_ROWS = = disp_log_buffer_idx ) { disp_log_buffer_idx = 0 ; }
2018-08-28 17:13:14 +01:00
}
}
2018-08-31 11:17:09 +01:00
char * DisplayLogBuffer ( char temp_code )
2018-08-28 17:13:14 +01:00
{
2019-03-26 17:26:50 +00:00
char * result = nullptr ;
2018-08-31 11:17:09 +01:00
if ( disp_log_buffer_cols ) {
if ( disp_log_buffer_idx ! = disp_log_buffer_ptr ) {
result = disp_log_buffer [ disp_log_buffer_ptr ] ;
disp_log_buffer_ptr + + ;
if ( DISPLAY_LOG_ROWS = = disp_log_buffer_ptr ) { disp_log_buffer_ptr = 0 ; }
2018-08-28 17:13:14 +01:00
2018-08-31 11:17:09 +01:00
char * pch = strchr ( result , ' ~ ' ) ; // = 0x7E (~) Replace degrees character (276 octal)
2019-03-26 17:26:50 +00:00
if ( pch ! = nullptr ) { result [ pch - result ] = temp_code ; }
2018-08-28 17:13:14 +01:00
}
}
2018-08-31 11:17:09 +01:00
return result ;
2018-08-28 17:13:14 +01:00
}
2018-11-14 13:32:09 +00:00
void DisplayLogBufferInit ( void )
2018-08-28 17:13:14 +01:00
{
2021-06-11 17:14:12 +01:00
if ( Settings - > display_mode ) {
2018-08-28 17:13:14 +01:00
disp_log_buffer_idx = 0 ;
disp_log_buffer_ptr = 0 ;
2021-06-11 17:14:12 +01:00
disp_refresh = Settings - > display_refresh ;
2018-08-28 17:13:14 +01:00
snprintf_P ( disp_temp , sizeof ( disp_temp ) , PSTR ( " %c " ) , TempUnit ( ) ) ;
2019-10-18 17:06:17 +01:00
snprintf_P ( disp_pres , sizeof ( disp_pres ) , PressureUnit ( ) . c_str ( ) ) ;
2018-08-28 17:13:14 +01:00
2018-08-31 11:17:09 +01:00
DisplayReAllocLogBuffer ( ) ;
2018-08-28 17:13:14 +01:00
2018-09-05 14:38:48 +01:00
char buffer [ 40 ] ;
2020-10-30 11:29:48 +00:00
snprintf_P ( buffer , sizeof ( buffer ) , PSTR ( D_VERSION " %s%s " ) , TasmotaGlobal . version , TasmotaGlobal . image_name ) ;
2018-08-31 11:17:09 +01:00
DisplayLogBufferAdd ( buffer ) ;
2021-06-11 17:14:12 +01:00
snprintf_P ( buffer , sizeof ( buffer ) , PSTR ( " Display mode %d " ) , Settings - > display_mode ) ;
2018-08-31 11:17:09 +01:00
DisplayLogBufferAdd ( buffer ) ;
2018-09-05 14:38:48 +01:00
2020-06-15 17:27:04 +01:00
snprintf_P ( buffer , sizeof ( buffer ) , PSTR ( D_CMND_HOSTNAME " %s " ) , NetworkHostname ( ) ) ;
2018-09-05 14:38:48 +01:00
DisplayLogBufferAdd ( buffer ) ;
2020-06-15 17:27:04 +01:00
snprintf_P ( buffer , sizeof ( buffer ) , PSTR ( D_JSON_MAC " %s " ) , NetworkMacAddress ( ) . c_str ( ) ) ;
2018-09-05 14:38:48 +01:00
DisplayLogBufferAdd ( buffer ) ;
2021-01-30 08:50:57 +00:00
ext_snprintf_P ( buffer , sizeof ( buffer ) , PSTR ( " IP %_I " ) , ( uint32_t ) NetworkAddress ( ) ) ;
2018-09-05 14:38:48 +01:00
DisplayLogBufferAdd ( buffer ) ;
2020-10-30 11:29:48 +00:00
if ( ! TasmotaGlobal . global_state . wifi_down ) {
2021-06-11 17:14:12 +01:00
snprintf_P ( buffer , sizeof ( buffer ) , PSTR ( D_JSON_SSID " %s " ) , SettingsText ( SET_STASSID1 + Settings - > sta_active ) ) ;
2018-09-05 14:38:48 +01:00
DisplayLogBufferAdd ( buffer ) ;
snprintf_P ( buffer , sizeof ( buffer ) , PSTR ( D_JSON_RSSI " %d%% " ) , WifiGetRssiAsQuality ( WiFi . RSSI ( ) ) ) ;
DisplayLogBufferAdd ( buffer ) ;
}
2018-08-28 17:13:14 +01:00
}
}
/*********************************************************************************************\
* Sensors
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
enum SensorQuantity {
JSON_TEMPERATURE ,
JSON_HUMIDITY , JSON_LIGHT , JSON_NOISE , JSON_AIRQUALITY ,
JSON_PRESSURE , JSON_PRESSUREATSEALEVEL ,
JSON_ILLUMINANCE ,
JSON_GAS ,
JSON_YESTERDAY , JSON_TOTAL , JSON_TODAY ,
JSON_PERIOD ,
JSON_POWERFACTOR , JSON_COUNTER , JSON_ANALOG_INPUT , JSON_UV_LEVEL ,
JSON_CURRENT ,
JSON_VOLTAGE ,
JSON_POWERUSAGE ,
2018-11-04 17:00:07 +00:00
JSON_CO2 ,
JSON_FREQUENCY } ;
2018-08-28 17:13:14 +01:00
const char kSensorQuantity [ ] PROGMEM =
D_JSON_TEMPERATURE " | " // degrees
D_JSON_HUMIDITY " | " D_JSON_LIGHT " | " D_JSON_NOISE " | " D_JSON_AIRQUALITY " | " // percentage
D_JSON_PRESSURE " | " D_JSON_PRESSUREATSEALEVEL " | " // hPa
D_JSON_ILLUMINANCE " | " // lx
D_JSON_GAS " | " // kOhm
D_JSON_YESTERDAY " | " D_JSON_TOTAL " | " D_JSON_TODAY " | " // kWh
D_JSON_PERIOD " | " // Wh
D_JSON_POWERFACTOR " | " D_JSON_COUNTER " | " D_JSON_ANALOG_INPUT " | " D_JSON_UV_LEVEL " | " // No unit
D_JSON_CURRENT " | " // Ampere
D_JSON_VOLTAGE " | " // Volt
D_JSON_POWERUSAGE " | " // Watt
2018-11-04 17:00:07 +00:00
D_JSON_CO2 " | " // ppm
D_JSON_FREQUENCY ; // Hz
2018-08-28 17:13:14 +01:00
2019-02-24 16:29:28 +00:00
void DisplayJsonValue ( const char * topic , const char * device , const char * mkey , const char * value )
2018-08-28 17:13:14 +01:00
{
char quantity [ TOPSZ ] ;
2021-06-11 17:14:12 +01:00
char buffer [ Settings - > display_cols [ 0 ] + 1 ] ;
char spaces [ Settings - > display_cols [ 0 ] ] ;
char source [ Settings - > display_cols [ 0 ] - Settings - > display_cols [ 1 ] ] ;
char svalue [ Settings - > display_cols [ 1 ] + 1 ] ;
2018-08-28 17:13:14 +01:00
2021-06-25 16:09:53 +01:00
SHOW_FREE_MEM ( PSTR ( " DisplayJsonValue " ) ) ;
2018-08-28 17:13:14 +01:00
memset ( spaces , 0x20 , sizeof ( spaces ) ) ;
spaces [ sizeof ( spaces ) - 1 ] = ' \0 ' ;
2019-02-24 16:29:28 +00:00
snprintf_P ( source , sizeof ( source ) , PSTR ( " %s%s%s%s " ) , topic , ( strlen ( topic ) ) ? " / " : " " , mkey , spaces ) ; // pow1/Voltage or Voltage if topic is empty (local sensor)
2018-08-28 17:13:14 +01:00
int quantity_code = GetCommandCode ( quantity , sizeof ( quantity ) , mkey , kSensorQuantity ) ;
if ( ( - 1 = = quantity_code ) | | ! strcmp_P ( mkey , S_RSLT_POWER ) ) { // Ok: Power, Not ok: POWER
return ;
}
if ( JSON_TEMPERATURE = = quantity_code ) {
snprintf_P ( svalue , sizeof ( svalue ) , PSTR ( " %s~%s " ) , value , disp_temp ) ;
}
else if ( ( quantity_code > = JSON_HUMIDITY ) & & ( quantity_code < = JSON_AIRQUALITY ) ) {
snprintf_P ( svalue , sizeof ( svalue ) , PSTR ( " %s%% " ) , value ) ;
}
else if ( ( quantity_code > = JSON_PRESSURE ) & & ( quantity_code < = JSON_PRESSUREATSEALEVEL ) ) {
2019-10-18 17:06:17 +01:00
snprintf_P ( svalue , sizeof ( svalue ) , PSTR ( " %s%s " ) , value , disp_pres ) ;
2018-08-28 17:13:14 +01:00
}
else if ( JSON_ILLUMINANCE = = quantity_code ) {
snprintf_P ( svalue , sizeof ( svalue ) , PSTR ( " %s " D_UNIT_LUX ) , value ) ;
}
else if ( JSON_GAS = = quantity_code ) {
snprintf_P ( svalue , sizeof ( svalue ) , PSTR ( " %s " D_UNIT_KILOOHM ) , value ) ;
}
else if ( ( quantity_code > = JSON_YESTERDAY ) & & ( quantity_code < = JSON_TODAY ) ) {
snprintf_P ( svalue , sizeof ( svalue ) , PSTR ( " %s " D_UNIT_KILOWATTHOUR ) , value ) ;
}
else if ( JSON_PERIOD = = quantity_code ) {
snprintf_P ( svalue , sizeof ( svalue ) , PSTR ( " %s " D_UNIT_WATTHOUR ) , value ) ;
}
else if ( ( quantity_code > = JSON_POWERFACTOR ) & & ( quantity_code < = JSON_UV_LEVEL ) ) {
snprintf_P ( svalue , sizeof ( svalue ) , PSTR ( " %s " ) , value ) ;
}
else if ( JSON_CURRENT = = quantity_code ) {
snprintf_P ( svalue , sizeof ( svalue ) , PSTR ( " %s " D_UNIT_AMPERE ) , value ) ;
}
else if ( JSON_VOLTAGE = = quantity_code ) {
snprintf_P ( svalue , sizeof ( svalue ) , PSTR ( " %s " D_UNIT_VOLT ) , value ) ;
}
else if ( JSON_POWERUSAGE = = quantity_code ) {
snprintf_P ( svalue , sizeof ( svalue ) , PSTR ( " %s " D_UNIT_WATT ) , value ) ;
}
else if ( JSON_CO2 = = quantity_code ) {
snprintf_P ( svalue , sizeof ( svalue ) , PSTR ( " %s " D_UNIT_PARTS_PER_MILLION ) , value ) ;
}
2018-11-04 17:00:07 +00:00
else if ( JSON_FREQUENCY = = quantity_code ) {
snprintf_P ( svalue , sizeof ( svalue ) , PSTR ( " %s " D_UNIT_HERTZ ) , value ) ;
}
2018-08-31 11:17:09 +01:00
snprintf_P ( buffer , sizeof ( buffer ) , PSTR ( " %s %s " ) , source , svalue ) ;
2018-08-28 17:13:14 +01:00
2021-06-05 10:47:09 +01:00
// AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "mkey [%s], source [%s], value [%s], quantity_code %d, log_buffer [%s]"), mkey, source, value, quantity_code, buffer);
2018-08-28 17:13:14 +01:00
2018-08-31 11:17:09 +01:00
DisplayLogBufferAdd ( buffer ) ;
2018-08-28 17:13:14 +01:00
}
2021-06-06 15:32:08 +01:00
void DisplayAnalyzeJson ( char * topic , const char * json )
2018-08-28 17:13:14 +01:00
{
// //tele/pow2/STATE {"Time":"2017-09-20T11:53:03", "Uptime":10, "Vcc":3.123, "POWER":"ON", "Wifi":{"AP":2, "SSId":"indebuurt2", "RSSI":68, "APMac":"00:22:6B:FE:8E:20"}}
// //tele/pow2/ENERGY {"Time":"2017-09-20T11:53:03", "Total":6.522, "Yesterday":0.150, "Today":0.073, "Period":0.5, "Power":12.1, "Factor":0.56, "Voltage":210.1, "Current":0.102}
// tele/pow1/SENSOR = {"Time":"2018-01-02T17:13:17","ENERGY":{"Total":13.091,"Yesterday":0.060,"Today":0.046,"Period":0.2,"Power":9.8,"Factor":0.49,"Voltage":206.8,"Current":0.096}}
// tele/dual/STATE {"Time":"2017-09-20T11:53:03","Uptime":25,"Vcc":3.178,"POWER1":"OFF","POWER2":"OFF","Wifi":{"AP":2,"SSId":"indebuurt2","RSSI":100,"APMac":"00:22:6B:FE:8E:20"}}
// tele/sc/SENSOR {"Time":"2017-09-20T11:53:09","Temperature":24.0,"Humidity":16.0,"Light":30,"Noise":20,"AirQuality":100,"TempUnit":"C"}
// tele/rf1/SENSOR {"Time":"2017-09-20T11:53:23","BH1750":{"Illuminance":57}}
// tele/wemos5/SENSOR {"Time":"2017-09-20T11:53:53","SHT1X":{"Temperature":20.1,"Humidity":58.9},"HTU21":{"Temperature":20.7,"Humidity":58.5},"BMP280":{"Temperature":21.6,"Pressure":1020.3},"TempUnit":"C"}
// tele/th1/SENSOR {"Time":"2017-09-20T11:54:48","DS18B20":{"Temperature":49.7},"TempUnit":"C"}
String jsonStr = json ; // Move from stack to heap to fix watchdogs (20180626)
2020-09-24 15:40:03 +01:00
JsonParser parser ( ( char * ) jsonStr . c_str ( ) ) ;
JsonParserObject root = parser . getRootObject ( ) ;
if ( root ) { // did JSON parsing went ok?
2018-08-28 17:13:14 +01:00
2020-09-24 15:40:03 +01:00
const char * unit = root . getStr ( PSTR ( D_JSON_TEMPERATURE_UNIT ) , nullptr ) ; // nullptr if not found
2019-10-18 17:06:17 +01:00
if ( unit ) {
snprintf_P ( disp_temp , sizeof ( disp_temp ) , PSTR ( " %s " ) , unit ) ; // C or F
}
2020-09-24 15:40:03 +01:00
unit = root . getStr ( PSTR ( D_JSON_PRESSURE_UNIT ) , nullptr ) ; // nullptr if not found
2019-10-18 17:06:17 +01:00
if ( unit ) {
snprintf_P ( disp_pres , sizeof ( disp_pres ) , PSTR ( " %s " ) , unit ) ; // hPa or mmHg
2018-08-28 17:13:14 +01:00
}
2020-09-24 15:40:03 +01:00
for ( auto key1 : root ) {
JsonParserToken value1 = key1 . getValue ( ) ;
if ( value1 . isObject ( ) ) {
JsonParserObject Object2 = value1 . getObject ( ) ;
for ( auto key2 : Object2 ) {
JsonParserToken value2 = key2 . getValue ( ) ;
if ( value2 . isObject ( ) ) {
JsonParserObject Object3 = value2 . getObject ( ) ;
for ( auto key3 : Object3 ) {
const char * value3 = key3 . getValue ( ) . getStr ( nullptr ) ;
if ( value3 ! = nullptr ) { // "DHT11":{"Temperature":null,"Humidity":null} - ignore null as it will raise exception 28
DisplayJsonValue ( topic , key1 . getStr ( ) , key3 . getStr ( ) , value3 ) ; // Sensor 56%
2019-01-08 13:22:45 +00:00
}
2018-08-28 17:13:14 +01:00
}
} else {
2020-09-24 15:40:03 +01:00
const char * value = value2 . getStr ( nullptr ) ;
2019-01-09 13:56:16 +00:00
if ( value ! = nullptr ) {
2020-09-24 15:40:03 +01:00
DisplayJsonValue ( topic , key1 . getStr ( ) , key2 . getStr ( ) , value ) ; // Sensor 56%
2019-01-08 13:22:45 +00:00
}
2018-08-28 17:13:14 +01:00
}
}
} else {
2020-09-24 15:40:03 +01:00
const char * value = value1 . getStr ( nullptr ) ;
2019-01-09 13:56:16 +00:00
if ( value ! = nullptr ) {
2020-09-24 15:40:03 +01:00
DisplayJsonValue ( topic , key1 . getStr ( ) , key1 . getStr ( ) , value ) ; // Topic 56%
2019-01-08 13:22:45 +00:00
}
2018-08-28 17:13:14 +01:00
}
}
}
}
2018-11-14 13:32:09 +00:00
void DisplayMqttSubscribe ( void )
2018-08-28 17:13:14 +01:00
{
/* Subscribe to tele messages only
* Supports the following FullTopic formats
* - % prefix % / % topic %
* - home / % prefix % / % topic %
* - home / level2 / % prefix % / % topic % etc .
*/
2021-06-11 17:14:12 +01:00
if ( Settings - > display_model & & ( Settings - > display_mode & 0x04 ) ) {
2018-08-28 17:13:14 +01:00
char stopic [ TOPSZ ] ;
char ntopic [ TOPSZ ] ;
ntopic [ 0 ] = ' \0 ' ;
2019-12-16 14:13:57 +00:00
strlcpy ( stopic , SettingsText ( SET_MQTT_FULLTOPIC ) , sizeof ( stopic ) ) ;
2018-08-28 17:13:14 +01:00
char * tp = strtok ( stopic , " / " ) ;
2019-03-26 17:26:50 +00:00
while ( tp ! = nullptr ) {
2019-03-30 15:29:27 +00:00
if ( ! strcmp_P ( tp , MQTT_TOKEN_PREFIX ) ) {
2018-08-28 17:13:14 +01:00
break ;
}
2018-11-22 14:41:30 +00:00
strncat_P ( ntopic , PSTR ( " +/ " ) , sizeof ( ntopic ) - strlen ( ntopic ) - 1 ) ; // Add single-level wildcards
2019-03-26 17:26:50 +00:00
tp = strtok ( nullptr , " / " ) ;
2018-08-28 17:13:14 +01:00
}
2019-12-16 14:13:57 +00:00
strncat ( ntopic , SettingsText ( SET_MQTTPREFIX3 ) , sizeof ( ntopic ) - strlen ( ntopic ) - 1 ) ; // Subscribe to tele messages
2018-11-22 14:41:30 +00:00
strncat_P ( ntopic , PSTR ( " /# " ) , sizeof ( ntopic ) - strlen ( ntopic ) - 1 ) ; // Add multi-level wildcard
2018-08-28 17:13:14 +01:00
MqttSubscribe ( ntopic ) ;
2019-07-01 11:54:26 +01:00
disp_subscribed = true ;
2018-08-28 17:13:14 +01:00
} else {
2019-07-01 11:54:26 +01:00
disp_subscribed = false ;
2018-08-28 17:13:14 +01:00
}
}
2019-01-28 13:08:33 +00:00
bool DisplayMqttData ( void )
2018-08-28 17:13:14 +01:00
{
if ( disp_subscribed ) {
char stopic [ TOPSZ ] ;
2019-12-16 14:13:57 +00:00
snprintf_P ( stopic , sizeof ( stopic ) , PSTR ( " %s/ " ) , SettingsText ( SET_MQTTPREFIX3 ) ) ; // tele/
2018-08-28 17:13:14 +01:00
char * tp = strstr ( XdrvMailbox . topic , stopic ) ;
2019-11-03 14:37:33 +00:00
if ( tp ) { // tele/tasmota/SENSOR
2021-06-11 17:14:12 +01:00
if ( Settings - > display_mode & 0x04 ) {
2019-11-03 14:37:33 +00:00
tp = tp + strlen ( stopic ) ; // tasmota/SENSOR
char * topic = strtok ( tp , " / " ) ; // tasmota
2018-08-28 17:13:14 +01:00
DisplayAnalyzeJson ( topic , XdrvMailbox . data ) ;
}
return true ;
}
}
return false ;
}
2018-11-14 13:32:09 +00:00
void DisplayLocalSensor ( void )
2018-08-28 17:13:14 +01:00
{
2021-06-11 17:14:12 +01:00
if ( ( Settings - > display_mode & 0x02 ) & & ( 0 = = TasmotaGlobal . tele_period ) ) {
2019-02-24 16:29:28 +00:00
char no_topic [ 1 ] = { 0 } ;
2021-08-15 16:08:31 +01:00
// DisplayAnalyzeJson(TasmotaGlobal.mqtt_topic, ResponseData()); // Add local topic
DisplayAnalyzeJson ( no_topic , ResponseData ( ) ) ; // Discard any topic
2018-08-28 17:13:14 +01:00
}
}
# endif // USE_DISPLAY_MODES1TO5
2021-02-14 14:00:57 +00:00
2018-08-28 17:13:14 +01:00
/*********************************************************************************************\
* Public
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2023-02-05 11:52:21 +00:00
void DisplayInitDriver ( void ) {
2018-08-28 17:13:14 +01:00
XdspCall ( FUNC_DISPLAY_INIT_DRIVER ) ;
2021-09-29 15:36:33 +01:00
// AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "Display model %d"), Settings->display_model);
if ( Settings - > display_model ) {
2023-02-05 15:54:25 +00:00
// ApplyDisplayDimmer(); // Not allowed here. Way too early in init sequence. Global power state has not been set at this point in time
2018-08-28 17:13:14 +01:00
2021-04-21 10:01:40 +01:00
# ifdef USE_MULTI_DISPLAY
2021-09-29 15:36:33 +01:00
Set_display ( 0 ) ;
2021-04-21 10:01:40 +01:00
# endif // USE_MULTI_DISPLAY
2021-09-29 15:36:33 +01:00
if ( renderer ) {
renderer - > setTextFont ( Settings - > display_font ) ;
renderer - > setTextSize ( Settings - > display_size ) ;
// force opaque mode
renderer - > setDrawMode ( 0 ) ;
2021-02-18 09:57:12 +00:00
2021-09-29 15:36:33 +01:00
for ( uint32_t cnt = 0 ; cnt < ( MAX_INDEXCOLORS - PREDEF_INDEXCOLORS ) ; cnt + + ) {
index_colors [ cnt ] = 0 ;
}
2021-02-18 09:57:12 +00:00
}
2019-09-06 09:11:50 +01:00
2021-02-18 09:57:12 +00:00
# ifdef USE_DT_VARS
2021-09-29 15:36:33 +01:00
free_dt_vars ( ) ;
2021-02-18 09:57:12 +00:00
# endif
2021-02-14 14:00:57 +00:00
# ifdef USE_UFILESYS
2021-09-29 15:36:33 +01:00
Display_Text_From_File ( DISP_BATCH_FILE ) ;
2021-02-14 14:00:57 +00:00
# endif
2019-09-06 09:11:50 +01:00
2021-03-17 15:26:04 +00:00
# ifdef USE_GRAPH
2021-09-29 15:36:33 +01:00
for ( uint8_t count = 0 ; count < NUM_GRAPHS ; count + + ) { graph [ count ] = 0 ; }
2021-03-17 15:26:04 +00:00
# endif
2021-02-15 16:22:06 +00:00
2023-02-25 15:44:04 +00:00
UpdateDevicesPresent ( 1 ) ;
2020-08-17 13:49:24 +01:00
if ( ! PinUsed ( GPIO_BACKLIGHT ) ) {
2021-06-11 17:14:12 +01:00
if ( TasmotaGlobal . light_type & & ( 4 = = Settings - > display_model ) ) {
2023-02-25 15:44:04 +00:00
UpdateDevicesPresent ( - 1 ) ; // Assume PWM channel is used for backlight
2020-08-17 13:49:24 +01:00
}
2020-08-09 10:10:09 +01:00
}
2020-10-30 11:29:48 +00:00
disp_device = TasmotaGlobal . devices_present ;
2018-08-28 17:13:14 +01:00
# ifndef USE_DISPLAY_MODES1TO5
2021-06-11 17:14:12 +01:00
Settings - > display_mode = 0 ;
2018-08-28 17:13:14 +01:00
# else
DisplayLogBufferInit ( ) ;
# endif // USE_DISPLAY_MODES1TO5
}
}
2023-02-05 11:52:21 +00:00
void DisplaySetPower ( void ) {
if ( ! disp_device ) { return ; } // Not initialized yet
2018-08-28 17:13:14 +01:00
disp_power = bitRead ( XdrvMailbox . index , disp_device - 1 ) ;
2019-08-19 17:17:44 +01:00
2021-01-23 15:26:23 +00:00
//AddLog(LOG_LEVEL_DEBUG, PSTR("DSP: Power %d"), disp_power);
2019-08-19 17:17:44 +01:00
2021-06-11 17:14:12 +01:00
if ( Settings - > display_model ) {
2019-08-19 17:17:44 +01:00
if ( ! renderer ) {
XdspCall ( FUNC_DISPLAY_POWER ) ;
} else {
renderer - > DisplayOnff ( disp_power ) ;
2021-11-04 18:29:06 +00:00
# ifdef USE_BERRY
// still call Berry virtual display in case it is not managed entirely by renderer
Xdsp18 ( FUNC_DISPLAY_POWER ) ;
# endif // USE_BERRY
2019-08-19 17:17:44 +01:00
}
2018-08-28 17:13:14 +01:00
}
}
/*********************************************************************************************\
* Commands
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-03-22 11:34:52 +00:00
void CmndDisplay ( void ) {
Response_P ( PSTR ( " { \" " D_PRFX_DISPLAY " \" :{ \" " D_CMND_DISP_MODEL " \" :%d, \" " D_CMND_DISP_TYPE " \" :%d, \" " D_CMND_DISP_WIDTH " \" :%d, \" " D_CMND_DISP_HEIGHT " \" :%d, \" "
2019-08-02 16:22:38 +01:00
D_CMND_DISP_MODE " \" :%d, \" " D_CMND_DISP_DIMMER " \" :%d, \" " D_CMND_DISP_SIZE " \" :%d, \" " D_CMND_DISP_FONT " \" :%d, \" "
2021-03-22 11:34:52 +00:00
D_CMND_DISP_ROTATE " \" :%d, \" " D_CMND_DISP_INVERT " \" :%d, \" " D_CMND_DISP_REFRESH " \" :%d, \" " D_CMND_DISP_COLS " \" :[%d,%d], \" " D_CMND_DISP_ROWS " \" :%d}} " ) ,
2021-06-11 17:14:12 +01:00
Settings - > display_model , Settings - > display_options . type , Settings - > display_width , Settings - > display_height ,
2021-09-14 21:40:26 +01:00
Settings - > display_mode , GetDisplayDimmer ( ) , Settings - > display_size , Settings - > display_font ,
2021-06-11 17:14:12 +01:00
Settings - > display_rotate , Settings - > display_options . invert , Settings - > display_refresh , Settings - > display_cols [ 0 ] , Settings - > display_cols [ 1 ] , Settings - > display_rows ) ;
2019-08-02 16:22:38 +01:00
}
2021-03-22 11:34:52 +00:00
void CmndDisplayModel ( void ) {
2019-08-02 16:22:38 +01:00
if ( ( XdrvMailbox . payload > = 0 ) & & ( XdrvMailbox . payload < DISPLAY_MAX_DRIVERS ) ) {
2021-06-11 17:14:12 +01:00
uint32_t last_display_model = Settings - > display_model ;
Settings - > display_model = XdrvMailbox . payload ;
2019-08-02 16:22:38 +01:00
if ( XdspCall ( FUNC_DISPLAY_MODEL ) ) {
2020-10-29 11:21:24 +00:00
TasmotaGlobal . restart_flag = 2 ; // Restart to re-init interface and add/Remove MQTT subscribe
2019-08-02 16:22:38 +01:00
} else {
2021-06-11 17:14:12 +01:00
Settings - > display_model = last_display_model ;
2018-08-28 17:13:14 +01:00
}
2019-08-02 16:22:38 +01:00
}
2021-06-11 17:14:12 +01:00
ResponseCmndNumber ( Settings - > display_model ) ;
2019-08-02 16:22:38 +01:00
}
2021-03-22 11:34:52 +00:00
void CmndDisplayType ( void ) {
if ( ( XdrvMailbox . payload > = 0 ) & & ( XdrvMailbox . payload < = 7 ) ) {
2021-06-11 17:14:12 +01:00
Settings - > display_options . type = XdrvMailbox . payload ;
2021-03-22 11:34:52 +00:00
TasmotaGlobal . restart_flag = 2 ;
}
2021-06-11 17:14:12 +01:00
ResponseCmndNumber ( Settings - > display_options . type ) ;
2021-03-22 11:34:52 +00:00
}
void CmndDisplayWidth ( void ) {
2019-08-02 16:22:38 +01:00
if ( XdrvMailbox . payload > 0 ) {
2021-06-11 17:14:12 +01:00
if ( XdrvMailbox . payload ! = Settings - > display_width ) {
Settings - > display_width = XdrvMailbox . payload ;
2020-10-29 11:21:24 +00:00
TasmotaGlobal . restart_flag = 2 ; // Restart to re-init width
2019-07-23 13:05:42 +01:00
}
2019-08-02 16:22:38 +01:00
}
2021-06-11 17:14:12 +01:00
ResponseCmndNumber ( Settings - > display_width ) ;
2019-08-02 16:22:38 +01:00
}
2021-03-22 11:34:52 +00:00
void CmndDisplayHeight ( void ) {
2019-08-02 16:22:38 +01:00
if ( XdrvMailbox . payload > 0 ) {
2021-06-11 17:14:12 +01:00
if ( XdrvMailbox . payload ! = Settings - > display_height ) {
Settings - > display_height = XdrvMailbox . payload ;
2020-10-29 11:21:24 +00:00
TasmotaGlobal . restart_flag = 2 ; // Restart to re-init height
2019-07-23 13:05:42 +01:00
}
2019-08-02 16:22:38 +01:00
}
2021-06-11 17:14:12 +01:00
ResponseCmndNumber ( Settings - > display_height ) ;
2019-08-02 16:22:38 +01:00
}
2021-03-22 11:34:52 +00:00
void CmndDisplayMode ( void ) {
2018-08-28 17:13:14 +01:00
# ifdef USE_DISPLAY_MODES1TO5
2021-03-19 13:24:26 +00:00
/* Matrix / 7-segment LCD / Oled TFT
2018-08-28 17:13:14 +01:00
* 1 = Text up and time Time
* 2 = Date Local sensors Local sensors
* 3 = Day Local sensors and time Local sensors and time
* 4 = Mqtt left and time Mqtt ( incl local ) sensors Mqtt ( incl local ) sensors
* 5 = Mqtt up and time Mqtt ( incl local ) sensors and time Mqtt ( incl local ) sensors and time
*/
2019-08-02 16:22:38 +01:00
if ( ( XdrvMailbox . payload > = 0 ) & & ( XdrvMailbox . payload < = 5 ) ) {
2021-06-11 17:14:12 +01:00
uint32_t last_display_mode = Settings - > display_mode ;
Settings - > display_mode = XdrvMailbox . payload ;
2019-08-02 16:22:38 +01:00
2021-06-11 17:14:12 +01:00
if ( disp_subscribed ! = ( Settings - > display_mode & 0x04 ) ) {
2020-10-29 11:21:24 +00:00
TasmotaGlobal . restart_flag = 2 ; // Restart to Add/Remove MQTT subscribe
2019-08-02 16:22:38 +01:00
} else {
2021-06-11 17:14:12 +01:00
if ( last_display_mode & & ! Settings - > display_mode ) { // Switch to mode 0
2019-08-02 16:22:38 +01:00
DisplayInit ( DISPLAY_INIT_MODE ) ;
2019-08-19 12:21:54 +01:00
if ( renderer ) renderer - > fillScreen ( bg_color ) ;
else DisplayClear ( ) ;
2019-08-02 16:22:38 +01:00
} else {
DisplayLogBufferInit ( ) ;
DisplayInit ( DISPLAY_INIT_MODE ) ;
2018-08-28 17:13:14 +01:00
}
}
2019-08-02 16:22:38 +01:00
}
# endif // USE_DISPLAY_MODES1TO5
2021-06-11 17:14:12 +01:00
ResponseCmndNumber ( Settings - > display_mode ) ;
2019-08-02 16:22:38 +01:00
}
2021-09-14 21:40:26 +01:00
// Apply the current display dimmer
void ApplyDisplayDimmer ( void ) {
2023-02-05 15:54:25 +00:00
disp_apply_display_dimmer_request = true ;
2023-02-05 11:52:21 +00:00
if ( ( disp_power < 0 ) | | ! disp_device ) { return ; } // Not initialized yet
2023-02-05 15:54:25 +00:00
disp_apply_display_dimmer_request = false ;
2023-02-05 11:52:21 +00:00
2021-09-14 21:40:26 +01:00
uint8_t dimmer8 = changeUIntScale ( GetDisplayDimmer ( ) , 0 , 100 , 0 , 255 ) ;
2022-01-27 20:30:05 +00:00
uint16_t dimmer10_gamma = ledGamma10 ( dimmer8 ) ;
2021-09-14 21:40:26 +01:00
if ( dimmer8 & & ! ( disp_power ) ) {
ExecuteCommandPower ( disp_device , POWER_ON , SRC_DISPLAY ) ;
}
else if ( ! dimmer8 & & disp_power ) {
ExecuteCommandPower ( disp_device , POWER_OFF , SRC_DISPLAY ) ;
}
if ( renderer ) {
2022-01-27 20:30:05 +00:00
renderer - > dim10 ( dimmer8 , dimmer10_gamma ) ; // provide 8 bits and gamma corrected dimmer in 8 bits
2021-11-04 18:29:06 +00:00
# ifdef USE_BERRY
// still call Berry virtual display in case it is not managed entirely by renderer
Xdsp18 ( FUNC_DISPLAY_DIM ) ;
# endif // USE_BERRY
2023-02-04 17:24:21 +00:00
2021-09-14 21:40:26 +01:00
} else {
XdspCall ( FUNC_DISPLAY_DIM ) ;
}
}
2021-03-19 13:24:26 +00:00
void CmndDisplayDimmer ( void ) {
2019-08-02 16:22:38 +01:00
if ( ( XdrvMailbox . payload > = 0 ) & & ( XdrvMailbox . payload < = 100 ) ) {
2021-09-14 21:40:26 +01:00
uint8_t dimmer = XdrvMailbox . payload ;
SetDisplayDimmer ( dimmer ) ;
ApplyDisplayDimmer ( ) ;
2019-08-02 16:22:38 +01:00
}
2021-09-14 21:40:26 +01:00
ResponseCmndNumber ( GetDisplayDimmer ( ) ) ;
2019-08-02 16:22:38 +01:00
}
2021-03-22 11:34:52 +00:00
void CmndDisplaySize ( void ) {
2021-12-08 15:32:02 +00:00
if ( ( XdrvMailbox . payload > 0 ) & & ( XdrvMailbox . payload < = TXT_MAX_SFAC ) ) {
2021-06-11 17:14:12 +01:00
Settings - > display_size = XdrvMailbox . payload ;
if ( renderer ) renderer - > setTextSize ( Settings - > display_size ) ;
//else DisplaySetSize(Settings->display_size);
2021-03-22 11:34:52 +00:00
}
2021-06-11 17:14:12 +01:00
ResponseCmndNumber ( Settings - > display_size ) ;
2021-03-22 11:34:52 +00:00
}
void CmndDisplayFont ( void ) {
if ( ( XdrvMailbox . payload > = 0 ) & & ( XdrvMailbox . payload < = 4 ) ) {
2021-06-11 17:14:12 +01:00
Settings - > display_font = XdrvMailbox . payload ;
if ( renderer ) renderer - > setTextFont ( Settings - > display_font ) ;
//else DisplaySetFont(Settings->display_font);
2021-03-22 11:34:52 +00:00
}
2021-06-11 17:14:12 +01:00
ResponseCmndNumber ( Settings - > display_font ) ;
2021-03-22 11:34:52 +00:00
}
void CmndDisplayRotate ( void ) {
if ( ( XdrvMailbox . payload > = 0 ) & & ( XdrvMailbox . payload < 4 ) ) {
2021-06-11 17:14:12 +01:00
if ( ( Settings - > display_rotate ) ! = XdrvMailbox . payload ) {
2021-03-22 11:34:52 +00:00
/*
// Needs font info regarding height and width
2021-06-11 17:14:12 +01:00
if ( ( Settings - > display_rotate & 1 ) ! = ( XdrvMailbox . payload & 1 ) ) {
uint8_t temp_rows = Settings - > display_rows ;
Settings - > display_rows = Settings - > display_cols [ 0 ] ;
Settings - > display_cols [ 0 ] = temp_rows ;
2021-03-22 11:34:52 +00:00
# ifdef USE_DISPLAY_MODES1TO5
DisplayReAllocScreenBuffer ( ) ;
# endif // USE_DISPLAY_MODES1TO5
}
*/
2021-06-11 17:14:12 +01:00
Settings - > display_rotate = XdrvMailbox . payload ;
2021-03-22 11:34:52 +00:00
DisplayInit ( DISPLAY_INIT_MODE ) ;
# ifdef USE_DISPLAY_MODES1TO5
DisplayLogBufferInit ( ) ;
# endif // USE_DISPLAY_MODES1TO5
}
}
2021-06-11 17:14:12 +01:00
ResponseCmndNumber ( Settings - > display_rotate ) ;
2021-03-22 11:34:52 +00:00
}
2021-01-04 15:34:44 +00:00
2021-03-22 11:34:52 +00:00
void CmndDisplayInvert ( void ) {
if ( ( XdrvMailbox . payload > = 0 ) & & ( XdrvMailbox . payload < = 1 ) ) {
2021-06-11 17:14:12 +01:00
Settings - > display_options . invert = XdrvMailbox . payload ;
if ( renderer ) renderer - > invertDisplay ( Settings - > display_options . invert ) ;
2021-03-22 11:34:52 +00:00
}
2021-06-11 17:14:12 +01:00
ResponseCmndNumber ( Settings - > display_options . invert ) ;
2021-03-22 11:34:52 +00:00
}
void CmndDisplayRefresh ( void ) {
if ( ( XdrvMailbox . payload > = 1 ) & & ( XdrvMailbox . payload < = 7 ) ) {
2021-06-11 17:14:12 +01:00
Settings - > display_refresh = XdrvMailbox . payload ;
2021-03-22 11:34:52 +00:00
}
2021-06-11 17:14:12 +01:00
ResponseCmndNumber ( Settings - > display_refresh ) ;
2021-03-22 11:34:52 +00:00
}
void CmndDisplayColumns ( void ) {
if ( ( XdrvMailbox . index > 0 ) & & ( XdrvMailbox . index < = 2 ) ) {
if ( ( XdrvMailbox . payload > 0 ) & & ( XdrvMailbox . payload < = DISPLAY_MAX_COLS ) ) {
2021-06-11 17:14:12 +01:00
Settings - > display_cols [ XdrvMailbox . index - 1 ] = XdrvMailbox . payload ;
2021-03-22 11:34:52 +00:00
# ifdef USE_DISPLAY_MODES1TO5
if ( 1 = = XdrvMailbox . index ) {
DisplayLogBufferInit ( ) ;
DisplayReAllocScreenBuffer ( ) ;
}
# endif // USE_DISPLAY_MODES1TO5
}
2021-06-11 17:14:12 +01:00
ResponseCmndIdxNumber ( Settings - > display_cols [ XdrvMailbox . index - 1 ] ) ;
2021-03-22 11:34:52 +00:00
}
}
void CmndDisplayRows ( void ) {
if ( ( XdrvMailbox . payload > 0 ) & & ( XdrvMailbox . payload < = DISPLAY_MAX_ROWS ) ) {
2021-06-11 17:14:12 +01:00
Settings - > display_rows = XdrvMailbox . payload ;
2021-03-22 11:34:52 +00:00
# ifdef USE_DISPLAY_MODES1TO5
DisplayLogBufferInit ( ) ;
DisplayReAllocScreenBuffer ( ) ;
# endif // USE_DISPLAY_MODES1TO5
}
2021-06-11 17:14:12 +01:00
ResponseCmndNumber ( Settings - > display_rows ) ;
2021-03-22 11:34:52 +00:00
}
void CmndDisplayAddress ( void ) {
if ( ( XdrvMailbox . index > 0 ) & & ( XdrvMailbox . index < = 8 ) ) {
if ( ( XdrvMailbox . payload > = 0 ) & & ( XdrvMailbox . payload < = 255 ) ) {
2021-06-11 17:14:12 +01:00
Settings - > display_address [ XdrvMailbox . index - 1 ] = XdrvMailbox . payload ;
2021-03-22 11:34:52 +00:00
}
2021-06-11 17:14:12 +01:00
ResponseCmndIdxNumber ( Settings - > display_address [ XdrvMailbox . index - 1 ] ) ;
2021-03-22 11:34:52 +00:00
}
}
void CmndDisplayBlinkrate ( void ) {
if ( ( XdrvMailbox . payload > = 0 ) & & ( XdrvMailbox . payload < = 3 ) ) {
if ( ! renderer ) {
2021-01-01 17:17:55 +00:00
XdspCall ( FUNC_DISPLAY_BLINKRATE ) ;
2021-03-22 11:34:52 +00:00
}
2021-01-01 17:17:55 +00:00
}
ResponseCmndNumber ( XdrvMailbox . payload ) ;
}
2021-02-16 12:12:49 +00:00
# ifdef USE_UFILESYS
void CmndDisplayBatch ( void ) {
if ( XdrvMailbox . data_len > 0 ) {
2021-06-11 17:14:12 +01:00
if ( ! Settings - > display_mode ) {
2021-02-16 12:12:49 +00:00
Display_Text_From_File ( XdrvMailbox . data ) ;
}
ResponseCmndChar ( XdrvMailbox . data ) ;
}
}
# endif
2021-03-22 11:34:52 +00:00
void CmndDisplayText ( void ) {
if ( disp_device & & XdrvMailbox . data_len > 0 ) {
# ifndef USE_DISPLAY_MODES1TO5
DisplayText ( ) ;
# else
2023-03-12 08:22:40 +00:00
if ( Settings - > display_model = = 15 | | Settings - > display_model = = 20 ) {
2021-03-22 11:34:52 +00:00
XdspCall ( FUNC_DISPLAY_SEVENSEG_TEXT ) ;
2021-06-11 17:14:12 +01:00
} else if ( ! Settings - > display_mode ) {
2021-03-22 11:34:52 +00:00
DisplayText ( ) ;
} else {
DisplayLogBufferAdd ( XdrvMailbox . data ) ;
}
# endif // USE_DISPLAY_MODES1TO5
ResponseCmndChar ( XdrvMailbox . data ) ;
}
}
/*********************************************************************************************\
* Currently 7 - segement specific - should have been handled by ( extended ) DisplayText command
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-02-16 12:12:49 +00:00
2021-03-22 11:34:52 +00:00
void CmndDisplayClear ( void ) {
2021-02-10 16:23:47 +00:00
if ( ! renderer )
XdspCall ( FUNC_DISPLAY_CLEAR ) ;
ResponseCmndChar ( XdrvMailbox . data ) ;
}
2021-03-22 11:34:52 +00:00
void CmndDisplayNumber ( void ) {
2021-02-10 16:23:47 +00:00
if ( ! renderer ) {
XdspCall ( FUNC_DISPLAY_NUMBER ) ;
}
ResponseCmndChar ( XdrvMailbox . data ) ;
}
2021-03-22 11:34:52 +00:00
void CmndDisplayFloat ( void ) {
2021-02-10 16:23:47 +00:00
if ( ! renderer ) {
XdspCall ( FUNC_DISPLAY_FLOAT ) ;
}
ResponseCmndChar ( XdrvMailbox . data ) ;
}
2021-03-22 11:34:52 +00:00
void CmndDisplayNumberNC ( void ) {
2021-02-10 16:23:47 +00:00
if ( ! renderer ) {
XdspCall ( FUNC_DISPLAY_NUMBERNC ) ;
}
ResponseCmndChar ( XdrvMailbox . data ) ;
}
2021-03-22 11:34:52 +00:00
void CmndDisplayFloatNC ( void ) {
2021-02-10 16:23:47 +00:00
if ( ! renderer ) {
XdspCall ( FUNC_DISPLAY_FLOATNC ) ;
}
ResponseCmndChar ( XdrvMailbox . data ) ;
}
2021-03-22 11:34:52 +00:00
void CmndDisplayRaw ( void ) {
2021-02-10 16:23:47 +00:00
if ( ! renderer ) {
XdspCall ( FUNC_DISPLAY_RAW ) ;
}
ResponseCmndChar ( XdrvMailbox . data ) ;
}
2021-03-22 11:34:52 +00:00
void CmndDisplayLevel ( void ) {
2021-02-10 16:23:47 +00:00
bool result = false ;
if ( ! renderer ) {
result = XdspCall ( FUNC_DISPLAY_LEVEL ) ;
}
if ( result ) ResponseCmndNumber ( XdrvMailbox . payload ) ;
}
2021-03-22 11:34:52 +00:00
void CmndDisplaySevensegText ( void ) {
2021-02-10 16:23:47 +00:00
if ( ! renderer ) {
XdspCall ( FUNC_DISPLAY_SEVENSEG_TEXT ) ;
}
ResponseCmndChar ( XdrvMailbox . data ) ;
}
2021-03-22 11:34:52 +00:00
void CmndDisplayTextNC ( void ) {
2021-02-14 11:22:08 +00:00
if ( ! renderer ) {
XdspCall ( FUNC_DISPLAY_SEVENSEG_TEXTNC ) ;
}
ResponseCmndChar ( XdrvMailbox . data ) ;
}
2021-03-22 11:34:52 +00:00
void CmndDisplaySevensegTextNC ( void ) {
2021-02-10 16:23:47 +00:00
if ( ! renderer ) {
XdspCall ( FUNC_DISPLAY_SEVENSEG_TEXTNC ) ;
}
ResponseCmndChar ( XdrvMailbox . data ) ;
}
2021-03-22 11:34:52 +00:00
void CmndDisplayScrollDelay ( void ) {
2021-02-10 16:23:47 +00:00
if ( ! renderer ) {
XdspCall ( FUNC_DISPLAY_SCROLLDELAY ) ;
}
ResponseCmndNumber ( XdrvMailbox . payload ) ;
}
2021-03-22 11:34:52 +00:00
void CmndDisplayClock ( void ) {
2021-02-10 16:23:47 +00:00
if ( ! renderer ) {
XdspCall ( FUNC_DISPLAY_CLOCK ) ;
}
ResponseCmndNumber ( XdrvMailbox . payload ) ;
}
2021-02-16 12:12:49 +00:00
2021-03-22 11:34:52 +00:00
void CmndDisplayScrollText ( void ) {
2021-02-19 09:58:16 +00:00
bool result = false ;
2021-02-16 12:12:49 +00:00
if ( ! renderer ) {
2021-02-19 09:58:16 +00:00
result = XdspCall ( FUNC_DISPLAY_SCROLLTEXT ) ;
2021-02-16 12:12:49 +00:00
}
2021-02-19 09:58:16 +00:00
if ( result ) ResponseCmndChar ( XdrvMailbox . data ) ;
2021-02-16 12:12:49 +00:00
}
2021-04-11 11:32:02 +01:00
void DisplayReInitDriver ( void ) {
XdspCall ( FUNC_DISPLAY_INIT_DRIVER ) ;
2021-04-21 10:01:40 +01:00
# ifdef USE_MULTI_DISPLAY
Set_display ( 0 ) ;
# endif // USE_MULTI_DISPLAY
2021-04-11 11:32:02 +01:00
ResponseCmndDone ( ) ;
}
2019-08-19 12:21:54 +01:00
/*********************************************************************************************\
2021-03-17 15:26:04 +00:00
* Optional drivers
2019-08-19 12:21:54 +01:00
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-03-17 15:26:04 +00:00
2021-01-04 15:34:44 +00:00
# ifdef USE_TOUCH_BUTTONS
// very limited path size, so, add .jpg
2021-01-08 10:49:07 +00:00
void draw_picture ( char * path , uint32_t xp , uint32_t yp , uint32_t xs , uint32_t ys , uint32_t ocol , bool inverted ) {
2021-01-04 15:34:44 +00:00
char ppath [ 16 ] ;
strcpy ( ppath , path ) ;
uint8_t plen = strlen ( path ) - 1 ;
if ( ppath [ plen ] = = ' 1 ' ) {
// index mode
if ( inverted ) {
ppath [ plen ] = ' 2 ' ;
}
inverted = false ;
}
2021-01-08 10:49:07 +00:00
if ( ocol = = 9 ) {
strcat ( ppath , " .rgb " ) ;
} else {
strcat ( ppath , " .jpg " ) ;
}
2022-12-09 08:32:14 +00:00
Draw_RGB_Bitmap ( ppath , xp , yp , 0 , inverted ) ;
2021-01-04 15:34:44 +00:00
}
2021-03-17 15:26:04 +00:00
# endif // USE_TOUCH_BUTTONS
2021-01-04 15:34:44 +00:00
2020-05-18 09:25:18 +01:00
# ifdef ESP32
# ifdef JPEG_PICTS
# include "img_converters.h"
# include "esp_jpg_decode.h"
bool jpg2rgb888 ( const uint8_t * src , size_t src_len , uint8_t * out , jpg_scale_t scale ) ;
2022-12-09 08:32:14 +00:00
bool jpg2rgb565 ( const uint8_t * src , size_t src_len , uint8_t * out , jpg_scale_t scale ) ;
2020-05-18 09:25:18 +01:00
char get_jpeg_size ( unsigned char * data , unsigned int data_size , unsigned short * width , unsigned short * height ) ;
2020-09-11 14:45:21 +01:00
# endif // JPEG_PICTS
# endif // ESP32
2020-05-18 09:25:18 +01:00
2022-12-09 08:32:14 +00:00
//#define SLOW_RGB16
2021-02-14 11:22:08 +00:00
# ifdef USE_UFILESYS
2021-01-05 15:39:16 +00:00
extern FS * ufsp ;
2020-05-18 09:25:18 +01:00
# define XBUFF_LEN 128
2022-12-09 08:32:14 +00:00
void Draw_RGB_Bitmap ( char * file , uint16_t xp , uint16_t yp , uint8_t scale , bool inverted ) {
2019-08-19 12:21:54 +01:00
if ( ! renderer ) return ;
File fp ;
2022-12-09 08:32:14 +00:00
char * ending = 0 ;
for ( uint32_t cnt = strlen ( file ) - 1 ; cnt > = 0 ; cnt - - ) {
if ( file [ cnt ] = = ' . ' ) {
ending = & file [ cnt + 1 ] ;
break ;
}
}
2020-05-18 09:25:18 +01:00
if ( ! ending ) return ;
char estr [ 8 ] ;
2022-12-09 08:32:14 +00:00
memset ( estr , 0 , sizeof ( estr ) ) ;
for ( uint32_t cnt = 0 ; cnt < strlen ( ending ) ; cnt + + ) {
estr [ cnt ] = tolower ( ending [ cnt ] ) ;
2020-05-18 09:25:18 +01:00
}
2022-12-09 08:32:14 +00:00
estr [ 3 ] = 0 ;
2019-08-19 12:21:54 +01:00
2020-05-18 09:25:18 +01:00
if ( ! strcmp ( estr , " rgb " ) ) {
// special rgb format
2022-12-09 08:32:14 +00:00
fp = ufsp - > open ( file , FS_FILE_READ ) ;
2020-05-18 09:25:18 +01:00
if ( ! fp ) return ;
uint16_t xsize ;
2022-12-09 08:32:14 +00:00
fp . read ( ( uint8_t * ) & xsize , 2 ) ;
2020-05-18 09:25:18 +01:00
uint16_t ysize ;
2022-12-09 08:32:14 +00:00
fp . read ( ( uint8_t * ) & ysize , 2 ) ;
# ifndef SLOW_RGB16
renderer - > setAddrWindow ( xp , yp , xp + xsize , yp + ysize ) ;
uint16_t * rgb = ( uint16_t * ) special_malloc ( xsize * 2 ) ;
if ( rgb ) {
//uint16_t rgb[xsize];
for ( int16_t j = 0 ; j < ysize ; j + + ) {
fp . read ( ( uint8_t * ) rgb , xsize * 2 ) ;
renderer - > pushColors ( rgb , xsize , true ) ;
OsWatchLoop ( ) ;
}
free ( rgb ) ;
2019-08-19 12:21:54 +01:00
}
2022-12-09 08:32:14 +00:00
renderer - > setAddrWindow ( 0 , 0 , 0 , 0 ) ;
2019-08-19 12:21:54 +01:00
# else
2022-12-09 08:32:14 +00:00
for ( int16_t j = 0 ; j < ysize ; j + + ) {
for ( int16_t i = 0 ; i < xsize ; i + + ) {
2020-05-18 09:25:18 +01:00
uint16_t rgb ;
2022-12-09 08:32:14 +00:00
uint8_t res = fp . read ( ( uint8_t * ) & rgb , 2 ) ;
2020-05-18 09:25:18 +01:00
if ( ! res ) break ;
2022-12-09 08:32:14 +00:00
renderer - > writePixel ( xp + i , yp , rgb ) ;
2020-05-18 09:25:18 +01:00
}
delay ( 0 ) ;
OsWatchLoop ( ) ;
yp + + ;
2019-08-19 12:21:54 +01:00
}
# endif
2020-05-18 09:25:18 +01:00
fp . close ( ) ;
} else if ( ! strcmp ( estr , " jpg " ) ) {
// jpeg files on ESP32 with more memory
# ifdef ESP32
# ifdef JPEG_PICTS
2022-12-09 08:32:14 +00:00
fp = ufsp - > open ( file , FS_FILE_READ ) ;
if ( ! fp ) {
// try url
Draw_JPG_from_URL ( file , xp , yp , scale ) ;
return ;
}
2021-01-04 15:34:44 +00:00
uint32_t size = fp . size ( ) ;
2022-12-09 08:32:14 +00:00
uint8_t * mem = ( uint8_t * ) special_malloc ( size + 4 ) ;
2021-01-04 15:34:44 +00:00
if ( mem ) {
2022-12-09 08:32:14 +00:00
uint8_t res = fp . read ( mem , size ) ;
2021-01-04 15:34:44 +00:00
if ( res ) {
uint16_t xsize ;
uint16_t ysize ;
2022-12-09 08:32:14 +00:00
if ( mem [ 0 ] = = 0xff & & mem [ 1 ] = = 0xd8 ) {
2021-01-04 15:34:44 +00:00
get_jpeg_size ( mem , size , & xsize , & ysize ) ;
//Serial.printf(" x,y,fs %d - %d - %d\n",xsize, ysize, size );
if ( xsize & & ysize ) {
2022-12-09 08:32:14 +00:00
uint8_t * out_buf = ( uint8_t * ) special_malloc ( ( xsize * ysize * 3 ) + 4 ) ;
2021-01-04 15:34:44 +00:00
if ( out_buf ) {
2022-12-09 08:32:14 +00:00
uint16_t * pixb = ( uint16_t * ) special_malloc ( ( xsize * 2 ) + 4 ) ;
2021-01-04 15:34:44 +00:00
if ( pixb ) {
2022-12-09 08:32:14 +00:00
uint8_t * ob = out_buf ;
2021-01-04 15:34:44 +00:00
if ( jpg2rgb888 ( mem , size , out_buf , ( jpg_scale_t ) JPG_SCALE_NONE ) ) {
2022-12-09 08:32:14 +00:00
renderer - > setAddrWindow ( xp , yp , xp + xsize , yp + ysize ) ;
for ( int32_t j = 0 ; j < ysize ; j + + ) {
if ( inverted = = false ) {
2021-01-04 15:34:44 +00:00
rgb888_to_565 ( ob , pixb , xsize ) ;
} else {
rgb888_to_565i ( ob , pixb , xsize ) ;
}
2022-12-09 08:32:14 +00:00
ob + = xsize * 3 ;
2021-01-04 15:34:44 +00:00
renderer - > pushColors ( pixb , xsize , true ) ;
OsWatchLoop ( ) ;
}
2022-12-09 08:32:14 +00:00
renderer - > setAddrWindow ( 0 , 0 , 0 , 0 ) ;
2020-05-18 09:25:18 +01:00
}
2021-01-04 15:34:44 +00:00
free ( out_buf ) ;
free ( pixb ) ;
} else {
2020-05-18 09:25:18 +01:00
free ( out_buf ) ;
}
}
}
}
free ( mem ) ;
}
fp . close ( ) ;
}
# endif // JPEG_PICTS
# endif // ESP32
}
2019-08-19 12:21:54 +01:00
}
2022-12-09 08:32:14 +00:00
# ifdef ESP32
# ifdef JPEG_PICTS
# define JPG_DEFSIZE 150000
void Draw_JPG_from_URL ( char * url , uint16_t xp , uint16_t yp , uint8_t scale ) {
uint8_t * mem = 0 ;
WiFiClient http_client ;
HTTPClient http ;
int32_t httpCode = 0 ;
String weburl = " http:// " + UrlEncode ( url ) ;
http . begin ( http_client , weburl ) ;
httpCode = http . GET ( ) ;
//AddLog(LOG_LEVEL_INFO, PSTR("HTTP RESULT %d %s"), httpCode , weburl.c_str());
uint32_t jpgsize = 0 ;
if ( httpCode = = HTTP_CODE_OK | | httpCode = = HTTP_CODE_MOVED_PERMANENTLY ) {
mem = ( uint8_t * ) special_malloc ( JPG_DEFSIZE ) ;
if ( ! mem ) return ;
uint8_t * jpgp = mem ;
WiFiClient * stream = http . getStreamPtr ( ) ;
int32_t len = http . getSize ( ) ;
if ( len < 0 ) len = 99999999 ;
while ( http . connected ( ) & & ( len > 0 ) ) {
size_t size = stream - > available ( ) ;
if ( size ) {
if ( size > JPG_DEFSIZE ) {
size = JPG_DEFSIZE ;
}
uint32_t read = stream - > readBytes ( jpgp , size ) ;
len - = read ;
jpgp + = read ;
jpgsize + = read ;
//AddLog(LOG_LEVEL_INFO,PSTR("HTTP read %d - %d"), read, jpgsize);
}
delayMicroseconds ( 1 ) ;
}
} else {
AddLog ( LOG_LEVEL_INFO , PSTR ( " HTTP ERROR %s " ) , http . getString ( ) . c_str ( ) ) ;
}
http . end ( ) ;
http_client . stop ( ) ;
if ( jpgsize ) {
Draw_jpeg ( mem , jpgsize , xp , yp , scale ) ;
}
if ( mem ) free ( mem ) ;
}
void Draw_jpeg ( uint8_t * mem , uint16_t jpgsize , uint16_t xp , uint16_t yp , uint8_t scale ) {
if ( mem [ 0 ] = = 0xff & & mem [ 1 ] = = 0xd8 ) {
uint16_t xsize ;
uint16_t ysize ;
get_jpeg_size ( mem , jpgsize , & xsize , & ysize ) ;
//AddLog(LOG_LEVEL_INFO, PSTR("Pict size %d - %d - %d"), xsize, ysize, jpgsize);
scale & = 3 ;
uint8_t fac = 1 < < scale ;
xsize / = fac ;
ysize / = fac ;
renderer - > setAddrWindow ( xp , yp , xp + xsize , yp + ysize ) ;
uint8_t * rgbmem = ( uint8_t * ) special_malloc ( xsize * ysize * 2 ) ;
if ( rgbmem ) {
//jpg2rgb565(mem, jpgsize, rgbmem, JPG_SCALE_NONE);
jpg2rgb565 ( mem , jpgsize , rgbmem , ( jpg_scale_t ) scale ) ;
renderer - > pushColors ( ( uint16_t * ) rgbmem , xsize * ysize , true ) ;
free ( rgbmem ) ;
}
renderer - > setAddrWindow ( 0 , 0 , 0 , 0 ) ;
}
}
# endif // JPEG_PICTS
# endif // ESP32
2021-02-14 11:22:08 +00:00
# endif // USE_UFILESYS
2019-08-19 12:21:54 +01:00
2021-03-17 15:26:04 +00:00
/*********************************************************************************************\
* AWatch
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2019-08-19 12:21:54 +01:00
# ifdef USE_AWATCH
# define MINUTE_REDUCT 4
# ifndef pi
# define pi 3.14159265359
# endif
// draw analog watch, just for fun
void DrawAClock ( uint16_t rad ) {
if ( ! renderer ) return ;
float frad = rad ;
uint16_t hred = frad / 3.0 ;
renderer - > fillCircle ( disp_xpos , disp_ypos , rad , bg_color ) ;
renderer - > drawCircle ( disp_xpos , disp_ypos , rad , fg_color ) ;
renderer - > fillCircle ( disp_xpos , disp_ypos , 4 , fg_color ) ;
for ( uint8_t count = 0 ; count < 60 ; count + = 5 ) {
float p1 = ( ( float ) count * ( pi / 30 ) - ( pi / 2 ) ) ;
uint8_t len ;
if ( ( count % 15 ) = = 0 ) {
len = 4 ;
} else {
len = 2 ;
}
renderer - > writeLine ( disp_xpos + ( ( float ) ( rad - len ) * cosf ( p1 ) ) , disp_ypos + ( ( float ) ( rad - len ) * sinf ( p1 ) ) , disp_xpos + ( frad * cosf ( p1 ) ) , disp_ypos + ( frad * sinf ( p1 ) ) , fg_color ) ;
}
// hour
float hour = ( ( float ) RtcTime . hour * 60.0 + ( float ) RtcTime . minute ) / 60.0 ;
float temp = ( hour * ( pi / 6.0 ) - ( pi / 2.0 ) ) ;
renderer - > writeLine ( disp_xpos , disp_ypos , disp_xpos + ( frad - hred ) * cosf ( temp ) , disp_ypos + ( frad - hred ) * sinf ( temp ) , fg_color ) ;
// minute
temp = ( ( float ) RtcTime . minute * ( pi / 30.0 ) - ( pi / 2.0 ) ) ;
renderer - > writeLine ( disp_xpos , disp_ypos , disp_xpos + ( frad - MINUTE_REDUCT ) * cosf ( temp ) , disp_ypos + ( frad - MINUTE_REDUCT ) * sinf ( temp ) , fg_color ) ;
}
2020-09-11 14:45:21 +01:00
# endif // USE_AWATCH
2019-08-19 12:21:54 +01:00
2021-03-17 15:26:04 +00:00
/*********************************************************************************************\
* Graphics
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2019-08-19 12:21:54 +01:00
2021-03-22 14:39:08 +00:00
# ifdef USE_GRAPH
2019-08-19 12:21:54 +01:00
# define TICKLEN 4
void ClrGraph ( uint16_t num ) {
struct GRAPH * gp = graph [ num ] ;
uint16_t xticks = gp - > xticks ;
uint16_t yticks = gp - > yticks ;
uint16_t count ;
// clr inside, but only 1.graph if overlapped
if ( gp - > flags . overlay ) return ;
2021-09-23 08:51:51 +01:00
renderer - > fillRect ( gp - > xp + 1 , gp - > yp + 1 , gp - > xs - 2 , gp - > ys - 2 , gp - > bg_color ) ;
2019-08-19 12:21:54 +01:00
if ( xticks ) {
float cxp = gp - > xp , xd = ( float ) gp - > xs / ( float ) xticks ;
for ( count = 0 ; count < xticks ; count + + ) {
2021-09-23 08:51:51 +01:00
renderer - > writeFastVLine ( cxp , gp - > yp + gp - > ys - TICKLEN , TICKLEN , gp - > fg_color ) ;
2019-08-19 12:21:54 +01:00
cxp + = xd ;
}
}
if ( yticks ) {
if ( gp - > ymin < 0 & & gp - > ymax > 0 ) {
// draw zero seperator
float cxp = 0 ;
float czp = gp - > yp + ( gp - > ymax / gp - > range ) ;
while ( cxp < gp - > xs ) {
2021-09-23 08:51:51 +01:00
renderer - > writeFastHLine ( gp - > xp + cxp , czp , 2 , gp - > fg_color ) ;
2019-08-19 12:21:54 +01:00
cxp + = 6.0 ;
}
// align ticks to zero line
float cyp = 0 , yd = gp - > ys / yticks ;
for ( count = 0 ; count < yticks ; count + + ) {
if ( ( czp - cyp ) > gp - > yp ) {
2021-09-23 08:51:51 +01:00
renderer - > writeFastHLine ( gp - > xp , czp - cyp , TICKLEN , gp - > fg_color ) ;
renderer - > writeFastHLine ( gp - > xp + gp - > xs - TICKLEN , czp - cyp , TICKLEN , gp - > fg_color ) ;
2019-08-19 12:21:54 +01:00
}
if ( ( czp + cyp ) < ( gp - > yp + gp - > ys ) ) {
renderer - > writeFastHLine ( gp - > xp , czp + cyp , TICKLEN , fg_color ) ;
2021-09-23 08:51:51 +01:00
renderer - > writeFastHLine ( gp - > xp + gp - > xs - TICKLEN , czp + cyp , TICKLEN , gp - > fg_color ) ;
2019-08-19 12:21:54 +01:00
}
cyp + = yd ;
}
} else {
float cyp = gp - > yp , yd = gp - > ys / yticks ;
for ( count = 0 ; count < yticks ; count + + ) {
2021-09-23 08:51:51 +01:00
renderer - > writeFastHLine ( gp - > xp , cyp , TICKLEN , gp - > fg_color ) ;
renderer - > writeFastHLine ( gp - > xp + gp - > xs - TICKLEN , cyp , TICKLEN , gp - > fg_color ) ;
2019-08-19 12:21:54 +01:00
cyp + = yd ;
}
}
}
}
// define a graph
void DefineGraph ( uint16_t num , uint16_t xp , uint16_t yp , int16_t xs , uint16_t ys , int16_t dec , float ymin , float ymax , uint8_t icol ) {
if ( ! renderer ) return ;
uint8_t rflg = 0 ;
if ( xs < 0 ) {
rflg = 1 ;
xs = abs ( xs ) ;
}
struct GRAPH * gp ;
uint16_t count ;
uint16_t index = num % NUM_GRAPHS ;
if ( ! graph [ index ] ) {
gp = ( struct GRAPH * ) calloc ( sizeof ( struct GRAPH ) , 1 ) ;
if ( ! gp ) return ;
graph [ index ] = gp ;
} else {
gp = graph [ index ] ;
if ( rflg ) {
RedrawGraph ( index , 1 ) ;
return ;
}
}
2021-09-23 08:51:51 +01:00
gp - > bg_color = bg_color ;
gp - > fg_color = fg_color ;
2019-08-19 12:21:54 +01:00
// 6 bits per axis
gp - > xticks = ( num > > 4 ) & 0x3f ;
gp - > yticks = ( num > > 10 ) & 0x3f ;
gp - > xp = xp ;
gp - > yp = yp ;
gp - > xs = xs ;
gp - > ys = ys ;
if ( ! dec ) dec = 1 ;
gp - > decimation = dec ;
if ( dec > 0 ) {
// is minutes per sweep prepare timing parameters in ms
gp - > x_time = ( ( float ) dec * 60000.0 ) / ( float ) xs ;
gp - > last_ms = millis ( ) + gp - > x_time ;
}
gp - > ymin = ymin ;
gp - > ymax = ymax ;
gp - > range = ( ymax - ymin ) / ys ;
gp - > xcnt = 0 ;
gp - > dcnt = 0 ;
gp - > summ = 0 ;
if ( gp - > values ) free ( gp - > values ) ;
gp - > values = ( uint8_t * ) calloc ( 1 , xs + 2 ) ;
if ( ! gp - > values ) {
free ( gp ) ;
graph [ index ] = 0 ;
return ;
}
// start from zero
gp - > values [ 0 ] = 0 ;
gp - > last_ms_redrawn = millis ( ) ;
if ( ! icol ) icol = 1 ;
gp - > color_index = icol ;
gp - > flags . overlay = 0 ;
gp - > flags . draw = 1 ;
// check if previous graph has same coordinates
if ( index > 0 ) {
for ( uint8_t count = 0 ; count < index ; count + + ) {
if ( graph [ count ] ) {
// a previous graph is defined, compare
// assume the same if corner is identical
struct GRAPH * gp1 = graph [ count ] ;
if ( ( gp - > xp = = gp1 - > xp ) & & ( gp - > yp = = gp1 - > yp ) ) {
gp - > flags . overlay = 1 ;
break ;
}
}
}
}
// draw rectangle
2021-09-23 08:51:51 +01:00
renderer - > drawRect ( xp , yp , xs , ys , gp - > fg_color ) ;
2019-08-19 12:21:54 +01:00
// clr inside
ClrGraph ( index ) ;
}
// check if to advance GRAPH
void DisplayCheckGraph ( ) {
int16_t count ;
struct GRAPH * gp ;
for ( count = 0 ; count < NUM_GRAPHS ; count + + ) {
gp = graph [ count ] ;
if ( gp ) {
if ( gp - > decimation > 0 ) {
// if time over add value
while ( millis ( ) > gp - > last_ms ) {
gp - > last_ms + = gp - > x_time ;
uint8_t val ;
if ( gp - > dcnt ) {
val = gp - > summ / gp - > dcnt ;
gp - > dcnt = 0 ;
gp - > summ = 0 ;
gp - > last_val = val ;
} else {
val = gp - > last_val ;
}
AddGraph ( count , val ) ;
}
}
}
}
}
2021-01-20 14:06:34 +00:00
# if (defined(USE_SCRIPT_FATFS) && defined(USE_SCRIPT)) || defined(USE_UFILESYS)
2020-05-30 14:29:47 +01:00
# ifdef ESP32
2019-08-19 12:21:54 +01:00
# include <SD.h>
2020-05-30 14:29:47 +01:00
# endif
2019-08-19 12:21:54 +01:00
void Save_graph ( uint8_t num , char * path ) {
if ( ! renderer ) return ;
uint16_t index = num % NUM_GRAPHS ;
struct GRAPH * gp = graph [ index ] ;
if ( ! gp ) return ;
File fp ;
2021-01-05 15:39:16 +00:00
ufsp - > remove ( path ) ;
fp = ufsp - > open ( path , FS_FILE_WRITE ) ;
2019-08-19 12:21:54 +01:00
if ( ! fp ) return ;
char str [ 32 ] ;
sprintf_P ( str , PSTR ( " %d \t %d \t %d \t " ) , gp - > xcnt , gp - > xs , gp - > ys ) ;
fp . print ( str ) ;
dtostrfd ( gp - > ymin , 2 , str ) ;
fp . print ( str ) ;
fp . print ( " \t " ) ;
dtostrfd ( gp - > ymax , 2 , str ) ;
fp . print ( str ) ;
fp . print ( " \t " ) ;
for ( uint32_t count = 0 ; count < gp - > xs ; count + + ) {
dtostrfd ( gp - > values [ count ] , 0 , str ) ;
fp . print ( str ) ;
fp . print ( " \t " ) ;
}
fp . print ( " \n " ) ;
fp . close ( ) ;
}
2021-03-17 15:26:04 +00:00
2019-08-19 12:21:54 +01:00
void Restore_graph ( uint8_t num , char * path ) {
if ( ! renderer ) return ;
uint16_t index = num % NUM_GRAPHS ;
struct GRAPH * gp = graph [ index ] ;
if ( ! gp ) return ;
File fp ;
2021-01-05 15:39:16 +00:00
fp = ufsp - > open ( path , FS_FILE_READ ) ;
2019-08-19 12:21:54 +01:00
if ( ! fp ) return ;
char vbuff [ 32 ] ;
char * cp = vbuff ;
2019-09-06 09:11:50 +01:00
uint8_t buf [ 2 ] ;
2019-08-19 12:21:54 +01:00
uint8_t findex = 0 ;
for ( uint32_t count = 0 ; count < = gp - > xs + 4 ; count + + ) {
cp = vbuff ;
findex = 0 ;
while ( fp . available ( ) ) {
fp . read ( buf , 1 ) ;
if ( buf [ 0 ] = = ' \t ' | | buf [ 0 ] = = ' , ' | | buf [ 0 ] = = ' \n ' | | buf [ 0 ] = = ' \r ' ) {
break ;
} else {
* cp + + = buf [ 0 ] ;
findex + + ;
if ( findex > = sizeof ( vbuff ) - 1 ) break ;
}
}
* cp = 0 ;
if ( count < = 4 ) {
if ( count = = 0 ) gp - > xcnt = atoi ( vbuff ) ;
} else {
2021-11-16 07:12:23 +00:00
uint8_t yval = atoi ( vbuff ) ;
if ( yval > = gp - > ys ) {
yval = gp - > ys - 1 ;
}
gp - > values [ count - 5 ] = yval ;
2019-08-19 12:21:54 +01:00
}
}
fp . close ( ) ;
RedrawGraph ( num , 1 ) ;
}
2020-09-11 14:45:21 +01:00
# endif // USE_SCRIPT_FATFS
2019-08-19 12:21:54 +01:00
void RedrawGraph ( uint8_t num , uint8_t flags ) {
uint16_t index = num % NUM_GRAPHS ;
struct GRAPH * gp = graph [ index ] ;
if ( ! gp ) return ;
if ( ! flags ) {
gp - > flags . draw = 0 ;
return ;
}
if ( ! renderer ) return ;
gp - > flags . draw = 1 ;
2021-09-23 08:51:51 +01:00
uint16_t linecol = gp - > fg_color ;
2019-08-19 12:21:54 +01:00
if ( color_type = = COLOR_COLOR ) {
2021-02-14 14:00:57 +00:00
linecol = GetColorFromIndex ( gp - > color_index ) ;
2019-08-19 12:21:54 +01:00
}
if ( ! gp - > flags . overlay ) {
// draw rectangle
2021-09-23 08:51:51 +01:00
renderer - > drawRect ( gp - > xp , gp - > yp , gp - > xs , gp - > ys , gp - > fg_color ) ;
2019-08-19 12:21:54 +01:00
// clr inside
ClrGraph ( index ) ;
}
for ( uint16_t count = 0 ; count < gp - > xs - 1 ; count + + ) {
renderer - > writeLine ( gp - > xp + count , gp - > yp + gp - > ys - gp - > values [ count ] - 1 , gp - > xp + count + 1 , gp - > yp + gp - > ys - gp - > values [ count + 1 ] - 1 , linecol ) ;
}
}
// add next value to graph
void AddGraph ( uint8_t num , uint8_t val ) {
struct GRAPH * gp = graph [ num ] ;
if ( ! renderer ) return ;
2021-09-23 08:51:51 +01:00
uint16_t linecol = gp - > fg_color ;
2019-08-19 12:21:54 +01:00
if ( color_type = = COLOR_COLOR ) {
2021-02-14 14:00:57 +00:00
linecol = GetColorFromIndex ( gp - > color_index ) ;
2019-08-19 12:21:54 +01:00
}
gp - > xcnt + + ;
if ( gp - > xcnt > gp - > xs ) {
gp - > xcnt = gp - > xs ;
int16_t count ;
// shift values
for ( count = 0 ; count < gp - > xs - 1 ; count + + ) {
gp - > values [ count ] = gp - > values [ count + 1 ] ;
}
gp - > values [ gp - > xcnt - 1 ] = val ;
if ( ! gp - > flags . draw ) return ;
// only redraw every second or longer
if ( millis ( ) - gp - > last_ms_redrawn > 1000 ) {
gp - > last_ms_redrawn = millis ( ) ;
// clr area and redraw graph
if ( ! gp - > flags . overlay ) {
// draw rectangle
2021-09-23 08:51:51 +01:00
renderer - > drawRect ( gp - > xp , gp - > yp , gp - > xs , gp - > ys , gp - > fg_color ) ;
2019-08-19 12:21:54 +01:00
// clr inner and draw ticks
ClrGraph ( num ) ;
}
for ( count = 0 ; count < gp - > xs - 1 ; count + + ) {
renderer - > writeLine ( gp - > xp + count , gp - > yp + gp - > ys - gp - > values [ count ] - 1 , gp - > xp + count + 1 , gp - > yp + gp - > ys - gp - > values [ count + 1 ] - 1 , linecol ) ;
}
}
} else {
// add value and draw a single line
gp - > values [ gp - > xcnt ] = val ;
if ( ! gp - > flags . draw ) return ;
renderer - > writeLine ( gp - > xp + gp - > xcnt - 1 , gp - > yp + gp - > ys - gp - > values [ gp - > xcnt - 1 ] - 1 , gp - > xp + gp - > xcnt , gp - > yp + gp - > ys - gp - > values [ gp - > xcnt ] - 1 , linecol ) ;
}
}
// add next value
void AddValue ( uint8_t num , float fval ) {
// not yet defined ???
num = num % NUM_GRAPHS ;
struct GRAPH * gp = graph [ num ] ;
if ( ! gp ) return ;
if ( fval > gp - > ymax ) fval = gp - > ymax ;
if ( fval < gp - > ymin ) fval = gp - > ymin ;
int16_t val ;
val = ( fval - gp - > ymin ) / gp - > range ;
if ( val > gp - > ys - 1 ) val = gp - > ys - 1 ;
if ( val < 0 ) val = 0 ;
// summ values
gp - > summ + = val ;
gp - > dcnt + + ;
// decimation option
if ( gp - > decimation < 0 ) {
if ( gp - > dcnt > = - gp - > decimation ) {
// calc average
2021-11-16 07:12:23 +00:00
val = gp - > summ / gp - > dcnt ;
gp - > dcnt = 0 ;
2019-08-19 12:21:54 +01:00
gp - > summ = 0 ;
// add to graph
AddGraph ( num , val ) ;
}
}
}
2020-09-03 11:26:03 +01:00
# endif // USE_GRAPH
2018-08-28 17:13:14 +01:00
/*********************************************************************************************\
* Interface
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2022-11-11 09:44:56 +00:00
bool Xdrv13 ( uint32_t function )
2018-08-28 17:13:14 +01:00
{
2019-01-28 13:08:33 +00:00
bool result = false ;
2018-08-28 17:13:14 +01:00
2021-03-17 15:26:04 +00:00
if ( XdspPresent ( ) ) {
2018-08-28 17:13:14 +01:00
switch ( function ) {
case FUNC_PRE_INIT :
DisplayInitDriver ( ) ;
break ;
2023-02-05 15:54:25 +00:00
case FUNC_INIT :
if ( disp_apply_display_dimmer_request ) {
ApplyDisplayDimmer ( ) ; // Allowed here.
}
break ;
2018-08-28 17:13:14 +01:00
case FUNC_EVERY_50_MSECOND :
2021-06-11 17:14:12 +01:00
if ( Settings - > display_model ) { XdspCall ( FUNC_DISPLAY_EVERY_50_MSECOND ) ; }
2018-08-28 17:13:14 +01:00
break ;
case FUNC_SET_POWER :
DisplaySetPower ( ) ;
break ;
case FUNC_EVERY_SECOND :
2019-08-19 12:21:54 +01:00
# ifdef USE_GRAPH
DisplayCheckGraph ( ) ;
# endif
2021-02-15 16:22:06 +00:00
# ifdef USE_DT_VARS
get_dt_mqtt ( ) ;
draw_dt_vars ( ) ;
# endif // USE_DT_VARS
2019-08-19 12:21:54 +01:00
# ifdef USE_DISPLAY_MODES1TO5
2021-06-11 17:14:12 +01:00
if ( Settings - > display_model & & Settings - > display_mode ) { XdspCall ( FUNC_DISPLAY_EVERY_SECOND ) ; }
2019-08-19 12:21:54 +01:00
# endif
2018-08-28 17:13:14 +01:00
break ;
2021-04-05 12:33:00 +01:00
case FUNC_AFTER_TELEPERIOD :
# ifdef USE_DT_VARS
DisplayDTVarsTeleperiod ( ) ;
# endif // USE_DT_VARS
break ;
2019-08-19 12:21:54 +01:00
# ifdef USE_DISPLAY_MODES1TO5
2018-08-28 17:13:14 +01:00
case FUNC_MQTT_SUBSCRIBE :
DisplayMqttSubscribe ( ) ;
break ;
case FUNC_MQTT_DATA :
result = DisplayMqttData ( ) ;
break ;
case FUNC_SHOW_SENSOR :
DisplayLocalSensor ( ) ;
break ;
# endif // USE_DISPLAY_MODES1TO5
2019-08-02 16:22:38 +01:00
case FUNC_COMMAND :
2019-08-11 17:12:18 +01:00
result = DecodeCommand ( kDisplayCommands , DisplayCommand ) ;
2019-08-02 16:22:38 +01:00
break ;
2023-12-27 21:03:56 +00:00
case FUNC_ACTIVE :
result = true ;
break ;
2018-08-28 17:13:14 +01:00
}
}
return result ;
}
# endif // USE_DISPLAY