<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>{{ title }}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
      <!--  <meta http-equiv="refresh" content="5" /> 每 content 秒網頁自動更新-->

    <!-- 新 Bootstrap4 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css">
    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
    <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
    <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
    <!--可用來建立使用者小圖示-->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <!-- Socket.IO -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.dev.js"></script>
    
    <script language="JavaScript">
        // 指定 10秒 刷新網頁一次
        var ctn = '{{tid}}';
        var status = '{{status}}';
        console.log('ctn:' + ctn)

        $(function(){
            $("#coffee_title_pc").text('C' + ctn + ' 清洗浮選槽操作介面');
            $("#coffee_title_phone").text('C' + ctn + ' 清洗浮選槽操作介面');

            if (status == 2) {
                $('input').prop('disabled', true);
                $('button').prop('disabled', true);
            } else if ( (status == 0) || (status == 1) ) {
                $('input').prop('disabled', false);
                $('button').prop('disabled', false);   
            }
        });
        var WebUpdate_set;
        WebUpdate_set = setInterval(function(){WebUpdate(ctn)} , 10 * 1000)
        
    </script>

    <script>
        // 清洗浮選 致動器開關
        var tank_num = '{{tid}}';

        // 桶內 真空吸料機
        function tankVacuum(params) {
            if (params == '1') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_vacuum_status", "value": "on" };
            } else if (params == '0') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_vacuum_status", "value": "off" };
            } else {
                var status = "off";
                var check = $("input[name=tank_vacuum_status]:checked");
                //大於0代表有被選中 
                if (check.length > 0) {
                    status = "on";
                    $("#cmn-toggle-02").prop('checked', false);
                    if (!confirm("你確定要開啟真空吸料機嗎?")) {
                        return false;
                    };
                } else {
                    $("#cmn-toggle-02").prop('checked', true);
                    if (!confirm("你確定要關閉真空吸料機嗎?")) {
                        return false;
                    };
                };
                var data = { "tank_num": "C" + tank_num, "command": "tank_vacuum_status", "value": status };
            }
            $.post('/mqtt/{{tid}}', data, function (res) {
                console.log('data:', data)
                if (res == 'on') {
                    $("#cmn-toggle-02").prop('checked', true);
                } else if (res == 'off') {
                    $("#cmn-toggle-02").prop('checked', false);
                } else {
                };
            }, 'text')
        }

        // 桶內 吸料機三通閥
        function tankThreeWayValveInput(params) {
            if (params == '1') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_threewayvalve_input_status", "value": "on" };
            } else if (params == '0') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_threewayvalve_input_status", "value": "off" };
            } else {
                var status = "off";
                var check = $("input[name=tank_threewayvalve_input_status]:checked");
                //大於0代表有被選中 
                if (check.length > 0) {
                    status = "on";
                    $("#cmn-toggle-05").prop('checked', false);
                    if (!confirm("你確定要開啟吸料機三通閥[入料]嗎?")) {
                        return false;
                    };
                } else {
                    $("#cmn-toggle-05").prop('checked', true);
                    if (!confirm("你確定要開啟吸料機三通閥[排氣]嗎?")) {
                        return false;
                    };
                };
                var data = { "tank_num": "C" + tank_num, "command": "tank_threewayvalve_input_status", "value": status };
            }
            $.post('/mqtt/{{tid}}', data, function (res) {
                console.log('data:', data)
                if (res == 'on') {
                    $("#cmn-toggle-05").prop('checked', true);
                } else if (res == 'off') {
                    $("#cmn-toggle-05").prop('checked', false);
                } else {
                };
            }, 'text')
        }

        // 桶內 馬達
        function tankMotor_set() {
            var motor_data = $("input[id=motor_rpm_data]").val();
            if (motor_data == '') {
                alert("請先輸入要運轉的值!");
                return false;
            } else if (motor_data == 0) {
                alert("轉速 0 為關閉馬達");

            } else if (Number(motor_data) < -50 || Number(motor_data) > 50 || !Number(motor_data)) {
                alert("您輸入的值已超過範圍，請重新輸入!" + !Number(motor_data));
                return false;
            };
            var value = "off";
            if (motor_data != 0) {
                value = motor_data;
                if (!confirm("你確定要開啟攪拌馬達，運轉速度為 " + motor_data + " RPM 嗎?")) {
                    return false;
                };
            } else {
                if (!confirm("你確定要關閉攪拌馬達嗎?")) {
                    return false;
                };
            };

            var data = { "tank_num": "C" + tank_num, "command": "tank_motor_status", "value": motor_data };
            $.post('/mqtt/{{tid}}', data, function (res) {
                console.log('data:', data)
                if (res == 'on') {
                    setTimeout("alert('攪拌馬達_開啟成功!')", 500);
                    var timer = setInterval(Rotate, 60000);
                } else if (res == 'off') {
                    setTimeout("alert('攪拌馬達_關閉成功!')", 500);
                    clearInterval(timer);
                    $("#motor_rpm_status").text('')
                } else {
                    alert(res);
                };
            }, 'text')
        };

        function tankMotor(params) {
            var params_int = parseInt(params)
            if (-50 <= params_int <= 50) {
                var data = { "tank_num": "C" + tank_num, "command": "tank_motor_status", "value": params };
            } else {
                var data = { "tank_num": "C" + tank_num, "command": "tank_motor_status", "value": '0' };
            }
            $.post('/mqtt/{{tid}}', data, function (res) {
                console.log('data:', data)
                if (res == 'on') {
                    $("#cmn-toggle-08").prop('checked', true);
                } else if (res == 'off') {
                    $("#cmn-toggle-08").prop('checked', false);
                } else {
                };
            }, 'text')
        }

        // 桶內 中水入水電磁閥
        function tankSolenoidReclaimedIn(params) {
            if (params == '1') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_solenoid_reclaimed_in_status", "value": "on" };
            } else if (params == '0') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_solenoid_reclaimed_in_status", "value": "off" };
            } else {
                var status = "off";
                var check = $("input[name=tank_solenoid_reclaimed_in_status]:checked");
                //大於0代表有被選中 
                if (check.length > 0) {
                    status = "on";
                    $("#cmn-toggle-11").prop('checked', false);
                    if (!confirm("你確定要開啟中水入水電磁閥嗎?")) {
                        return false;
                    };
                } else {
                    $("#cmn-toggle-11").prop('checked', true);
                    if (!confirm("你確定要關閉中水入水電磁閥嗎?")) {
                        return false;
                    };
                };
                var data = { "tank_num": "C" + tank_num, "command": "tank_solenoid_reclaimed_in_status", "value": status };
            }
            $.post('/mqtt/{{tid}}', data, function (res) {
                console.log('data:', data)
                if (res == 'on') {
                    $("#cmn-toggle-11").prop('checked', true);
                } else if (res == 'off') {
                    $("#cmn-toggle-11").prop('checked', false);
                } else {
                };
            }, 'text')
        }

        // 桶內 清水入水電磁閥
        function tankSolenoidWaterIn(params) {
            if (params == '1') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_solenoid_water_in_status", "value": "on" };
            } else if (params == '0') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_solenoid_water_in_status", "value": "off" };
            } else {
                var status = "off";
                var check = $("input[name=tank_solenoid_water_in_status]:checked");
                //大於0代表有被選中 
                if (check.length > 0) {
                    status = "on";
                    $("#cmn-toggle-14").prop('checked', false);
                    if (!confirm("你確定要開啟清水入水電磁閥嗎?")) {
                        return false;
                    };
                } else {
                    $("#cmn-toggle-14").prop('checked', true);
                    if (!confirm("你確定要關閉清水入水電磁閥嗎?")) {
                        return false;
                    };
                };
                var data = { "tank_num": "C" + tank_num, "command": "tank_solenoid_water_in_status", "value": status };
            }
            $.post('/mqtt/{{tid}}', data, function (res) {
                console.log('data:', data)
                if (res == 'on') {
                    $("#cmn-toggle-14").prop('checked', true);
                } else if (res == 'off') {
                    $("#cmn-toggle-14").prop('checked', false);
                } else {
                };
            }, 'text')
        }

        // 桶內 幫浦 (清水入水)
        function tankPumpWaterIn(params) {
            if (params == '1') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_pump_water_in_status", "value": "on" };
            } else if (params == '0') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_pump_water_in_status", "value": "off" };
            } else {
                var status = "off";
                var check = $("input[name=tank_pump_water_in_status]:checked");
                //大於0代表有被選中 
                if (check.length > 0) {
                    status = "on";
                    $("#cmn-toggle-17").prop('checked', false);
                    if (!confirm("你確定要開啟清水入水幫浦嗎?")) {
                        return false;
                    };
                } else {
                    $("#cmn-toggle-17").prop('checked', true);
                    if (!confirm("你確定要關閉清水入水幫浦嗎?")) {
                        return false;
                    };
                };
                var data = { "tank_num": "C" + tank_num, "command": "tank_pump_water_in_status", "value": status };
            }
            $.post('/mqtt/{{tid}}', data, function (res) {
                console.log('data:', data)
                if (res == 'on') {
                    $("#cmn-toggle-17").prop('checked', true);
                } else if (res == 'off') {
                    $("#cmn-toggle-17").prop('checked', false);
                } else {
                };
            }, 'text')
        }

        // 桶內 排水廢水電磁閥
        function tankSolenoidWaterOut(params) {
            if (params == '1') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_solenoid_water_out_status", "value": "on" };
            } else if (params == '0') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_solenoid_water_out_status", "value": "off" };
            } else {
                var status = "off";
                var check = $("input[name=tank_solenoid_water_out_status]:checked");
                //大於0代表有被選中 
                if (check.length > 0) {
                    status = "on";
                    $("#cmn-toggle-20").prop('checked', false);
                    if (!confirm("你確定要開啟排水廢水電磁閥嗎?")) {
                        return false;
                    };
                } else {
                    $("#cmn-toggle-20").prop('checked', true);
                    if (!confirm("你確定要關閉排水廢水電磁閥嗎?")) {
                        return false;
                    };
                };

                var data = { "tank_num": "C" + tank_num, "command": "tank_solenoid_water_out_status", "value": status };
            }
            $.post('/mqtt/{{tid}}', data, function (res) {
                console.log('data:', data)
                if (res == 'on') {
                    $("#cmn-toggle-20").prop('checked', true);
                } else if (res == 'off') {
                    $("#cmn-toggle-20").prop('checked', false);
                } else {
                };
            }, 'text')
        }

        // 桶內 排水中水電磁閥
        function tankSolenoidReclaimedOut(params) {
            if (params == '1') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_solenoid_reclaimed_out_status", "value": "on" };
            } else if (params == '0') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_solenoid_reclaimed_out_status", "value": "off" };
            } else {
                var status = "off";
                var check = $("input[name=tank_solenoid_reclaimed_out_status]:checked");
                //大於0代表有被選中 
                if (check.length > 0) {
                    status = "on";
                    $("#cmn-toggle-23").prop('checked', false);
                    if (!confirm("你確定要開啟排水中水電磁閥嗎?")) {
                        return false;
                    };
                } else {
                    $("#cmn-toggle-23").prop('checked', true);
                    if (!confirm("你確定要關閉排水中水電磁閥嗎?")) {
                        return false;
                    };
                };

                var data = { "tank_num": "C" + tank_num, "command": "tank_solenoid_reclaimed_out_status", "value": status };
            }
            $.post('/mqtt/{{tid}}', data, function (res) {
                console.log('data:', data)
                if (res == 'on') {
                    $("#cmn-toggle-23").prop('checked', true);
                } else if (res == 'off') {
                    $("#cmn-toggle-23").prop('checked', false);
                } else {
                };
            }, 'text')
        }

        // 桶內 消毒電磁閥
        function tankSolenoidDisinfect(params) {
            if (params == '1') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_solenoid_disinfect_status", "value": "on" };
            } else if (params == '0') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_solenoid_disinfect_status", "value": "off" };
            } else {
                var status = "off";
                var check = $("input[name=tank_solenoid_disinfect_status]:checked");
                //大於0代表有被選中 
                if (check.length > 0) {
                    status = "on";
                    $("#cmn-toggle-26").prop('checked', false);
                    if (!confirm("你確定要開啟消毒電磁閥嗎?")) {
                        return false;
                    };
                } else {
                    $("#cmn-toggle-26").prop('checked', true);
                    if (!confirm("你確定要關閉消毒電磁閥嗎?")) {
                        return false;
                    };
                };
                var data = { "tank_num": "C" + tank_num, "command": "tank_solenoid_disinfect_status", "value": status };
            }
            $.post('/mqtt/{{tid}}', data, function (res) {
                console.log('data:', data)
                if (res == 'on') {
                    $("#cmn-toggle-26").prop('checked', true);
                } else if (res == 'off') {
                    $("#cmn-toggle-26").prop('checked', false);
                } else {
                };
            }, 'text')
        }

        // 桶內 混合槽幫浦
        function tankPumpDisinfect(params) {
            if (params == '1') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_pump_disinfect_status", "value": "on" };
            } else if (params == '0') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_pump_disinfect_status", "value": "off" };
            } else {
                var status = "off";
                var check = $("input[name=tank_pump_disinfect_status]:checked");
                //大於0代表有被選中 
                if (check.length > 0) {
                    status = "on";
                    $("#cmn-toggle-29").prop('checked', false);
                    if (!confirm("你確定要開啟混合槽幫浦嗎?")) {
                        return false;
                    };
                } else {
                    $("#cmn-toggle-29").prop('checked', true);
                    if (!confirm("你確定要關閉混合槽幫浦嗎?")) {
                        return false;
                    };
                };

                var data = { "tank_num": "C" + tank_num, "command": "tank_pump_disinfect_status", "value": status };
            }
            $.post('/mqtt/{{tid}}', data, function (res) {
                console.log('data:', data)
                if (res == 'on') {
                    $("#cmn-toggle-29").prop('checked', true);
                } else if (res == 'off') {
                    $("#cmn-toggle-29").prop('checked', false);
                } else {
                };
            }, 'text')
        }

        // 桶內 蝴蝶閥
        function tankDiskvalve(params) {
            if (params == '1') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_diskvalve_status", "value": "on" };
            } else if (params == '0') {
                var data = { "tank_num": "C" + tank_num, "command": "tank_diskvalve_status", "value": "off" };
            } else {
                var status = "off";
                var check = $("input[name=tank_diskvalve_status]:checked");
                //大於0代表有被選中 
                if (check.length > 0) {
                    status = "on";
                    $("#cmn-toggle-32").prop('checked', false);
                    if (!confirm("你確定要開啟蝴蝶閥嗎?")) {
                        return false;
                    };
                } else {
                    $("#cmn-toggle-32").prop('checked', true);
                    if (!confirm("你確定要關閉蝴蝶閥嗎?")) {
                        return false;
                    };
                };

                var data = { "tank_num": "C" + tank_num, "command": "tank_diskvalve_status", "value": status };
            }
            $.post('/mqtt/{{tid}}', data, function (res) {
                console.log('data:', data)
                if (res == 'on') {
                    $("#cmn-toggle-32").prop('checked', true);
                } else if (res == 'off') {
                    $("#cmn-toggle-32").prop('checked', false);
                } else {
                };
            }, 'text')
        }



    </script>

    <script language="JavaScript">
        function changeUpdate() {
            clearInterval(WebUpdate_set);

            var webupdate_time = $("input[name=webupdate_time]").val()
            console.log('webupdate_time' + webupdate_time)
            WebUpdate_set = setInterval(function(){WebUpdate(ctn)} , webupdate_time * 1000);
        }

        // jQuery 更新感測器致動器狀態
        function WebUpdate(ctn) {
            $.get('/loading/C' + ctn, '', function (res) {
                if (res.tank_vacuum == 0) {
                    $("#cmn-toggle-02").prop('checked', false);
                } else if (res.tank_vacuum == 1) {
                    $("#cmn-toggle-02").prop('checked', true);
                }

                if (res.tank_threewayvalve_input == 0) {
                    $("#cmn-toggle-05").prop('checked', false);
                } else if (res.tank_threewayvalve_input == 1) {
                    $("#cmn-toggle-05").prop('checked', true);
                }

                if (res.tank_solenoid_reclaimed_in == 0) {
                    $("#cmn-toggle-11").prop('checked', false);
                } else if (res.tank_solenoid_reclaimed_in == 1) {
                    $("#cmn-toggle-11").prop('checked', true);
                }

                if (res.tank_solenoid_water_in == 0) {
                    $("#cmn-toggle-14").prop('checked', false);
                } else if (res.tank_solenoid_water_in == 1) {
                    $("#cmn-toggle-14").prop('checked', true);
                }

                if (res.tank_pump_water_in == 0) {
                    $("#cmn-toggle-17").prop('checked', false);
                } else if (res.tank_pump_water_in == 1) {
                    $("#cmn-toggle-17").prop('checked', true);
                }

                if (res.tank_solenoid_water_out == 0) {
                    $("#cmn-toggle-20").prop('checked', false);
                } else if (res.tank_solenoid_water_out == 1) {
                    $("#cmn-toggle-20").prop('checked', true);
                }

                if (res.tank_solenoid_reclaimed_out == 0) {
                    $("#cmn-toggle-23").prop('checked', false);
                } else if (res.tank_solenoid_reclaimed_out == 1) {
                    $("#cmn-toggle-23").prop('checked', true);
                }

                if (res.tank_solenoid_disinfect == 0) {
                    $("#cmn-toggle-26").prop('checked', false);
                } else if (res.tank_solenoid_disinfect == 1) {
                    $("#cmn-toggle-26").prop('checked', true);
                }

                if (res.tank_pump_disinfect == 0) {
                    $("#cmn-toggle-29").prop('checked', false);
                } else if (res.tank_pump_disinfect == 1) {
                    $("#cmn-toggle-29").prop('checked', true);
                }

                if (res.tank_diskvalve == 0) {
                    $("#cmn-toggle-32").prop('checked', false);
                } else if (res.tank_diskvalve == 1) {
                    $("#cmn-toggle-32").prop('checked', true);
                }

                $("#motor_rpm_data").attr("placeholder", res.tank_motor);
                $("#UltraSonic_t_status").text(res.UltraSonic);
                $("#MotorEncoder_t_status").text(res.Encoder);
                $("#tankTurbidity_t_status").text(res.tankTurbidity);
                $("#filterTurbidity_t_status").text(res.filterTurbidity);

                // setTimeout(function(){WebUpdate(ctn)}, 10 * 1000);

            }, 'json');

            
        }
    </script>
