Bläddra i källkod

Merge branch 'master' of https://tree.clementinecomputing.com/clementinecomputing/popufare

clementinecomputing 5 år sedan
förälder
incheckning
eb89a02a6b

+ 64 - 3
busunit/DIUv2/diu_main.c

@@ -896,9 +896,6 @@ static void ui_handle_paddle_input(struct mg_connection *nc, struct http_message
   ret = mg_get_http_var(&(hm->body), "paddle", s_paddle, _SLEN);
   if (ret<=0) { mg_http_send_error(nc, 404, NULL); return; }
 
-  //DEBUG
-  printf("#got paddle %s\n", s_paddle);
-
   ipaddle = atoi(s_paddle);
   make_paddle_request(ipaddle);
 
@@ -986,6 +983,66 @@ static void ui_handle_volume(struct mg_connection *nc, struct http_message *hm)
       (unsigned long)strlen(msg_success), msg_success);
 }
 
+// custom script
+//
+static void ui_handle_custom(struct mg_connection *nc, struct http_message *hm) {
+  int i, j, ret;
+  char s_func[128], s_func_clean[128];
+  char s_param[128], s_param_clean[128];
+  char _cmd[128*3];
+
+  char msg_fail[] = "fail custom";
+  char msg_success[] = "ok custom";
+
+  memset(s_func, 0, sizeof(char)*128);
+  memset(s_param, 0, sizeof(char)*128);
+
+  ret = mg_get_http_var(&(hm->body), "function", s_func, 127);
+  if (ret<=0) { mg_http_send_error(nc, 404, NULL); return; }
+
+  ret = mg_get_http_var(&(hm->body), "parameter", s_param, 127);
+
+  memset(_cmd, 0, sizeof(char)*3*128);
+
+  // restrict to only alphnum and ',' '.'
+  //
+  memset(s_func_clean, 0, sizeof(char)*128);
+  for (i=0, j=0; (s_func[i]) && (i<(128-1)); i++) {
+    if ( ((s_func[i] >= 'a') && (s_func[i] <= 'z')) ||
+         ((s_func[i] >= 'A') && (s_func[i] <= 'Z')) ||
+         ((s_func[i] >= '0') && (s_func[i] <= '9')) ||
+         (s_func[i] == ',') || (s_func[i] == '.') ) {
+      s_func_clean[j] = s_func[i];
+      j++;
+    }
+  }
+
+  memset(s_param_clean, 0, sizeof(char)*128);
+  for (i=0, j=0; (s_param[i]) && (i<(128-1)); i++) {
+    if ( ((s_param[i] >= 'a') && (s_param[i] <= 'z')) ||
+         ((s_param[i] >= 'A') && (s_param[i] <= 'Z')) ||
+         ((s_param[i] >= '0') && (s_param[i] <= '9')) ||
+         (s_param[i] == ' ') || (s_param[i] == ',') || (s_param[i] == '.') ) {
+      s_param_clean[j] = s_param[i];
+      j++;
+    }
+  }
+
+  // assuming we're running as root for now
+  //
+  snprintf(_cmd, (3*128)-1, "/home/bus/bin/custom '%s' '%s' &", s_func_clean, s_param_clean);
+  ret = system(_cmd);
+
+  if (ret!=0) {
+    mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%s",
+        (unsigned long)strlen(msg_fail), msg_fail);
+    return;
+  }
+
+  mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%s",
+      (unsigned long)strlen(msg_success), msg_success);
+}
+
 // bring network interface up/down
 //
 static void ui_handle_interfaceupdown(struct mg_connection *nc, struct http_message *hm) {
@@ -1249,6 +1306,10 @@ static void api_handle_req(struct mg_connection *nc, struct http_message *hm) {
     ui_handle_switchserver(nc, hm);
   }
 
+  else if (strncmp(s_action, "custom", strlen("custom")+1)==0) {
+    ui_handle_custom(nc, hm);
+  }
+
   else {
     mg_http_send_error(nc, 404, NULL);
   }

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

@@ -137,19 +137,9 @@ body { letter-spacing: 0.25em; }
 .bdrop    { font-size: 6vh; border: solid .3vw #888888; box-shadow: .5vw .5vw 0px #aaaaaa; }
 .bdropinp { font-size: 6vh; border: solid .3vw #888888; box-shadow: .5vw .5vw 0px #aaaaaa; }
 
-/*
 .bkey       { width: 20vh; height: 20vh; }
-.bkeyFull   { width: 96vw; height: 96vh; }
-.bkeyNarrow { width: 12vw; height: 40vh; }
-.bkeyw      { width: 25vw; height: 17vh; }
-.bkeym      { width: 20vw; height: 17vh; }
-.bkeyHuge   { width: 80vw; height: 80vh; }
-.bfieldinp  { width: 20vw; height: 20vh; }
-*/
 
-.bkey       { width: 18vh; height: 22vh; }
 .bkeyFull   { width: 96vw; height: 96vh; }
-/* .bkeyNarrow { width: 12vw; height: 40vh; } */
 .bkeyNarrow { width: 12vw; height: 25vh; }
 .bkeyTime { width:16vw; height:10vh; }
 

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

@@ -70,8 +70,15 @@
       <div class='pure-g row'>
 
         <div class='pure-u-1-3 col'> <button onmousedown='_beep();' class='bdropinp bkeyw' id='ui_login_login'>Login</button> </div>
+        <div class='pure-u-1-3 col'>
+          <button class='bdisp bkeyTime' id='ui_login_time' style='color:#773333; font-family: monospace; font-size: 6.5vh;' >
+            02:34
+          </button>
+        </div>
+        <!--
         <div class='pure-u-1-6 col'> </div>
         <div class='pure-u-1-6 col'> </div>
+        -->
         <div class='pure-u-1-3 col'> <button onmousedown='_beep();' class='bdropinp bkeyw' id='ui_login_configuration'>Config</button> </div>
 
       </div>

+ 42 - 14
busunit/DIUv2/html/js/diu_ui-ORG.js

@@ -27,8 +27,8 @@ var _fqADDRESS = _ADDRESS + ":" + _PORT;
 var BG_COLOR = "#f7f7f7";
 var TEXT_COLOR = "#444444";
 
-var DIU_UI_VERSION = "0.1.9";
-var DIU_UI_VERSION_DATE = "2020-01-30";
+var DIU_UI_VERSION = "0.1.10";
+var DIU_UI_VERSION_DATE = "2020-02-10";
 
 var g_snd = {
   "reject_fare" : "",
@@ -271,10 +271,7 @@ function _show_ui_element(to) {
 
 //------------
 
-function _update_display_time() {
-  var ele = document.getElementById("ui_main_time");
-  if (typeof ele === "undefined") { return; }
-
+function _get_now_HH_MM() {
   var _dt = new Date();
 
   var _sep = ":";
@@ -294,7 +291,39 @@ function _update_display_time() {
 
   var _time_str = _hr_str + _sep + _min_str;
 
-  //ele.innerText = _time_str;
+  return _time_str;
+}
+
+function _update_display_time() {
+  var ele = document.getElementById("ui_main_time");
+  if (typeof ele === "undefined") { return; }
+
+  /*
+  var _dt = new Date();
+  var _sep = ":";
+  if ( (_dt.getSeconds() % 2) == 0) { _sep = " "; }
+  var _hr = _dt.getHours();
+  var _min = _dt.getMinutes();
+  var _hr_str = _hr.toString();
+  var _min_str = _min.toString();
+  if (_hr < 10) { _hr_str = "0" + _hr_str; }
+  if (_min < 10) { _min_str = "0" + _min_str; }
+  var _time_str = _hr_str + _sep + _min_str;
+  */
+
+  var _time_str = _get_now_HH_MM();
+
+  ele.innerHTML = "<span style='white-space:nowrap;'>" + _time_str + "</span>";
+}
+
+//------------
+
+function _update_login_time() {
+  var ele = document.getElementById("ui_login_time");
+  if (typeof ele === "undefined") { return; }
+
+  var _time_str = _get_now_HH_MM();
+
   ele.innerHTML = "<span style='white-space:nowrap;'>" + _time_str + "</span>";
 }
 
@@ -314,16 +343,12 @@ function _slider_change(name) {
     _process_volume(val);
 
     ivol = Math.floor(val*100.0);
-    _api_request("volume", {"volume":ivol},
-      function(inp) { console.log("volume api set ok:", inp); },
-      function(inp) { console.log("volume api set fail:", inp); });
+    _api_request("custom", {"function":"volume", "parameter":ivol});
   }
 }
 
 function _volume_test() {
-  _api_request("say", {"message":"testing 1, 2, 3"},
-    function(inp) { console.log("volume test ok:", inp); },
-    function(inp) { console.log("volume test fail:", inp); });
+  _api_request("custom", {"function":"say", "parameter":"testing 1, 2, 3"});
 }
 
 //------------
@@ -576,12 +601,14 @@ function _main_nxt() {
 
 function _main_dim() {
   console.log("dim...");
-  _api_request("dim");
+  //_api_request("dim");
+  _api_request("custom", {"function":"dim"});
   _switch_ui('ui_dim');
 }
 
 function _dim_wakeup() {
   console.log("waking up from dim");
+  _api_request("custom", {"function": "undim" });
   _switch_ui("ui_main");
 }
 
@@ -1233,6 +1260,7 @@ function init() {
   _init_websocket();
 
   window.setInterval(_update_display_time, 200);
+  window.setInterval(_update_login_time, 200);
 
   // watchdog
   //

+ 1 - 1
busunit/rootfs/etc/rc.local

@@ -42,6 +42,6 @@ sleep 1
 
 #xinit /home/bus/bin/start-kiosk.sh >> /tmp/kiosk.log 2>&1 &
 #su -l pi -c /usr/bin/startx /home/bus/bin/start-kiosk.sh >> /tmp/kiosk.log 2>&1 &
-( sleep 5 && usr/bin/startx /home/bus/bin/start-kiosk.sh >> /tmp/kiosk.log 2>&1 ) &
+( sleep 5 && /usr/bin/startx /home/bus/bin/start-kiosk.sh >> /tmp/kiosk.log 2>&1 ) &
 
 exit 0

+ 92 - 0
busunit/scripts/custom

@@ -0,0 +1,92 @@
+#!/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/>.
+#
+
+func="$1"
+param="$2"
+
+echo "$0 , $func , $param ." >> /tmp/custom.log
+
+if [[ "$func"  == "dim" ]] ; then
+  infofn="/tmp/kiosk.info"
+
+  export DISPLAY=':0'
+  export XAUTHORITY='/home/pi/.Xauthority'
+
+  if [[ -e "/tmp/kiosk.info" ]] ; then
+
+    disp=`grep DISPLAY $infofn | cut -f2 -d'='`
+    auth=`grep XAUTHORITY $infofn | cut -f2 -d'='`
+
+    export DISPLAY="$disp"
+    export XAUTHORITY="$auth"
+
+  fi
+
+  /usr/bin/xset dpms force off
+
+elif [[ "$func" == "undim" ]] ; then
+
+  infofn="/tmp/kiosk.info"
+
+  export DISPLAY=':0'
+  export XAUTHORITY='/home/pi/.Xauthority'
+
+  if [[ -e "/tmp/kiosk.info" ]] ; then
+
+    disp=`grep DISPLAY $infofn | cut -f2 -d'='`
+    auth=`grep XAUTHORITY $infofn | cut -f2 -d'='`
+
+    export DISPLAY="$disp"
+    export XAUTHORITY="$auth"
+
+  fi
+
+  /usr/bin/xset s noblank
+  /usr/bin/xset s off
+  /usr/bin/xset -dpms
+
+elif [[ "$func" == "interface" ]] ; then
+
+  if [[ "$param" == "up" ]]; then
+    /sbin/ip link set eth0 up
+  elif [[ "$param" == "down" ]] ; then
+    /sbin/ip link set eth0 down
+  fi
+
+elif [[ "$func" == "ts_calibrate" ]] ; then
+
+  /usr/bin/ts_calibrate
+
+elif [[ "$func" == "volume" ]] ; then
+
+  vol=100
+  if [[ "$param" != "" ]] ; then vol=`printf "%2d" "$param" 2> /dev/null` ; fi
+  chan=`amixer controls | grep Volume | head -n1 | cut -f1 -d',' | cut -f2 -d'='`
+  amixer cset numid=$chan -- ${vol}% > /dev/null
+
+elif [[ "$func" == "say" ]] ; then
+
+  echo "$param" | espeak --stdin --stdout | aplay 2> /dev/null
+
+fi
+
+exit 0
+
+