Просмотр исходного кода

updates:

* diu_minder reports a custom configuration in it's status message, if available
* configuration has volume, brightness and 'show clock on dim' option
* config menu in UI has additional 'show clock on dim' option
* volume slider now beeps (rate limited) instead of explicit 'test' button
* software dime function that shows clock if option set
* ui/diu_minder/custom chain can set configuration
* check_deploy.sh - simple helper script to see if deployed programs match
  up to repo
clementinecomputing 5 лет назад
Родитель
Сommit
5fdacefa7a

+ 4 - 4
aux/check_deploy.sh

@@ -1,19 +1,19 @@
 #!/bin/bash
 #
 # Copyright (c) 2019 Clementine Computing LLC.
-# 
+#
 # This file is part of PopuFare.
-# 
+#
 # PopuFare is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
-# 
+#
 # PopuFare is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU Affero General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU Affero General Public License
 # along with PopuFare.  If not, see <https://www.gnu.org/licenses/>.
 #

+ 22 - 5
busunit/DIUv2/diu_main.c

@@ -54,7 +54,7 @@
 
 #define _SLEN LINE_BUFFER_SIZE
 
-#define DIU_MINDER_VERSION "2.1.11"
+#define DIU_MINDER_VERSION "2.1.12"
 
 static const char *s_http_port = "60535";
 static struct mg_serve_http_opts s_http_server_opts;