</head>

<body>
    <div id="wrapper">
        <div id="coffee_header">
            <!-- 匯入共同使用的 header.html 內容 -->
            {% include 'header.html' %}
        </div>
    
        <h4>致動器</h4>
        <table border="1" class="table-all" cellpadding="3" style="text-align: center;">
            <tr>
                <td style="color:red;">Valve</td>
                <td>真空吸料機</td>
                <td>吸料機<br>三通閥</td>
                <td>馬達</td>
                <td>中水入水<br>電磁閥</td>
                <td>清水入水<br>電磁閥</td>
                <td>幫浦<br>(清水入水)</td>
                <td>排水廢水<br>電磁閥</td>
                <td>排水中水<br>電磁閥</td>
                <td>消毒<br>電磁閥</td>
                <td>混合槽<br>幫浦</td>
                <td>蝴蝶閥</td>
            </tr>
            <tr>
                <td>
                    <span style="color:#C0C0C0;">off</span>
                    <span style="color:#008CBA;">on</span>
                </td>
                <td>
                    <div class="switch_div">
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round" id="cmn-toggle-01">
                        </div>
                        <div class="text-center">
                            {% if tank_vacuum == 1 %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-02" checked
                                name="tank_vacuum_status" value="ON" onclick="tankVacuum()">
                            {% else %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-02"
                                name="tank_vacuum_status" value="OFF" onclick="tankVacuum()">
                            {% endif %}
                            <label class="label_ActuatorStatus" for="cmn-toggle-02"></label>
                        </div>
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-yes-no" id="cmn-toggle-03">
                        </div>
                    </div>
                </td>
                <td>
                    <div class="switch_div">
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round" id="cmn-toggle-04">
                        </div>
                        <div class="text-center">
                            {% if tank_threewayvalve_input == 1 %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-05" checked
                                name="tank_threewayvalve_input_status" value="ON" onclick="tankThreeWayValveInput()">
                            {% else %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-05"
                                name="tank_threewayvalve_input_status" value="OFF" onclick="tankThreeWayValveInput()">
                            {% endif %}
                            <label class="label_ActuatorStatus" for="cmn-toggle-05"></label>
                        </div>
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-yes-no" id="cmn-toggle-06">
                        </div>
                    </div>
                </td>
                <td>
                    <input type="text" class="input-text" id="motor_rpm_data" placeholder="{{tank_motor}}" value="">RPM
                    <br>
                    <span id="motor_rpm_status" style="color:red;"></span>
                    <input type="button" class="input-button" value="Confirm" name="tank_motor_status" onclick="tankMotor_set()">
                </td>
                <td>
                    <div class="switch_div">
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round" id="cmn-toggle-10">
                        </div>
                        <div class="text-center">
                            {% if tank_solenoid_reclaimed_in == 1 %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-11" checked
                                name="tank_solenoid_reclaimed_in_status" value="ON" onclick="tankSolenoidReclaimedIn()">
                            {% else %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-11"
                                name="tank_solenoid_reclaimed_in_status" value="OFF" onclick="tankSolenoidReclaimedIn()">
                            {% endif %}
                            <label class="label_ActuatorStatus" for="cmn-toggle-11"></label>
                        </div>
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-yes-no" id="cmn-toggle-12">
                        </div>
                    </div>
                </td>
                <td>
                    <div class="switch_div">
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round" id="cmn-toggle-13">
                        </div>
                        <div class="text-center">
                            {% if tank_solenoid_water_in == 1 %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-14" checked
                                name="tank_solenoid_water_in_status" value="ON" onclick="tankSolenoidWaterIn()">
                            {% else %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-14"
                                name="tank_solenoid_water_in_status" value="OFF" onclick="tankSolenoidWaterIn()">
                            {% endif %}
                            <label class="label_ActuatorStatus" for="cmn-toggle-14"></label>
                        </div>
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-yes-no" id="cmn-toggle-15">
                        </div>
                    </div>
                </td>
                <td>
                    <div class="switch_div">
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round" id="cmn-toggle-16">
                        </div>
                        <div class="text-center">
                            {% if tank_pump_water_in == 1 %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-17" checked
                                name="tank_pump_water_in_status" value="ON" onclick="tankPumpWaterIn()">
                            {% else %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-17"
                                name="tank_pump_water_in_status" value="OFF" onclick="tankPumpWaterIn()">
                            {% endif %}
                            <label class="label_ActuatorStatus" for="cmn-toggle-17"></label>
                        </div>
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-yes-no" id="cmn-toggle-18">
                        </div>
                    </div>
                </td>
                <td>
                    <div class="switch_div">
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round" id="cmn-toggle-19">
                        </div>
                        <div class="text-center">
                            {% if tank_solenoid_water_out == 1 %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-20" checked
                                name="tank_solenoid_water_out_status" value="ON" onclick="tankSolenoidWaterOut()">
                            {% else %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-20"
                                name="tank_solenoid_water_out_status" value="OFF" onclick="tankSolenoidWaterOut()">
                            {% endif %}
                            <label class="label_ActuatorStatus" for="cmn-toggle-20"></label>
                        </div>
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-yes-no" id="cmn-toggle-21">
                        </div>
                    </div>
                </td>
                <td>
                    <div class="switch_div">
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round" id="cmn-toggle-22">
                        </div>
                        <div class="text-center">
                            {% if tank_solenoid_reclaimed_out == 1 %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-23" checked
                                name="tank_solenoid_reclaimed_out_status" value="ON" onclick="tankSolenoidReclaimedOut()">
                            {% else %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-23"
                                name="tank_solenoid_reclaimed_out_status" value="OFF" onclick="tankSolenoidReclaimedOut()">
                            {% endif %}
                            <label class="label_ActuatorStatus" for="cmn-toggle-23"></label>
                        </div>
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-yes-no" id="cmn-toggle-24">
                        </div>
                    </div>
                </td>
                <td>
                    <div class="switch_div">
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round" id="cmn-toggle-25">
                        </div>
                        <div class="text-center">
                            {% if tank_solenoid_disinfect == 1 %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-26" checked
                                name="tank_solenoid_disinfect_status" value="ON" onclick="tankSolenoidDisinfect()">
                            {% else %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-26"
                                name="tank_solenoid_disinfect_status" value="OFF" onclick="tankSolenoidDisinfect()">
                            {% endif %}
                            <label class="label_ActuatorStatus" for="cmn-toggle-26"></label>
                        </div>
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-yes-no" id="cmn-toggle-27">
                        </div>
                    </div>
                </td>
                <td>
                    <div class="switch_div">
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round" id="cmn-toggle-28">
                        </div>
                        <div class="text-center">
                            {% if tank_pump_disinfect == 1 %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-29" checked
                                name="tank_pump_disinfect_status" value="ON" onclick="tankPumpDisinfect()">
                            {% else %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-29"
                                name="tank_pump_disinfect_status" value="OFF" onclick="tankPumpDisinfect()">
                            {% endif %}
                            <label class="label_ActuatorStatus" for="cmn-toggle-29"></label>
                        </div>
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-yes-no" id="cmn-toggle-30">
                        </div>
                    </div>
                </td>
                <td>
                    <div class="switch_div">
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round" id="cmn-toggle-31">
                        </div>
                        <div class="text-center">
                            {% if tank_diskvalve == 1 %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-32" checked
                                name="tank_diskvalve_status" value="ON" onclick="tankDiskvalve()">
                            {% else %}
                            <input type="checkbox" class="cmn-toggle cmn-toggle-round-flat" id="cmn-toggle-32"
                                name="tank_diskvalve_status" value="OFF" onclick="tankDiskvalve()">
                            {% endif %}
                            <label class="label_ActuatorStatus" for="cmn-toggle-32"></label>
                        </div>
                        <div>
                            <input type="checkbox" class="cmn-toggle cmn-toggle-yes-no" id="cmn-toggle-33">
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td><span style="color:#008CBA;"><b>ON</b></span></td>
                <td><input type="button" class="input-button-on" value="ON" onclick="tankVacuum('1')"></td>
                <td><input type="button" class="input-button-on" value="ON" onclick="tankThreeWayValveInput('1')"></td>
                <td><input type="button" class="input-button-on" value="20" onclick="tankMotor('20')"></td>
                <td><input type="button" class="input-button-on" value="ON" onclick="tankSolenoidReclaimedIn('1')"></td>
                <td><input type="button" class="input-button-on" value="ON" onclick="tankSolenoidWaterIn('1')"></td>
                <td><input type="button" class="input-button-on" value="ON" onclick="tankPumpWaterIn('1')"></td>
                <td><input type="button" class="input-button-on" value="ON" onclick="tankSolenoidWaterOut('1')"></td>
                <td><input type="button" class="input-button-on" value="ON" onclick="tankSolenoidReclaimedOut('1')"></td>
                <td><input type="button" class="input-button-on" value="ON" onclick="tankSolenoidDisinfect('1')"></td>
                <td><input type="button" class="input-button-on" value="ON" onclick="tankPumpDisinfect('1')"></td>
                <td><input type="button" class="input-button-on" value="ON" onclick="tankDiskvalve('1')"></td>
            </tr>
            <tr>
                <td><span style="color:#C0C0C0;"><b>OFF</b></span></td>
                <td><input type="button" class="input-button-off" value="OFF" onclick="tankVacuum('0')"></td>
                <td><input type="button" class="input-button-off" value="OFF" onclick="tankThreeWayValveInput('0')"></td>
                <td><input type="button" class="input-button-off" value="0" onclick="tankMotor('0')"></td>
                <td><input type="button" class="input-button-off" value="OFF" onclick="tankSolenoidReclaimedIn('0')"></td>
                <td><input type="button" class="input-button-off" value="OFF" onclick="tankSolenoidWaterIn('0')"></td>
                <td><input type="button" class="input-button-off" value="OFF" onclick="tankPumpWaterIn('0')"></td>
                <td><input type="button" class="input-button-off" value="OFF" onclick="tankSolenoidWaterOut('0')"></td>
                <td><input type="button" class="input-button-off" value="OFF" onclick="tankSolenoidReclaimedOut('0')"></td>
                <td><input type="button" class="input-button-off" value="OFF" onclick="tankSolenoidDisinfect('0')"></td>
                <td><input type="button" class="input-button-off" value="OFF" onclick="tankPumpDisinfect('0')"></td>
                <td><input type="button" class="input-button-off" value="OFF" onclick="tankDiskvalve('0')"></td>
            </tr>
        </table>

        <br>

        <h4>感測器</h4>
        <table border="1" class="table-all" cellpadding="5">
            <tr>
                <td style="background-color:#f3f3f3">生豆高度</td>
                <td><span id="UltraSonic_t_status">{{tank_UltraSonic.UltraSonic}}</span> 公分</td>
                <td style="background-color:#f3f3f3">桶內濁度計</td>
                <td><span id="tankTurbidity_t_status">{{tank_Turbidity.tankTurbidity}}</span> NTU</td>
            </tr>
            <tr>
                <td style="background-color:#f3f3f3">馬達編碼器</td>
                <td><span id="MotorEncoder_t_status">{{tank_Encoder.Encoder}}</span> RPM</td>
                <td style="background-color:#f3f3f3">過濾器濁度計</td>
                <td><span id="filterTurbidity_t_status">{{filter_Turbidity.filterTurbidity}}</span> NYU</td>
            </tr>
        </table>

        <br>

        <h4>排程測試</h4>
        <table border="1" class="table-all" cellpadding="5">
            <tr>
                <td>排氣下豆測試</td>
            </tr>
            <tr>
                <td>
                    吸料
                    <input type="text" class="input-text" name="waiting_time_8" value="5">
                    秒                
                    <br>
                    放料
                    <input type="text" class="input-text" name="waiting_time_9" value="10">
                    秒
                    <br>
                    循環
                    <input type="text" class="input-text" name="waiting_loop_3" value="4">
                    次
                </td>
            </tr>
            <tr>
                <td>
                    <button type="submit" class="btn btn-primary" onclick="tank_BeanInputAir_testing()">排氣下豆測試</button>
                    <script>
                        function tank_BeanInputAir_testing() {
                            // 循環次數
                            var loop3 = $("input[name=waiting_loop_3]").val();
                            console.log('--- 循環 ' + loop3 + ' 次 ---')

                            for (step = 1; step <= loop3; step++) {
                                // 真空吸料機 ON
                                tankVacuum_ON()
                                console.log('tankVacuum_ON')

                                // 吸料時間 
                                var time8 = $("input[name=waiting_time_8]").val();
                                console.log('等待 ' + time8 + ' 秒')
                                var time = new Date();
                                while ((new Date() - time) < time8 * 1000) { };

                                // 真空吸料機 OFF
                                tankVacuum_OFF()
                                console.log('tankVacuum_OFF')

                                // 吸料時間
                                var time9 = $("input[name=waiting_time_9]").val();
                                console.log('等待 ' + time9 + ' 秒')
                                var time = new Date();
                                while ((new Date() - time) < time9 * 1000) { };
                            }                        
                        }
                    </script>
                </td>
            </tr>
        </table>

        <div id="coffee_footer">
            <!-- 匯入共同使用的 footer.html 內容 -->
            {% include 'footer.html' %}
        </div>
    </div>

</body>

</html>