Add graph autoscale

This commit is contained in:
Carsten Schmiemann 2022-11-20 01:09:02 +01:00
parent 420d37e99e
commit 1625019b7a
1 changed files with 30 additions and 4 deletions

View File

@ -253,8 +253,6 @@ void display_screen_graph(float values[100], char* key, int buffersize)
display_header(title_graph);
display.drawLine(7, 60, 9, 60); //X mark
display.drawLine(9, 8, 9, 62); //Y boarder
display.drawStr(1,17, "1");
display.drawStr(1,40, "5");
display.drawStr(1,63, "0");
display.drawLine(7, 36, 9, 36); //marker Y 5
display.drawLine(7, 13, 9, 13); //marker Y 1
@ -264,11 +262,39 @@ void display_screen_graph(float values[100], char* key, int buffersize)
display.drawLine(i, 60, i, 62); //marker X
}
//Data display
// Auto-scale graph (scale 1kW to 15kW automatically)
float max = values[0];
// find highest value
for (int i = 0; i<buffersize; i++)
{
display.drawLine((10+i), 60, (10+i), map(values[i], 0, 1000, 60, 10));
if (max < values[i])
{
max = values[i];
}
}
int graph_max_kW = 1000;
if (max > 2000) { graph_max_kW = 2000; }
else if (max > 3000) { graph_max_kW = 3000; }
else if (max > 4000) { graph_max_kW = 4000; }
else if (max > 4000) { graph_max_kW = 4000; }
else if (max > 5000) { graph_max_kW = 5000; }
else if (max > 6000) { graph_max_kW = 6000; }
else if (max > 7000) { graph_max_kW = 7000; }
else if (max > 8000) { graph_max_kW = 8000; }
else if (max > 9000) { graph_max_kW = 9000; }
else if (max > 10000) { graph_max_kW = 10000; }
else if (max > 11000) { graph_max_kW = 11000; }
else if (max > 12000) { graph_max_kW = 12000; }
else if (max > 13000) { graph_max_kW = 13000; }
else if (max > 14000) { graph_max_kW = 14000; }
else if (max > 15000) { graph_max_kW = 15000; }
else if (max > 16000) { graph_max_kW = 16000; }
display.drawStr(1,17, (char*)(graph_max_kW/1000));
for (int i = 0; i<buffersize; i++)
{
display.drawLine((10+i), 60, (10+i), map(values[i], 0, graph_max_kW, 60, 10));
}
display.drawStr(120, 10, key);
} while ( display.nextPage() );
}