From 1625019b7a82c467735b91872717bf6699643eee Mon Sep 17 00:00:00 2001 From: Carsten Schmiemann Date: Sun, 20 Nov 2022 01:09:02 +0100 Subject: [PATCH] Add graph autoscale --- src/display.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index 33ff4d4..4afe00a 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -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 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