@@ -722,9 +722,10 @@ static void process_ws_message(struct websocket_message *ws_msg) {
 // ui wants status information
 //
 static void ui_handle_status_input(struct mg_connection *nc, struct http_message *hm) {
-  int i, npkgs, npkgnet=0;
+  int i, npkgs, npkgnet=0, ncfgline=0;
   char buf[4*_SLEN],
        pkgnetline[_SLEN],
+       cfgline[_SLEN],
        _str[_SLEN];
   char date_str[32];
   time_t t;
@@ -732,6 +733,11 @@ static void ui_handle_status_input(struct mg_connection *nc, struct http_message
   FILE *fp;
   package_signature pkgs[MAX_PKGS];
 
+  buf[0] = '\0';
+  cfgline[0] = '\0';
+  pkgnetline[0] = '\0';
+  _str[0] = '\0';
+
   t = time(NULL);
   localtime_r(&t, &tm);
   strftime(date_str, 32, "%Y-%m-%d", &tm);
@@ -753,7 +759,6 @@ static void ui_handle_status_input(struct mg_connection *nc, struct http_message
 
   fp = fopen("/tmp/net_ids", "rb");
   if (fp) {
-    i=0;
     while (fgets(_str, _SLEN, fp)) {
       strip_crlf(_str);
       _strnncat(pkgnetline, "|", _SLEN);
@@ -764,6 +769,17 @@ static void ui_handle_status_input(struct mg_connection *nc, struct http_message
   }
 
 
+  fp = fopen(CONFIG_FILE_PATH "/popufare.config", "rb");
+  if (fp) {
+    while (fgets(_str, _SLEN, fp)) {
+      strip_crlf(_str);
+      _strnncat(cfgline, "|", _SLEN);
+      _strnncat(cfgline, _str, _SLEN);
+      ncfgline++;
+    }
+    fclose(fp);
+  }
+
   snprintf(buf, 4*_SLEN, "ok msg=status\n"
       "equipno=%d|"
 
@@ -782,8 +798,8 @@ static void ui_handle_status_input(struct mg_connection *nc, struct http_message
 
       "date=%s|"
       "nmsg=%d|"
-      "last_token=%d"
-
+      "last_token=%d|"
+      "%s"
       "%s",
 
       get_equip_num(),
@@ -805,6 +821,7 @@ static void ui_handle_status_input(struct mg_connection *nc, struct http_message
       bill_stat.unsynced_messages,
       token_diag_serial % 100,
 
+      cfgline,
       pkgnetline);
 
   mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%s",

+ 16 - 0
busunit/DIUv2/html/css/diustyles.css

@@ -240,6 +240,22 @@ body { letter-spacing: 0.25em; }
 
 }
 
+.bdropdark {
+  font-weight: bold;
+  color: #444444;
+
+  background: none;
+
+  -webkit-transition: margin-left 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
+  -moz-transition: margin-left 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
+  transition: margin-left 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
+
+  font-size: 6vh;
+  border: solid .3vw #000000;
+  box-shadow: .5vw .5vw 0px #000000;
+
+}
+
 .bdropinp.ltyellow  { background: #ffffbb; }
 
 .bdropinp.mny       { color: #446444; background: #efefef; }

+ 29 - 9
busunit/DIUv2/html/index-ORG.html

@@ -23,15 +23,31 @@
 <html>
 
   <head>
-
     <link rel="stylesheet" href="css/diustyles.css">
     <link rel="stylesheet" href="css/grids.css">
-
-
   </head>
 
   <body id='body'>
-    <div id='dim_overlay' style='z-index:100;'></div>
+
+    <div id='dim_overlay' style='z-index:1001;'></div>
+
+    <!--
+      an optional clock display under 'quick dim' mode
+    -->
+    <div id='ui_dimclock' style='z-index:1000; display:none; background:#000000;'>
+      <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='bdropdark bkeyHuge' id='ui_dimclock_btn'>
+              <span id='ui_dimclock_clock' class='bkeyTime'> ok </span> <br>
+              <span id='ui_dimclock_date' class='bkeyDate'> ok </span> <br>
+            </button>
+
+          </div>
+        </div>
+      </div>
+    </div>
 
     <div id='ui_test'>X</div>
 
@@ -164,13 +180,17 @@
 
       <div class='pure-g row4'>
 
-        <div class='pure-u-1-3 col'> </div>
-        <div class='pure-u-1-3 col'> <button class='bdropinp bkeym' id='ui_configuration_volumetest'>Test</button> </div>
-        <div class='pure-u-1-3 col'>  </div>
-
+        <div class='pure-u-1-3 col'> <button class='bdisp' style='font-size:5vh;'></button> </div>
+        <div class='pure-u-1-3 col'> <button class='bdisp' style='font-size:5vh;'>Show Clock on Dim</div>
+        <div class='pure-u-1-3 col'> <button class='bdisp' style='font-size:5vh;'>
+            <button
+              onmousedown='_btn_show_clock_on_dim_toggle();'
+              class='bdropinp bkey'
+              id='ui_configuration_showclockondim'>
+            </button>
+        </div>
       </div>
 
-
     </div>
 
     <!-- ********************************* -->

+ 145 - 11
busunit/DIUv2/html/js/diu_ui-ORG.js

@@ -83,7 +83,18 @@ var g_ctx = {
 
   "status_html_text":"",
 
-  "diu_status" : {},
+  "diu_status" : {
+    "last_update" : -1
+  },
+
+  // system config
+  //
+  "config" : {
+    "last_update": -1,
+    "volume": 100,
+    "brightness": 100,
+    "showdimclock": 0
+  },
 
   "x": ""
 };
@@ -143,8 +154,6 @@ function _api_request(action, param, cb_ok, cb_fail, cb_neterr) {
 
   req.addEventListener("error", _api_fail);
   req.addEventListener("abort", _api_fail);
-  //req.addEventListener("load", _api_tick);
-  //req.addEventListener("progress", _api_tick);
 
   req.onerror = function() { console.log("network error"); };
 
@@ -342,9 +351,23 @@ function _update_login_date() {
 
 //------------
 
+function _update_dimclock_datetime() {
+  var ele = document.getElementById("ui_dimclock_clock");
+  if (typeof ele === "undefined") { return; }
+  var _time_str = _get_now_HH_MM();
+  ele.innerHTML = "<span style='white-space:nowrap;'>" + _time_str + "</span>";
+
+  var ele = document.getElementById("ui_dimclock_date");
+  if (typeof ele === "undefined") { return; }
+  var _date_str = _get_now_YYYY_MM_DD();
+  ele.innerHTML = "<span style='white-space:nowrap;'>" + _date_str + "</span>";
+}
+
+//------------
+
 // value is from [0,1]
 //
-function _process_brightness(brightness) {
+function _process_brightness(brightness, update_system) {
 
   // 0 opacity is completely clear, so (1.0) brightness (100% brightness).
   //
@@ -361,29 +384,55 @@ function _process_brightness(brightness) {
   ele = document.getElementById("ui_configuration_displaybrightness");
   ival = Math.floor(f_brightness*100.0);
   ele.innerHTML = "" + ival + "%";
+
+  g_ctx.config.brightness = ival;
+
+  if (update_system) { _set_system_config(); }
 }
 
 //------------
 
 // volume is from [0,1]
 //
-function _process_volume(vol) {
+function _process_volume(vol, update_system) {
   var ele = document.getElementById("ui_configuration_displayvolume");
   ivol = Math.floor(vol*100.0);
+
+  if (ivol < 0)   { ivol = 0; }
+  if (ivol > 100) { ivol = 100; }
+
   ele.innerHTML = "" + ivol + "%";
+
+  g_ctx.config.volume = ivol;
+
+  if (update_system) { _set_system_config(); }
+}
+
+var _rate_limit_beep_t = -1.0;
+var _rate_limit_beep_dt = 250;
+function _rate_limit_beep() {
+  if (_rate_limit_beep_t<0) {
+    _rate_limit_beep_t = Date.now();
+  }
+  if (Date.now() > (_rate_limit_beep_t + _rate_limit_beep_dt)) {
+    _rate_limit_beep_t = Date.now();
+    _beep();
+  }
 }
 
 function _slider_change(name) {
   if (name == "configuration.volume") {
     var val = document.getElementById("ui_configuration_volume").value;
-    _process_volume(val);
+    _process_volume(val, true);
 
     ivol = Math.floor(val*100.0);
     _api_request("custom", {"function":"volume", "parameter":ivol});
+
+    _rate_limit_beep();
   }
   else if (name == "configuration.brightness") {
     var val = document.getElementById("ui_configuration_brightness").value;
-    _process_brightness(val);
+    _process_brightness(val, true);
   }
 }
 
@@ -391,6 +440,30 @@ function _volume_test() {
   _api_request("custom", {"function":"say", "parameter":"testing 1, 2, 3"});
 }
 
+function _btn_show_clock_on_dim_toggle() {
+  if (g_ctx.config.showdimclock == 0) {
+    g_ctx.config.showdimclock = 1;
+  }
+  else {
+    g_ctx.config.showdimclock = 0;
+  }
+
+  _process_showdimclock(g_ctx.config.showdimclock, true);
+
+  _beep();
+}
+
+function _process_showdimclock(val, update_system) {
+  var ele = document.getElementById("ui_configuration_showclockondim");
+
+  if (val == 1) { ele.innerHTML = 'X'; }
+  else          { ele.innerHTML = ''; }
+
+  if (update_system) {
+    _set_system_config();
+  }
+}
+
 //------------
 
 function _clear_ui_driver() {
@@ -653,9 +726,14 @@ function _main_nxt() {
 
 function _main_dim() {
   console.log("dim...");
-  //_api_request("dim");
-  _api_request("custom", {"function":"dim"});
-  _switch_ui('ui_dim');
+
+  if (g_ctx.config.showdimclock) {
+    _switch_ui("ui_dimclock");
+  }
+  else {
+    _api_request("custom", {"function":"dim"});
+    _switch_ui('ui_dim');
+  }
 }
 
 function _dim_wakeup() {
@@ -664,6 +742,15 @@ function _dim_wakeup() {
   _switch_ui("ui_main");
 }
 
+function _dim_soft_wakeup() {
+  console.log("waking up from soft dim");
+  _switch_ui("ui_main");
+
+  // just in case
+  //
+  _api_request("custom", {"function": "undim" });
+}
+
 function _fare_adult() {
   console.log("fare adult");
   _api_request("fare", {"rule":"CASH-ADULT", "param":"", "fare":"adult","count":1});
@@ -806,6 +893,8 @@ function _cb_status(inp) {
   if (valtok[0]!="msg=status") { return; }
 
   g_ctx.diu_status = {};
+  g_ctx.diu_status.last_update = Date.now();
+
   var fields = valtok[1].split("|");
   for (var ii=0; ii<fields.length; ii++) {
     var kv = fields[ii].split("=");
@@ -817,6 +906,10 @@ function _cb_status(inp) {
     g_ctx.cur_eqnum = g_ctx.diu_status["equipno"];
   }
 
+  if (g_ctx.config.last_update < 0) {
+    _get_system_config();
+  }
+
   var m = g_ctx.diu_status;
   if (g_ctx.current_ui === "ui_login") {
 
@@ -1030,6 +1123,44 @@ function _main_message_add(msg, bg_color, text_color) {
 
 }
 
+//-------------
+
+// The status message has the config lines, if present,
+// so parse them into the 'config' sub-object.
+// This should be called after we feel confident the status
+// has been updated with the most current config.
+//
+function _get_system_config() {
+  var m = g_ctx.diu_status;
+  if (typeof m === 'undefined') { return; }
+
+  g_ctx.config.last_update = Date.now();
+
+  if ("brightness" in m)    { g_ctx.config.brightness = m["brightness"]; }
+  if ("volume" in m)        { g_ctx.config.volume = m["volume"]; }
+  if ("showdimclock" in m)  { g_ctx.config.showdimclock = m["showdimclock"]; }
+
+  _process_volume(g_ctx.config.volume/100.0);
+  _process_brightness(g_ctx.config.brightness/100.0);
+  _process_showdimclock(g_ctx.config.showdimclock);
+}
+
+//---
+
+function _set_system_config_ok(dat) { }
+function _set_system_config_fail(dat) { }
+function _set_system_config() {
+  var dat = {
+    "function"  : "setconfig",
+    "parameter" : "volume " + g_ctx.config.volume + "," +
+                  "brightness " + g_ctx.config.brightness + "," +
+                  "showdimclock " + g_ctx.config.showdimclock
+  };
+
+  console.log(">>", dat);
+
+  _api_request("custom", dat, _set_system_config_ok, _set_system_config_fail);
+}
 
 //-------------
 //-------------
@@ -1337,6 +1468,7 @@ function init() {
   window.setInterval(_update_display_time, 200);
   window.setInterval(_update_login_time, 200);
   window.setInterval(_update_login_date, 200);
+  window.setInterval(_update_dimclock_datetime, 200);
 
   // watchdog
   //
@@ -1360,7 +1492,7 @@ function init() {
   //
   //document.getElementById('ui_configuration_back').onclick = _mainscreen;
   document.getElementById('ui_configuration_back').onclick = _configuration_back;
-  document.getElementById('ui_configuration_volumetest').onclick = _volume_test;
+  //document.getElementById('ui_configuration_volumetest').onclick = _volume_test;
   document.getElementById('ui_configuration_eqnum').onclick = _eqnum;
 
   // equipment number change
@@ -1390,6 +1522,8 @@ function init() {
   //
   document.getElementById('ui_dim_btn').onclick = _dim_wakeup;
 
+  document.getElementById('ui_dimclock_btn').onclick = _dim_soft_wakeup;
+
   var simple_fares   = [ "adult", "youth", "half", "bike", "wheelchair", "transfer"];
   var simple_fares_f = [ _fare_adult, _fare_youth, _fare_half, _fare_bike, _fare_wheelchair, _fare_transfer];
   for (var ii=0; ii<simple_fares.length; ii++) {

+ 1 - 1
busunit/configure_target.sh.include

@@ -28,7 +28,7 @@ case $target in
 		;;
 	
 	native)
-		echo "Building for native x86 target."
+		echo "Building for native target."
 		target_cc="gcc"
 		target_ccopts="$universal_ccopts -g -D TARGET_DEVEL_DESKTOP"
 		target_ok="$target"

+ 28 - 0
busunit/scripts/custom

@@ -85,6 +85,34 @@ elif [[ "$func" == "say" ]] ; then
 
   echo "$param" | espeak --stdin --stdout | aplay 2> /dev/null
 
+elif [[ "$func" == "getconfig" ]] ; then
+
+  cfgfn="/home/bus/config/popufare.config"
+
+  if [[ -e $cfgfn ]] ; then
+    cat $cfgfn | tr '\n' ' '
+  else
+    echo "file-not-found"
+  fi
+
+elif [[ "$func" == "setconfig" ]] ; then
+
+  cfgfn="/home/bus/config/popufare.config"
+
+  _v=`echo "$param" | tr '=' ' ' | grep -P -o 'volume (\d+)' | cut -f2 -d' '`
+  _b=`echo "$param" | tr '=' ' ' | grep -P -o 'brightness (\d+)' | cut -f2 -d' '`
+  _d=`echo "$param" | tr '=' ' ' | grep -P -o 'showdimclock (\d+)' | cut -f2 -d' '`
+
+  if [[ "$_v" == "" ]] ; then _v=100; fi
+  if [[ "$_b" == "" ]] ; then _b=100; fi
+  if [[ "$_d" == "" ]] ; then _d="0"; fi
+
+  _t=`mktemp`
+  echo -e "volume=$_v\nbrightness=$_b\nshowdimclock=$_d\n" > $_t
+  mv $_t $cfgfn
+
+  cat $cfgfn | tr '\n' ' '
+
 elif [[ "$func" == "reboot" ]] ; then
 
   /sbin/reboot