update displaytext dv

This commit is contained in:
gemu2015 2021-02-18 10:57:12 +01:00
parent 5a96af95b2
commit 9c05aca525
2 changed files with 140 additions and 90 deletions

View File

@ -540,14 +540,10 @@ void Renderer::drawPixel(int16_t x, int16_t y, uint16_t color) {
}
extern uint16_t index_colors[MAX_INDEXCOLORS];
// this is called for every driver
void Renderer::setDrawMode(uint8_t mode) {
drawmode=mode;
for (uint32_t count = 0; count < MAX_INDEXCOLORS; count++) {
index_colors[count] = GetColorFromIndex(count);
}
}
void Renderer::invertDisplay(boolean i) {

View File

@ -151,7 +151,8 @@ uint8_t dsp_font;
uint8_t dsp_flag;
uint8_t dsp_on;
uint16_t index_colors[MAX_INDEXCOLORS];
#define PREDEF_INDEXCOLORS 19
uint16_t index_colors[MAX_INDEXCOLORS - PREDEF_INDEXCOLORS];
#ifdef USE_DISPLAY_MODES1TO5
@ -322,7 +323,12 @@ uint32_t decode_te(char *line) {
uint16_t GetColorFromIndex(uint32_t index) {
if (index >= MAX_INDEXCOLORS) index = 0;
return index_colors[index];
if (index < PREDEF_INDEXCOLORS) {
return renderer->GetColorFromIndex(index);
} else {
return index_colors[index - PREDEF_INDEXCOLORS];
}
}
void DisplayText(void)
@ -610,14 +616,15 @@ void DisplayText(void)
cp++;
var = fatoiv(cp, &ftemp);
cp += var;
if (temp >= MAX_INDEXCOLORS) temp = 0;
index_colors[temp] = ftemp;
if (temp >= MAX_INDEXCOLORS) temp = PREDEF_INDEXCOLORS;
if (temp < PREDEF_INDEXCOLORS) temp = PREDEF_INDEXCOLORS;
index_colors[temp - PREDEF_INDEXCOLORS] = ftemp;
break;
}
#ifdef USE_DT_VARS
if (*cp == 'v') {
cp++;
{ int16_t num, gxp, gyp, textbcol, textfcol, font, textsize, txlen, dp;
{ int16_t num, gxp, gyp, textbcol, textfcol, font, textsize, txlen, dp, time;
var=atoiv(cp,&num);
cp+=var;
cp++;
@ -645,12 +652,15 @@ void DisplayText(void)
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);
define_dt_var(num, gxp, gyp, textbcol, textfcol, font, textsize, txlen, dp, bbuff, unit);
define_dt_var(num, gxp, gyp, textbcol, textfcol, font, textsize, txlen, time, dp, bbuff, unit);
}
}
#endif // USE_DT_VARS
@ -995,6 +1005,8 @@ typedef struct {
int8_t txtlen;
int8_t dp;
int8_t font;
int8_t time;
int8_t timer;
char unit[6];
char *jstrbuf;
char rstr[32];
@ -1002,7 +1014,7 @@ typedef struct {
DT_VARS *dt_vars[MAX_DT_VARS];
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 dp, char *jstr, char *unit) {
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) {
if (num >= MAX_DT_VARS) return;
if (dt_vars[num]) {
@ -1022,71 +1034,107 @@ void define_dt_var(uint32_t num, uint32_t xp, uint32_t yp, uint32_t txtbcol, u
dtp->txtfcol = txtfcol;
dtp->font = font;
dtp->txtsiz = txtsiz;
dtp->time = time;
if (txtlen > MAX_DVTSIZE) {txtlen = MAX_DVTSIZE;}
dtp->txtlen = txtlen;
dtp->dp = dp;
dtp->jstrbuf = (char*)malloc(strlen(jstr + 1));
uint8_t jlen = strlen(jstr);
dtp->jstrbuf = (char*)calloc(jlen + 2,1);
if (!dtp->jstrbuf) {
free (dtp);
return;
}
strcpy(dtp->jstrbuf, jstr);
dtp->rstr[0] = 0;
strcpy(dtp->unit, unit);
strcpy(dtp->jstrbuf, jstr);
if (!time) time = 1;
dtp->timer = time;
}
void draw_dt_vars(void) {
if (!renderer) return;
for (uint32_t cnt = 0; cnt < MAX_DT_VARS; cnt++) {
if (dt_vars[cnt]) {
if (dt_vars[cnt]->jstrbuf) {
DT_VARS *dtp = dt_vars[cnt];
if (dtp) {
if (dtp->jstrbuf) {
// draw
dtp->timer--;
if (!dtp->timer) {
dtp->timer = dtp->time;
char vstr[MAX_DVTSIZE + 7];
memset(vstr, ' ', sizeof(vstr));
strcpy(vstr, dt_vars[cnt]->rstr);
strcpy(vstr, dtp->rstr);
strcat(vstr, " ");
strcat(vstr, dt_vars[cnt]->unit);
strcat(vstr, dtp->unit);
uint16_t slen = strlen(vstr);
vstr[slen] = ' ';
if (!dt_vars[cnt]->txtlen) {
if (!dtp->txtlen) {
vstr[slen] = 0;
} else {
vstr[abs(int(dt_vars[cnt]->txtlen))] = 0;
vstr[abs(int(dtp->txtlen))] = 0;
}
if (dt_vars[cnt]->txtlen < 0) {
if (dtp->txtlen < 0) {
// right align
alignright(vstr);
}
if (dt_vars[cnt]->txtsiz > 0) {
if (dtp->txtsiz > 0) {
renderer->setDrawMode(0);
} else {
renderer->setDrawMode(2);
}
renderer->setTextColor(GetColorFromIndex(dt_vars[cnt]->txtfcol),GetColorFromIndex(dt_vars[cnt]->txtbcol));
renderer->setTextFont(dt_vars[cnt]->font);
renderer->setTextSize(abs(dt_vars[cnt]->txtsiz));
renderer->DrawStringAt(dt_vars[cnt]->xp, dt_vars[cnt]->yp, vstr, GetColorFromIndex(dt_vars[cnt]->txtfcol), 0);
renderer->setTextColor(GetColorFromIndex(dtp->txtfcol),GetColorFromIndex(dtp->txtbcol));
renderer->setTextFont(dtp->font);
renderer->setTextSize(abs(dtp->txtsiz));
// reset display vars
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);
renderer->setDrawMode(auto_draw);
}
}
}
}
}
#define DTV_JSON_SIZE 1024
void DTVarsTeleperiod(void) {
char *json = (char*)malloc(DTV_JSON_SIZE);
if (TasmotaGlobal.mqtt_data && TasmotaGlobal.mqtt_data[0]) {
uint32_t jlen = strlen(TasmotaGlobal.mqtt_data);
if (jlen < DTV_JSON_SIZE) {
char *json = (char*)malloc(jlen + 2);
if (json) {
strlcpy(json, TasmotaGlobal.mqtt_data, DTV_JSON_SIZE);
strlcpy(json, TasmotaGlobal.mqtt_data, jlen + 1);
get_dt_vars(json);
free(json);
}
}
}
}
void get_dt_mqtt(void) {
ResponseClear();
@ -1108,7 +1156,7 @@ void get_dt_vars(char *json) {
for (uint32_t cnt = 0; cnt < MAX_DT_VARS; cnt++) {
if (dt_vars[cnt]) {
if (dt_vars[cnt]->jstrbuf) {
if (dt_vars[cnt]->jstrbuf && dt_vars[cnt]->jstrbuf[0]!='[') {
char sbuf[32];
uint32_t res = JsonParsePath(&obj, dt_vars[cnt]->jstrbuf, '#', NULL, sbuf, sizeof(sbuf));
if (res) {
@ -1536,15 +1584,21 @@ void DisplayInitDriver(void)
renderer->setTextSize(Settings.display_size);
// force opaque mode
renderer->setDrawMode(0);
for (uint32_t cnt = 0; cnt < (MAX_INDEXCOLORS - PREDEF_INDEXCOLORS); cnt++) {
index_colors[cnt] = 0;
}
}
#ifdef USE_DT_VARS
free_dt_vars();
#endif
#ifdef USE_UFILESYS
Display_Text_From_File("/display.ini");
#endif
#ifdef USE_DT_VARS
free_dt_vars();
#endif
// AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "Display model %d"), Settings.display_model);