fix graph colors

This commit is contained in:
gemu2015 2021-09-23 09:51:51 +02:00
parent 751366f7b7
commit 038809e5c1
1 changed files with 26 additions and 15 deletions

View File

@ -50,6 +50,11 @@ int16_t disp_xpos = 0;
int16_t disp_ypos = 0; int16_t disp_ypos = 0;
#ifdef USE_MULTI_DISPLAY #ifdef USE_MULTI_DISPLAY
#ifndef MAX_MULTI_DISPLAYS
#define MAX_MULTI_DISPLAYS 3
#endif
struct MULTI_DISP { struct MULTI_DISP {
Renderer *display; Renderer *display;
uint16_t fg_color; uint16_t fg_color;
@ -58,7 +63,7 @@ struct MULTI_DISP {
int16_t disp_ypos; int16_t disp_ypos;
uint8_t color_type; uint8_t color_type;
uint8_t auto_draw; uint8_t auto_draw;
} displays[3]; } displays[MAX_MULTI_DISPLAYS];
uint8_t cur_display; uint8_t cur_display;
Renderer *Init_uDisplay(const char *desc, int8_t cs); Renderer *Init_uDisplay(const char *desc, int8_t cs);
@ -204,6 +209,8 @@ struct GRAPH {
uint8_t yticks; uint8_t yticks;
uint8_t last_val; uint8_t last_val;
uint8_t color_index; uint8_t color_index;
uint16_t bg_color;
uint16_t fg_color;
GFLAGS flags; GFLAGS flags;
}; };
@ -583,7 +590,7 @@ void DisplayText(void)
{ {
var = atoiv(cp, &temp); var = atoiv(cp, &temp);
cp += var; cp += var;
if (temp < 1 || temp > 3) { if (temp < 1 || temp > MAX_MULTI_DISPLAYS) {
temp = 1; temp = 1;
} }
temp--; temp--;
@ -612,6 +619,7 @@ void DisplayText(void)
renderer = Init_uDisplay(fdesc, -1); renderer = Init_uDisplay(fdesc, -1);
Set_display(temp); Set_display(temp);
AddLog(LOG_LEVEL_INFO, PSTR("DSP: File descriptor loaded %x"),renderer); AddLog(LOG_LEVEL_INFO, PSTR("DSP: File descriptor loaded %x"),renderer);
free(fdesc);
} }
} }
} }
@ -2378,12 +2386,12 @@ void ClrGraph(uint16_t num) {
// clr inside, but only 1.graph if overlapped // clr inside, but only 1.graph if overlapped
if (gp->flags.overlay) return; if (gp->flags.overlay) return;
renderer->fillRect(gp->xp+1,gp->yp+1,gp->xs-2,gp->ys-2,bg_color); renderer->fillRect(gp->xp+1,gp->yp+1,gp->xs-2,gp->ys-2,gp->bg_color);
if (xticks) { if (xticks) {
float cxp=gp->xp,xd=(float)gp->xs/(float)xticks; float cxp=gp->xp,xd=(float)gp->xs/(float)xticks;
for (count=0; count<xticks; count++) { for (count=0; count<xticks; count++) {
renderer->writeFastVLine(cxp,gp->yp+gp->ys-TICKLEN,TICKLEN,fg_color); renderer->writeFastVLine(cxp,gp->yp+gp->ys-TICKLEN,TICKLEN,gp->fg_color);
cxp+=xd; cxp+=xd;
} }
} }
@ -2393,27 +2401,27 @@ void ClrGraph(uint16_t num) {
float cxp=0; float cxp=0;
float czp=gp->yp+(gp->ymax/gp->range); float czp=gp->yp+(gp->ymax/gp->range);
while (cxp<gp->xs) { while (cxp<gp->xs) {
renderer->writeFastHLine(gp->xp+cxp,czp,2,fg_color); renderer->writeFastHLine(gp->xp+cxp,czp,2,gp->fg_color);
cxp+=6.0; cxp+=6.0;
} }
// align ticks to zero line // align ticks to zero line
float cyp=0,yd=gp->ys/yticks; float cyp=0,yd=gp->ys/yticks;
for (count=0; count<yticks; count++) { for (count=0; count<yticks; count++) {
if ((czp-cyp)>gp->yp) { if ((czp-cyp)>gp->yp) {
renderer->writeFastHLine(gp->xp,czp-cyp,TICKLEN,fg_color); renderer->writeFastHLine(gp->xp,czp-cyp,TICKLEN,gp->fg_color);
renderer->writeFastHLine(gp->xp+gp->xs-TICKLEN,czp-cyp,TICKLEN,fg_color); renderer->writeFastHLine(gp->xp+gp->xs-TICKLEN,czp-cyp,TICKLEN,gp->fg_color);
} }
if ((czp+cyp)<(gp->yp+gp->ys)) { if ((czp+cyp)<(gp->yp+gp->ys)) {
renderer->writeFastHLine(gp->xp,czp+cyp,TICKLEN,fg_color); renderer->writeFastHLine(gp->xp,czp+cyp,TICKLEN,fg_color);
renderer->writeFastHLine(gp->xp+gp->xs-TICKLEN,czp+cyp,TICKLEN,fg_color); renderer->writeFastHLine(gp->xp+gp->xs-TICKLEN,czp+cyp,TICKLEN,gp->fg_color);
} }
cyp+=yd; cyp+=yd;
} }
} else { } else {
float cyp=gp->yp,yd=gp->ys/yticks; float cyp=gp->yp,yd=gp->ys/yticks;
for (count=0; count<yticks; count++) { for (count=0; count<yticks; count++) {
renderer->writeFastHLine(gp->xp,cyp,TICKLEN,fg_color); renderer->writeFastHLine(gp->xp,cyp,TICKLEN,gp->fg_color);
renderer->writeFastHLine(gp->xp+gp->xs-TICKLEN,cyp,TICKLEN,fg_color); renderer->writeFastHLine(gp->xp+gp->xs-TICKLEN,cyp,TICKLEN,gp->fg_color);
cyp+=yd; cyp+=yd;
} }
} }
@ -2443,6 +2451,9 @@ void DefineGraph(uint16_t num,uint16_t xp,uint16_t yp,int16_t xs,uint16_t ys,int
} }
} }
gp->bg_color=bg_color;
gp->fg_color=fg_color;
// 6 bits per axis // 6 bits per axis
gp->xticks=(num>>4)&0x3f; gp->xticks=(num>>4)&0x3f;
gp->yticks=(num>>10)&0x3f; gp->yticks=(num>>10)&0x3f;
@ -2496,7 +2507,7 @@ void DefineGraph(uint16_t num,uint16_t xp,uint16_t yp,int16_t xs,uint16_t ys,int
} }
// draw rectangle // draw rectangle
renderer->drawRect(xp,yp,xs,ys,fg_color); renderer->drawRect(xp,yp,xs,ys,gp->fg_color);
// clr inside // clr inside
ClrGraph(index); ClrGraph(index);
@ -2611,7 +2622,7 @@ void RedrawGraph(uint8_t num, uint8_t flags) {
if (!renderer) return; if (!renderer) return;
gp->flags.draw=1; gp->flags.draw=1;
uint16_t linecol=fg_color; uint16_t linecol=gp->fg_color;
if (color_type==COLOR_COLOR) { if (color_type==COLOR_COLOR) {
linecol = GetColorFromIndex(gp->color_index); linecol = GetColorFromIndex(gp->color_index);
@ -2619,7 +2630,7 @@ void RedrawGraph(uint8_t num, uint8_t flags) {
if (!gp->flags.overlay) { if (!gp->flags.overlay) {
// draw rectangle // draw rectangle
renderer->drawRect(gp->xp,gp->yp,gp->xs,gp->ys,fg_color); renderer->drawRect(gp->xp,gp->yp,gp->xs,gp->ys,gp->fg_color);
// clr inside // clr inside
ClrGraph(index); ClrGraph(index);
} }
@ -2634,7 +2645,7 @@ void AddGraph(uint8_t num,uint8_t val) {
struct GRAPH *gp=graph[num]; struct GRAPH *gp=graph[num];
if (!renderer) return; if (!renderer) return;
uint16_t linecol=fg_color; uint16_t linecol=gp->fg_color;
if (color_type==COLOR_COLOR) { if (color_type==COLOR_COLOR) {
linecol = GetColorFromIndex(gp->color_index); linecol = GetColorFromIndex(gp->color_index);
} }
@ -2656,7 +2667,7 @@ void AddGraph(uint8_t num,uint8_t val) {
// clr area and redraw graph // clr area and redraw graph
if (!gp->flags.overlay) { if (!gp->flags.overlay) {
// draw rectangle // draw rectangle
renderer->drawRect(gp->xp,gp->yp,gp->xs,gp->ys,fg_color); renderer->drawRect(gp->xp,gp->yp,gp->xs,gp->ys,gp->fg_color);
// clr inner and draw ticks // clr inner and draw ticks
ClrGraph(num); ClrGraph(num);
} }