Fix display rotation with skip

This commit is contained in:
Carsten Schmiemann 2022-11-13 22:53:59 +01:00
parent 29e46d526c
commit 32256bf77a
2 changed files with 50 additions and 34 deletions

View File

@ -249,7 +249,7 @@ void display_screen_graph(float values[100])
logPrintD("Display graph...");
display.firstPage();
do {
display_header("Graph");
display_header((char*)"Graph");
display.drawLine(8, 27, 127, 27);
display.drawLine(8, 10, 8, 27);
display.drawStr(18,53, "0");

View File

@ -95,6 +95,8 @@ bool display_conf_dc_pvcharger_present = false;
bool display_conf_graph_pv_present = false;
bool display_conf_statistics_present = false;
float display_graph_power[100] = { 0 };
int display_refresh_counter = 0;
int display_refresh_time;
//WiFiManager flag for saving data
bool shouldSaveConfig = false;
@ -435,6 +437,7 @@ void setup() {
DISPLAY_REFRESH_INTERVAL = strtol(disp_refresh_interval, NULL, 10);
DISPLAY_SCREEN_INTERVAL = strtol(disp_screen_interval, NULL, 10);
display_refresh_time = DISPLAY_SCREEN_INTERVAL / DISPLAY_REFRESH_INTERVAL;
//parse config and set display parameter
if (strtol(address_outside_temperature, NULL, 10) != 0)
@ -606,21 +609,53 @@ void loop() {
digitalWrite(STATUS_LED, LOW); //Turn Status LED ON again
lastDispRefreshTime += DISPLAY_REFRESH_INTERVAL;
if (display_screen == 0) {
if (display_refresh_counter <= display_refresh_time)
{
display_screen_grid(grid_p, inv_p, inv_i, pv_w);
}
if (display_screen == 1) {
if (display_refresh_counter >= display_refresh_time && display_refresh_counter <= (display_refresh_time*2))
{
display_screen_battery(batt_v, batt_i, batt_p, batt_soc, batt_c_min, batt_c_max);
}
if (display_screen == 2 && display_conf_dc_pvcharger_present) {
display_screen_pv(pv_v, pv_w, batt_v, pv_i, pv_kwh);
} else {display_screen++;}
if (display_screen == 3 && display_conf_graph_pv_present) {
display_screen_graph(display_graph_power[100]);
} else {display_screen++;}
if (display_screen == 4 && display_conf_statistics_present) {
//To Do: display_screen_statistics(mqtt_grid_power_l1, mqtt_grid_power_l2, mqtt_grid_power_l3);
} else {display_screen++;}
if (display_refresh_counter >= (display_refresh_time*2) && display_refresh_counter <= (display_refresh_time*3))
{
if (display_conf_dc_pvcharger_present)
{
display_screen_pv(pv_v, pv_w, batt_v, pv_i, pv_kwh);
}
else
{
display_refresh_counter = (display_refresh_time*3) + 1;
}
}
if (display_refresh_counter >= (display_refresh_time*3) && display_refresh_counter <= (display_refresh_time*4))
{
if (display_conf_graph_pv_present)
{
display_screen_graph(display_graph_power);
}
else
{
display_refresh_counter = (display_refresh_time*4) + 1;
}
}
if (display_refresh_counter >= (display_refresh_time*4) && display_refresh_counter <= (display_refresh_time*5))
{
if (display_conf_statistics_present)
{
//To Do: display_screen_statistics(mqtt_grid_power_l1, mqtt_grid_power_l2, mqtt_grid_power_l3);
}
else
{
display_refresh_counter = (display_refresh_time*5) + 1;
}
}
display_refresh_counter++;
if (display_refresh_counter > (display_refresh_time*5))
{
display_refresh_counter = 0;
}
}
//Change screen after time if intervall setting not zero
@ -629,38 +664,19 @@ void loop() {
if(millis() - lastScreenChangeTime >= DISPLAY_SCREEN_INTERVAL)
{
time(&now); localtime_r(&now, &tm); //Get local time
display_time(tm.tm_hour, tm.tm_min);
display_screen++;
lastScreenChangeTime += DISPLAY_SCREEN_INTERVAL;
if (display_screen == 6)
{
display_screen = 0;
}
}
}
}
//Rotate screen if BUTTON_ROTATION is pressed
currentButtonRotationState = digitalRead(BUTTON_ROTATION);
if(lastButtonRotationState == HIGH && currentButtonRotationState == LOW)
{
display_screen++;
if (display_screen == display_last_screen + 1)
{
//If no pv power generated, skip PV charger screen
if (pv_kwh == 0)
{
display_screen = 1;
}
else
{
display_screen = 0;
}
}
lastButtonRotationState = currentButtonRotationState;
lastButtonRotationState = currentButtonRotationState;
}
if (!client.connected()) {