* Added timeouts to elapse before disabling NoSleep in offline or paused mode.
authorUrban Wallasch <urban.wallasch@freenet.de>
Thu, 8 Aug 2019 12:05:57 +0000 (14:05 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Thu, 8 Aug 2019 12:05:57 +0000 (14:05 +0200)
* Fixed off-by-one error in fuel and fuel_range WRT in-game display.

dash.html

index a959e9759f5a0871dbe7694b2ef464811c8672d0..3b8a81e345d41fbd525a648f17c634687b63060e 100644 (file)
--- 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
   );