1
0

ferment_container_input.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>{{ title }}</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  7. <!-- <meta http-equiv="refresh" content="5" /> 每 content 秒網頁自動更新-->
  8. <!-- 新 Bootstrap4 核心 CSS 文件 -->
  9. <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css">
  10. <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
  11. <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  12. <!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
  13. <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
  14. <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
  15. <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
  16. <!--可用來建立使用者小圖示-->
  17. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  18. <script language="JavaScript">
  19. // 指定 秒 刷新網頁一次
  20. var ftn = '{{tid}}';
  21. var status = '{{status}}';
  22. console.log('ftn:' + ftn)
  23. $(function(){
  24. $("#ferment_input_page").text('發酵貨櫃入料儲豆槽 FI' + ftn + ' 攝影機畫面 ')
  25. $('#ferment_input_page').attr("href", "/camera_FI" + ftn)
  26. $("#ferment_input_title").text('發酵貨櫃入料儲豆槽 FI' + ftn + ' 操作介面')
  27. $("#coffee_title_pc").text('FI' + ftn + ' 發酵入料儲豆槽操作介面');
  28. $("#coffee_title_phone").text('FI' + ftn + ' 操作介面');
  29. if (status == 2) {
  30. $('input').prop('disabled', true);
  31. $('button').prop('disabled', true);
  32. } else if ( (status == 0) || (status == 1) ) {
  33. $('input').prop('disabled', false);
  34. $('button').prop('disabled', false);
  35. }
  36. });
  37. WebUpdate_set = setInterval(function(){WebUpdate(ftn)} , 10 * 1000)
  38. </script>
  39. <script>
  40. // 發酵槽_制動器控制
  41. var tank_num = '{{tid}}';
  42. function inputVacuum() {
  43. var status = "off";
  44. var check = $("input[name=input_vacuum_status]:checked"); // 這裡面是 jQuery 撈取資料的方法, jQuery 常使用到 $ 錢字號
  45. console.log('check:', check);
  46. //大於0代表有被選中, 如果有多個可以呈現勾取的項目數量
  47. if (check.length > 0) {
  48. status = "on";
  49. $("#cmn-toggle-02").prop('checked', false); // 確認是否勾選
  50. if (!confirm("你確定要開啟入料儲豆槽真空吸料機嗎?")) {
  51. return false;
  52. };
  53. } else {
  54. $("#cmn-toggle-02").prop('checked', true);
  55. if (!confirm("你確定要關閉入料儲豆槽真空吸料機嗎?")) {
  56. return false;
  57. };
  58. };
  59. var data = { "tank_num": "FI" + tank_num, "command": "input_vacuum_status", "value": status };
  60. $.post('/mqtt/{{tid}}', data, function (res) {
  61. console.log('data:', data)
  62. if (res == 'on') {
  63. $("#cmn-toggle-02").prop('checked', true);
  64. setTimeout("alert('入料儲豆槽真空吸料機_開啟成功!')", 500);
  65. } else if (res == 'off') {
  66. $("#cmn-toggle-02").prop('checked', false);
  67. setTimeout("alert('入料儲豆槽真空吸料機_關閉成功!')", 500);
  68. } else {
  69. alert(res);
  70. };
  71. }, 'text')
  72. };
  73. function inputVacuum(params) {
  74. if (params == '1') {
  75. var data = { "tank_num": "FI" + tank_num, "command": "input_vacuum_status", "value": "on" };
  76. } else if (params == '0') {
  77. var data = { "tank_num": "FI" + tank_num, "command": "input_vacuum_status", "value": "off" };
  78. } else {
  79. var data = { "tank_num": "FI" + tank_num, "command": "input_vacuum_status", "value": params };
  80. }
  81. $.post('/mqtt/{{tid}}', data, function (res) { //res:HTTP response argument to the middleware function
  82. console.log('data:', data)
  83. if (res == 'on') {
  84. $("#cmn-toggle-02").prop('checked', true);
  85. } else if (res == 'off') {
  86. $("#cmn-toggle-02").prop('checked', false);
  87. } else {
  88. };
  89. }, 'text')
  90. };
  91. </script>
  92. <script language="JavaScript">
  93. function changeUpdate() {
  94. clearInterval(WebUpdate_set);
  95. var webupdate_time = $("input[name=webupdate_time]").val()
  96. console.log('webupdate_time' + webupdate_time)
  97. WebUpdate_set = setInterval(function(){WebUpdate(ftn)} , webupdate_time * 1000);
  98. }
  99. // jQuery 更新感測器制動器狀態
  100. function WebUpdate(ftn) {
  101. $.get('/loading/FI' + ftn, '', function (res) {
  102. if (res.input_vacuum == 0) {
  103. $("#cmn-toggle-02").prop('checked', false);
  104. } else if (res.input_vacuum == 1) {
  105. $("#cmn-toggle-02").prop('checked', true);}
  106. $("#UltraSonic_t_status").text(res.input_UltraSonic);
  107. }, 'json');
  108. }
  109. </script>
  110. </head>
  111. <body>
  112. <div id="wrapper">
  113. <div id="coffee_header">
  114. <!-- 匯入共同使用的 header.html 內容 -->
  115. {% include 'header.html' %}
  116. </div>
  117. <h4>制動器</h4>
  118. <table border="1" class="table-all" cellpadding="5" style="text-align: center;">
  119. <tr>
  120. <td style="color:red;">Valve</td>
  121. <td>真空吸料機</td>
  122. </tr>
  123. <tr>
  124. <td>
  125. <span style="color:#C0C0C0;">off</span>
  126. <span style="color:#008CBA;">on</span>
  127. </td>
  128. <td>
  129. <div class="switch_div">
  130. <div class="switch">
  131. <input type="checkbox" class="cmn-toggle cmn-toggle-round" id="cmn-toggle-01">
  132. </div>
  133. <div class="switch text-center">
  134. {% if input_vacuum == 1 %}
  135. <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-02" checked
  136. name="tank_vacuum_status" value="ON" onclick="inputVacuum()">
  137. {% else %}
  138. <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-02"
  139. name="tank_vacuum_status" value="OFF" onclick="inputVacuum()">
  140. {% endif %}
  141. <label class="label_ActuatorStatus" for="cmn-toggle-02"></label>
  142. </div>
  143. <div class="switch">
  144. <input type="checkbox" class="cmn-toggle cmn-toggle-yes-no" id="cmn-toggle-03">
  145. </div>
  146. </div>
  147. </td>
  148. </tr>
  149. <tr>
  150. <td><span style="color:#008CBA;"><b>ON</b></span></td>
  151. <td><input type="button" class="input-button-on" value="ON" onclick="inputVacuum('1')"></td>
  152. </tr>
  153. <tr>
  154. <td><span style="color:#C0C0C0;"><b>OFF</b></span></td>
  155. <td><input type="button" class="input-button-off" value="OFF" onclick="inputVacuum('0')"></td>
  156. </tr>
  157. </table>
  158. <br>
  159. <h4>感測器</h4>
  160. <table border="1" class="table-all" cellpadding="5">
  161. <tr>
  162. <td>生豆高度:<span id="UltraSonic_t_status">{{input_UltraSonic.UltraSonic}}</span> 公分</td>
  163. </tr>
  164. </table>
  165. <br>
  166. <h4>排程設計</h4>
  167. <table border="1" class="table-all" cellpadding="5">
  168. <tr>
  169. <td>入料</td>
  170. <td>循環測試</td>
  171. </tr>
  172. <tr>
  173. <td>
  174. 指定桶內生豆高度
  175. <input type="text" class="input-text" name="testing_BeanIn_Height" value="0">公分<br>
  176. 吸料時間
  177. <input type="text" class="input-text" name="testing_in_vacuum_in" value="5">秒<br>
  178. 放料時間
  179. <input type="text" class="input-text" name="testing_in_vacuum_out" value="10">秒<br>
  180. 循環次數
  181. <input type="text" class="input-text" name="testing_in_vacuum_loop" value="3">次<br>
  182. </td>
  183. <td>
  184. ON (開)
  185. <input type="text" class="input-text" name="Testing_starttime" value="3">秒<br>
  186. OFF (關)
  187. <input type="text" class="input-text" name="Testing_endtime" value="5">秒<br>
  188. 循環
  189. <input type="text" class="input-text" name="Testing_loop" value="3">次
  190. </td>
  191. </tr>
  192. <tr>
  193. <td>
  194. <button type="submit" class="btn btn-primary" onclick="CoffeeIn_testing()">入豆測試</button>
  195. <script>
  196. CoffeeIn_Process = 0; // 生豆入豆狀態
  197. function CoffeeIn_testing() {
  198. var testing_tank_coffee_height = $("input[name=testing_tank_coffee_height]").val();
  199. console.log('目標入料高度' + testing_tank_coffee_height)
  200. var testing_tank_vacuum_in = $("input[name=testing_tank_vacuum_in]").val();
  201. var testing_tank_vacuum_out = $("input[name=testing_tank_vacuum_out]").val();
  202. var testing_tank_vacuum_loop = $("input[name=testing_tank_vacuum_loop]").val();
  203. if (testing_tank_coffee_height != 0) {
  204. console.log('以目標高度入豆')
  205. var Coffee_interval = setInterval(tankCoffeeHeight, 5000);
  206. function tankCoffeeHeight(){
  207. if (CoffeeIn_Process == 1){
  208. return;
  209. }
  210. CoffeeIn_Process = 1;
  211. $.ajax({
  212. async:false,
  213. type:'GET',
  214. url:'/ferment_LiDAR_' + tank_num,
  215. dataType:'JSON',
  216. success:function(response){
  217. var present_Coffee_height = response.LiDAR
  218. console.log("目前生豆高度: ", present_Coffee_height)
  219. if( present_Coffee_height >= testing_tank_coffee_height){
  220. clearInterval(Coffee_interval);
  221. console.log("生豆已達目標高度!")
  222. CoffeeIn_Process = 0;
  223. } else {
  224. inputVacuum('1')
  225. console.log('inputVacuum_ON')
  226. var time = new Date();
  227. while ((new Date() - time) < testing_tank_vacuum_in * 1000) { };
  228. inputVacuum('0')
  229. console.log('inputVacuum_OFF')
  230. var time = new Date();
  231. while ((new Date() - time) < testing_tank_vacuum_out * 1000) { };
  232. CoffeeIn_Process = 0;
  233. }
  234. },
  235. error:function(thrownError){
  236. console.log("Error: " + thrownError)
  237. CoffeeIn_Process = 0;
  238. }
  239. });
  240. CoffeeIn_Process = 0;
  241. };
  242. } else if (testing_tank_coffee_height == 0){
  243. console.log('開始循環入豆')
  244. for (step = 1; step <= testing_tank_vacuum_loop; step++) {
  245. console.log('-- 循環第 ' + step + ' 次 --');
  246. inputVacuum('1')
  247. console.log('inputVacuum_ON')
  248. var time = new Date();
  249. while ((new Date() - time) < testing_tank_vacuum_in * 1000) { };
  250. inputVacuum('0')
  251. console.log('inputVacuum_OFF')
  252. var time = new Date();
  253. while ((new Date() - time) < testing_tank_vacuum_out * 1000) { };
  254. }
  255. console.log('-- 循環入豆結束 --')
  256. }
  257. }
  258. </script>
  259. </td>
  260. <td>
  261. <button type="submit" class="btn btn-primary" onclick="tankVacuumTest()">真空吸料機測試(秒)</button><br>
  262. <script>
  263. function tankVacuumTest() {
  264. clearInterval(WebUpdate_set);
  265. var Testing_starttime = $("input[name=Testing_starttime]").val();
  266. var Testing_endtime = $("input[name=Testing_endtime]").val();
  267. var Testing_loop = $("input[name=Testing_loop]").val();
  268. alert('測試間隔' + Testing_starttime + ':' + Testing_endtime + ' 次數' + Testing_loop)
  269. var step;
  270. for (step = 1; step <= Testing_loop; step++) {
  271. console.log('循環第 ' + step + ' 次');
  272. inputVacuum('1')
  273. console.log('inputVacuum_ON')
  274. var time = new Date();
  275. while ((new Date() - time) < Testing_starttime * 1000) { }
  276. inputVacuum('0')
  277. console.log('inputVacuum_OFF')
  278. var time = new Date();
  279. while ((new Date() - time) < Testing_endtime * 1000) { }
  280. }
  281. WebUpdate_set = setInterval(function(){WebUpdate(dtn)} , 10 * 1000);
  282. }
  283. </script>
  284. </td>
  285. </tr>
  286. </table>
  287. <div id="coffee_footer">
  288. <!-- 匯入共同使用的 footer.html 內容 -->
  289. {% include 'footer.html' %}
  290. </div>
  291. </div>
  292. </body>
  293. </html>