From 26199fee4d73eb594289560aeb93a5afbe254b4f Mon Sep 17 00:00:00 2001 From: Trammell Hudson Date: Fri, 9 Oct 2020 06:12:06 -0400 Subject: [PATCH] force redraw every 10 seconds --- overtime/GVB.h | 3 +++ overtime/overtime.ino | 38 +++++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/overtime/GVB.h b/overtime/GVB.h index ddc1e34..10d6a49 100644 --- a/overtime/GVB.h +++ b/overtime/GVB.h @@ -20,4 +20,7 @@ struct train_t { extern train_t * train_list; +extern void gvb_setup(void); +extern int gvb_loop(void); + #endif diff --git a/overtime/overtime.ino b/overtime/overtime.ino index 42f4460..ffb38f3 100644 --- a/overtime/overtime.ino +++ b/overtime/overtime.ino @@ -43,10 +43,13 @@ WebsocketsClient ws; #define TZ_OFFSET (1 * 3600) // watchdog: if we don't get a packet for this long, reboot -const unsigned long query_interval_ms = 600 * 1000; // ten minutes -//const unsigned long query_interval_ms = 10 * 1000; // debug +const unsigned long query_interval_ms = 5 * 60 * 1000; // five minutes unsigned long last_query_ms; +// ensure that updates happen at least this often +const unsigned long draw_interval_ms = 10 * 1000; // ten seconds +unsigned long last_draw_ms; + /* 250x122 => 83 wide per entry BIG sec BIG sec BIG sec MIN MIN MIN sec @@ -209,6 +212,9 @@ void setup() { display.display(); gvb_setup(); + + last_draw_ms = 0; + last_query_ms = 0; } @@ -289,27 +295,29 @@ static int draw_train(train_t * t, int count) void loop() { -#if 0 - const int remaining_ms = ui.update(); - if (remaining_ms < 0) - return; -#endif + const unsigned long now_ms = millis(); - unsigned long now_ms = millis(); - - if (!gvb_loop()) + if (gvb_loop()) + { + // we have a packet! reset the watchdog + last_query_ms = now_ms; + } else + if (now_ms - last_query_ms > query_interval_ms) { - if (now_ms - last_query_ms < query_interval_ms) - return; - // it has been too long without some sort of update; // re-initiate the wifi and connection and everything setup(); return; + } else + if (now_ms - last_draw_ms > draw_interval_ms) + { + // update the display anyway + last_draw_ms = now_ms; + } else { + // nothing to do + return; } - // we have a packet! reset the watchdog - last_query_ms = now_ms; // dump the list, drawing the first few to the display display.clearBuffer();