From f7eaa892789d7da7122d7b50c7d164520b513aef Mon Sep 17 00:00:00 2001 From: Urban Wallasch Date: Thu, 8 Aug 2019 14:05:57 +0200 Subject: [PATCH] * Added timeouts to elapse before disabling NoSleep in offline or paused mode. * Fixed off-by-one error in fuel and fuel_range WRT in-game display. --- dash.html | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/dash.html b/dash.html index a959e97..3b8a81e 100644 --- a/dash.html +++ b/dash.html @@ -242,6 +242,14 @@ function dgear(x, f, m) { return 'N'; } +// Return current time stamp in seconds: +function tnow() { + return Math.floor(Date.now() / 1000); +} + +// Timestamp of last activity, used for NoSleep timeout: +var last_active = tnow(); + // Used to calculate current fuel consumption: var last_fuel = -1; var last_odometer = -1; @@ -254,7 +262,8 @@ function update_cb() { //// pause and error bar status: if ( !(tele.tele_flags & 1) ) { // TELE_FLAG_ALIVE - disableNoSleep(); + if ( tnow() - last_active > 300 ) // 5 minutes NoSleep timeout + disableNoSleep(); pausebar.style.display = "none"; errbar.style.display = "block"; errbar.innerHTML = "Game offline"; @@ -268,11 +277,14 @@ function update_cb() { } if ( tele.paused ) { - disableNoSleep(); + if ( tnow() - last_active > 600 ) // 10 minutes NoSleep timeout + disableNoSleep(); pausebar.style.display = "block"; } - else + else { + last_active = tnow(); pausebar.style.display = "none"; + } //// "speedo" box @@ -306,11 +318,11 @@ function update_cb() { //// "range" box // fuel amount: - fuel.innerHTML = tele.fuel.toFixed(0); + fuel.innerHTML = (tele.fuel - 0.5).toFixed(0); warn( fuel, tele.fuel_warn ? 1 : 0 ); // estimated range remaining: - fuel_range.innerHTML = tele.fuel_range.toFixed(0); + fuel_range.innerHTML = (tele.fuel_range - 0.5).toFixed(0); // current fuel consumption: if ( last_fuel != tele.fuel && last_odometer != tele.odometer ) { @@ -488,6 +500,7 @@ function installNoSleepHandler() { noSleep.enable(); nsbar.innerHTML = "NoSleep enabled."; nsbar.classList.add("nosleepon"); + last_active = tnow(); }, false ); -- 2.30.2