Skip to content

Commit

Permalink
force redraw every 10 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
osresearch committed Oct 9, 2020
1 parent 76a8c20 commit 26199fe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
3 changes: 3 additions & 0 deletions overtime/GVB.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ struct train_t {

extern train_t * train_list;

extern void gvb_setup(void);
extern int gvb_loop(void);

#endif
38 changes: 23 additions & 15 deletions overtime/overtime.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -209,6 +212,9 @@ void setup() {
display.display();

gvb_setup();

last_draw_ms = 0;
last_query_ms = 0;
}


Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 26199fe

Please sign in to comment.