piu_ui.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * Copyright (c) 2019 Clementine Computing LLC.
  3. *
  4. * This file is part of PopuFare.
  5. *
  6. * PopuFare is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * PopuFare is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. */
  20. var _ADDRESS = "localhost";
  21. var _URL = "http://" + _ADDRESS;
  22. var _PORT = 60535;
  23. var _VID_FEED_PORT = 8080;
  24. var _fqADDRESS = _ADDRESS + ":" + _PORT;
  25. var BG_COLOR = "#f7f7f7";
  26. var TEXT_COLOR = "#444444";
  27. var PIU_UI_VERSION = "0.1.0";
  28. var PIU_UI_VERSION_DATE = "2020-04-11";
  29. var g_snd = {
  30. "reject_fare" : "",
  31. "accept_fare" : "",
  32. "rule_error" : "",
  33. "button_press" : ""
  34. };
  35. function _beep_error() {
  36. g_snd.rule_error.currentTime=0;
  37. g_snd.rule_error.play();
  38. }
  39. function _beep_reject() {
  40. g_snd.reject_fare.currentTime=0;
  41. g_snd.reject_fare.play();
  42. }
  43. function _beep_accept() {
  44. g_snd.accept_fare.currentTime=0;
  45. g_snd.accept_fare.play();
  46. }
  47. function _beep() {
  48. g_snd.button_press.currentTime=0;
  49. g_snd.button_press.play();
  50. }
  51. var g_ctx = {
  52. "current_ui" : "ui_main",
  53. "ui_stack" : [],
  54. "ui_change_timeoutid": -1,
  55. "ui_watchdog_timeoutid": -1,
  56. "status_text": "",
  57. "status_text_w": 32,
  58. "status_text_h": 11,
  59. "status_html_text":"",
  60. "piu_status" : {
  61. "last_update" : -1
  62. },
  63. // system config
  64. //
  65. "config" : {
  66. "last_update": -1,
  67. "volume": 100,
  68. "brightness": 100,
  69. "showdimclock": 0
  70. },
  71. "x": ""
  72. };
  73. function _clear_ui_watchdog() {
  74. if (g_ctx.ui_watchdog_timeoutid >= 0) {
  75. window.clearTimeout(g_ctx.ui_watchdog_timeoutid);
  76. }
  77. }
  78. function _set_ui_watchdog(failsafe_ui, _dt) {
  79. // default to 'ui_watchdog' and 5s
  80. //
  81. failsafe_ui = (( typeof failsafe_ui === "undefined") ? "ui_watchdog" : failsafe_ui);
  82. _dt = (( typeof _dt === "undefined") ? 5000 : _dt);
  83. _clear_ui_watchdog();
  84. g_ctx.ui_watchdog_timeoutid = window.setTimeout(
  85. (function(_fsui) {
  86. return function() { console.log("???", _fsui); _switch_ui(_fsui); };
  87. })(failsafe_ui),
  88. _dt);
  89. }
  90. function _switch_ui(to) {
  91. var ele;
  92. if (g_ctx.ui_change_timeoutid > 0) {
  93. window.clearTimeout(g_ctx.ui_change_timeoutid);
  94. g_ctx.ui_change_timeoutid = -1;
  95. }
  96. var from = g_ctx.current_ui;
  97. ele = document.getElementById(from);
  98. ele.style.display = "none";
  99. ele = document.getElementById(to);
  100. ele.style.display = "block";
  101. g_ctx.current_ui = to;
  102. if (to == "ui_main") {
  103. var _x = _calculate_ui_main_status_width_height();
  104. g_ctx.status_text_h = _x.n_height;
  105. g_ctx.status_text_w = _x.n_width;
  106. }
  107. if ((to == "ui_main") ||
  108. (to == "ui_login")) {
  109. _block_status_window(to);
  110. }
  111. }
  112. function _hide_ui(from) {
  113. var ele = document.getElementById(from);
  114. ele.style.display = "none";
  115. }
  116. function _hide_ui_element(from) {
  117. var ele = document.getElementById(from);
  118. ele.style.display = "none";
  119. }
  120. function _show_ui(to) {
  121. var ele = document.getElementById(to);
  122. ele.style.display = "block";
  123. g_ctx.current_ui = to;
  124. // put pane over status window to prevent highlights,
  125. // copy/pasting, etc.
  126. //
  127. if ((to == "ui_main") ||
  128. (to == "ui_login")) {
  129. _block_status_window(to);
  130. }
  131. }
  132. function _show_ui_element(to) {
  133. var ele = document.getElementById(to);
  134. ele.style.display = "block";
  135. }
  136. function _get_now_HH_MM() {
  137. var _dt = new Date();
  138. var _sep = ":";
  139. if ( (_dt.getSeconds() % 2) == 0) {
  140. _sep = " ";
  141. }
  142. var _hr = _dt.getHours();
  143. var _min = _dt.getMinutes();
  144. var _hr_str = _hr.toString();
  145. var _min_str = _min.toString();
  146. if (_hr < 10) { _hr_str = "0" + _hr_str; }
  147. if (_min < 10) { _min_str = "0" + _min_str; }
  148. var _time_str = _hr_str + _sep + _min_str;
  149. return _time_str;
  150. }
  151. function _get_now_YYYY_MM_DD() {
  152. var _dt = new Date();
  153. var _sep = "-";
  154. var _yr = _dt.getFullYear();
  155. var _mo = _dt.getMonth()+1;
  156. var _dy = _dt.getDate();
  157. var _yr_str = _yr.toString();
  158. var _mo_str = _mo.toString();
  159. if (_mo < 10) {
  160. _mo_str = "0" + _mo_str;
  161. }
  162. var _dy_str = _dy.toString();
  163. if (_dy < 10) {
  164. _dy_str = "0" + _dy_str;
  165. }
  166. return _yr_str + _sep + _mo_str + _sep + _dy_str;
  167. }
  168. //------------
  169. // value is from [0,1]
  170. //
  171. function _process_brightness(brightness, update_system) {
  172. // 0 opacity is completely clear, so (1.0) brightness (100% brightness).
  173. //
  174. var f_brightness = parseFloat(brightness);
  175. var opacity = 1.0 - f_brightness;
  176. // fail
  177. //
  178. if ((opacity < 0.0) || (opacity > 1.0)) { return {"type":"error", "msg":"opacity out of range"}; }
  179. var ele = document.getElementById("dim_overlay");
  180. ele.style.opacity = opacity;
  181. ele = document.getElementById("ui_configuration_displaybrightness");
  182. ival = Math.floor(f_brightness*100.0);
  183. ele.innerHTML = "" + ival + "%";
  184. g_ctx.config.brightness = ival;
  185. if (update_system) { _set_system_config(); }
  186. }
  187. //------------
  188. // volume is from [0,1]
  189. //
  190. function _process_volume(vol, update_system) {
  191. var ele = document.getElementById("ui_configuration_displayvolume");
  192. ivol = Math.floor(vol*100.0);
  193. if (ivol < 0) { ivol = 0; }
  194. if (ivol > 100) { ivol = 100; }
  195. ele.innerHTML = "" + ivol + "%";
  196. g_ctx.config.volume = ivol;
  197. if (update_system) { _set_system_config(); }
  198. }
  199. var _rate_limit_beep_t = -1.0;
  200. var _rate_limit_beep_dt = 250;
  201. function _rate_limit_beep() {
  202. if (_rate_limit_beep_t<0) {
  203. _rate_limit_beep_t = Date.now();
  204. }
  205. if (Date.now() > (_rate_limit_beep_t + _rate_limit_beep_dt)) {
  206. _rate_limit_beep_t = Date.now();
  207. _beep();
  208. }
  209. }
  210. function _watchdog_tripped(inp) {
  211. console.log("watchdog UI expired!...");
  212. _reset();
  213. }
  214. function _init_dim_overlay() {
  215. var ele = document.getElementById("ui_dim_overlay");
  216. }
  217. function init() {
  218. _init_dim_overlay();
  219. g_snd.button_press = new Audio("assets/459992_florianreichelt_beep_short.mp3");
  220. g_snd.accept_fare = new Audio("assets/389214__joe-anderson22__microwave-beeps.mp3");
  221. g_snd.reject_fare = new Audio("assets/368780__gurie__start-sound-beep.mp3");
  222. g_snd.rule_error = new Audio("assets/363920__samsterbirdies__8-bit-error.mp3");
  223. var ele = document.getElementById('ui_main_vidfeed');
  224. ele.src = _URL + ":" + _VID_FEED_PORT;
  225. }
  226. (function($) {
  227. $(document).ready(function() {
  228. init();
  229. });
  230. })(jQuery);