Ver código fonte

watchdog for verification so we don't get stuck

* further 'resolves' issue #18
* found that it's too easy to get stuck in the verification
* watchdog is set for both driver and paddle verification and,
  if they take too long, switches to 'watchdog' screen to inform
  driver that UI isbeing reset
* resets UI which will deposit driver in login state
abram 5 anos atrás
pai
commit
264d11caec
2 arquivos alterados com 103 adições e 5 exclusões
  1. 20 0
      busunit/DIUv2/html/index-ORG.html
  2. 83 5
      busunit/DIUv2/html/js/diu_ui-ORG.js

+ 20 - 0
busunit/DIUv2/html/index-ORG.html

@@ -32,6 +32,26 @@
 
   <body id='body'>
 
+    <!-- ************************* -->
+    <!-- ******            ******* -->
+    <!-- ******  Watchdog  ******* -->
+    <!-- ******            ******* -->
+    <!-- ************************* -->
+
+    <div id='ui_watchdog' style='display:none;'>
+
+      <div style='width:100%; height:100%;'>
+
+        <div class='pure-g row' style='width:100%; height:100%;' >
+          <div class='pure-u-1-6 col' style=' position:absolute; top:10vh; margin-left:10vw; '>
+            <button onmousedown='_beep();' class='bdropinp bkeyHuge' id='ui_watchdog_btn'>Watchdog Timer Expired! <br> Press Button to Reset UI </button>
+          </div>
+        </div>
+
+      </div>
+
+    </div>
+
     <!-- ************************* -->
     <!-- ******            ******* -->
     <!-- ******    Login   ******* -->

+ 83 - 5
busunit/DIUv2/html/js/diu_ui-ORG.js

@@ -71,6 +71,7 @@ var g_ctx = {
   "current_ui" : "ui_login",
 
   "ui_change_timeoutid": -1,
+  "ui_watchdog_timeoutid": -1,
 
   "bulkfare" : "",
   "bulkfare_count" : "",
@@ -181,6 +182,30 @@ function _block_status_window(ui_id) {
   block_ele.style.y = rect.y;
 }
 
+function _clear_ui_watchdog() {
+  if (g_ctx.ui_watchdog_timeoutid >= 0) {
+    window.clearTimeout(g_ctx.ui_watchdog_timeoutid);
+  }
+}
+
+function _set_ui_watchdog(failsafe_ui, _dt) {
+
+  // default to 'ui_watchdog' and 5s
+  //
+  failsafe_ui = (( typeof failsafe_ui === "undefined") ? "ui_watchdog" : failsafe_ui);
+  _dt = (( typeof _dt === "undefined") ? 5000 : _dt);
+
+  _clear_ui_watchdog();
+
+  g_ctx.ui_watchdog_timeoutid = window.setTimeout(
+    (function(_fsui) {
+      return function() { console.log("???", _fsui); _switch_ui(_fsui); };
+    })(failsafe_ui),
+    _dt);
+
+}
+
+
 
 function _switch_ui(to) {
   var ele;
@@ -322,16 +347,36 @@ function _verify_driver() {
   var driver = g_ctx.driver;
   var pin = g_ctx.pin;
 
+  // have a fail safe for the verification
+  //
+  _set_ui_watchdog();
+
   _api_request("driverlogin", {"driver":driver, "pin":pin}, _verify_driver_ok, _verify_driver_fail);
   return;
 }
 
-function _verify_driver_ok()      { console.log("driver ok"); _switch_ui("ui_paddle"); }
-function _verify_driver_fail()    { console.log("driver fail"); _switch_ui("ui_driverincorrect");  }
+function _verify_driver_ok() {
+  console.log("driver ok");
+
+  _clear_ui_watchdog();
+
+  _switch_ui("ui_paddle");
+}
+
+function _verify_driver_fail() {
+  console.log("driver fail");
+
+  _clear_ui_watchdog();
+
+  _switch_ui("ui_driverincorrect");
+}
+
 function _driver_incorrect(inp)  {
   console.log("driver incorrect");
 
+  _clear_ui_watchdog();
   _clear_ui_driver();
+
   _switch_ui("ui_driver");
 }
 
@@ -412,22 +457,51 @@ function _driver_login(inp) {
 function _verify_paddle() {
   var paddle = g_ctx.paddle;
 
+  // have a fail safe for the verification
+  //
+  _set_ui_watchdog();
+
   _api_request("paddleinput", {"paddle":paddle}, _verify_paddle_ack, _verify_paddle_fail);
   return;
 }
 
-function _verify_paddle_ack()    { console.log("got ack for push paddle message\n"); }
-function _verify_paddle_ok()    { console.log("verify paddle ok"); _switch_ui("ui_main"); }
-function _verify_paddle_fail()  { console.log("verify paddle fail"); _switch_ui("ui_paddleunknown"); }
+function _verify_paddle_ack() {
+  console.log("got ack for push paddle message\n");
+
+}
+
+function _verify_paddle_ok() {
+  console.log("verify paddle ok");
+
+  _clear_ui_watchdog();
+
+  _switch_ui("ui_main");
+
+}
+
+function _verify_paddle_fail() {
+  console.log("verify paddle fail");
+
+  _clear_ui_watchdog();
+
+  _switch_ui("ui_paddleunknown");
+}
 
 function _paddle_unknown(inp)   {
 
   console.log("paddle unknown...");
 
+  _clear_ui_watchdog();
   _clear_ui_paddle();
+
   _switch_ui("ui_paddle");
 }
 
+function _watchdog_tripped(inp)   {
+  console.log("watchdog UI expired!...");
+  _reset();
+}
+
 //------------
 
 function _paddle_input(inp) {
@@ -1105,6 +1179,10 @@ function init() {
 
   _init_websocket();
 
+  // watchdog
+  //
+  document.getElementById('ui_watchdog_btn').onclick = _watchdog_tripped;
+
   // diagnostics
   //
   document.getElementById('ui_diagnostic_mainscreen').onclick = _mainscreen;