<!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="10" />每 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>
    <!--
    <script src="../static/js/sign_in.js"></script>
    <link rel="stylesheet" href="../static/css/sign_in.css">
    -->
    <!-- Rita 發酵貨櫃 - 入料、桶槽、出料致動器 function-->
    <script type="text/javascript" src="../static/js/ferment_function.js"></script>

    <script>
        var tank_num = '1';
        $(document).ready(function(){
            $("#coffee_title").text('發酵自動化');

            // 脫皮出料顯示
            console.log('PO1: ' + '{{PO1}}')
            peel_output_status = ['{{PO1}}']
            for (let i=0; i<peel_output_status.length; i++) {
                if (peel_output_status[i] == 'PO_InputtingBean') {
                    console.log('[動作] 脫皮出料 PO' + parseInt(i+1) + ' 入豆中')
                    $("#PO"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#PO"+parseInt(i+1)+"_status").text("PO" + parseInt(i+1) + " 入豆中")
                    
                } else if (peel_output_status[i] == 'PO_Waiting') {
                    console.log('[動作] 脫皮出料 PO' + parseInt(i+1) + ' 空桶等待')
                    $("#PO"+parseInt(i+1)+"_status_dot").css("background-color", "lightgray")
                    $("#PO"+parseInt(i+1)+"_status").text("PO" + parseInt(i+1) + " 空桶等待")

                } else if (peel_output_status[i] == 'PO_OutputtingBean') {
                    console.log('[動作] 脫皮出料 PO' + parseInt(i+1) + ' 可出豆')
                    $("#PO"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#PO"+parseInt(i+1)+"_status").text("PO" + parseInt(i+1) + " 可出豆")

                } else {
                    console.log('pass')
                }
            }

            // 桶槽入料顯示
            ferment_input_status_N = ['{{FI1}}', '{{FI2}}']
            // console.log('ferment_input_status_N: ' + ferment_input_status_N)
            for (let i=0; i<ferment_input_status_N.length; i++) {
                // 顯示對應發酵桶槽號碼 F1~F6 和目前狀態
                // console.log(i+1 + ' : '+ ferment_output_status[i])
                // 1 : F_InputtingBean
                // 2 : F_Waiting
                if (ferment_input_status_N[i] == 'FI_InputtingBean') {
                    $("#FI"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#FI"+parseInt(i+1)+"_status").text("FI" + parseInt(i+1) + " 入豆中")
                } else if (ferment_input_status_N[i] == 'FI_Waiting') {
                    $("#FI"+parseInt(i+1)+"_status_dot").css("background-color", "lightgray")
                    $("#FI"+parseInt(i+1)+"_status").text("FI" + parseInt(i+1) + " 空桶等待")
                } else if (ferment_input_status_N[i] == 'FI_OutputtingBean') {
                    $("#FI"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#FI"+parseInt(i+1)+"_status").text("FI" + parseInt(i+1) + " 可出豆")
                } else {
                    console.log('pass')
                }
            }

            // 桶槽狀態顯示
            ferment_tank_status_N = ['{{F1}}', '{{F2}}', '{{F3}}', '{{F4}}', '{{F5}}', '{{F6}}', 
                                    '{{F7}}', '{{F8}}', '{{F9}}', '{{F10}}', '{{F11}}', '{{F12}}']
            // console.log('ferment_tank_status_N: ' + ferment_tank_status_N)
            for (let i=0; i<ferment_tank_status_N.length; i++) {
                // 顯示對應發酵桶槽號碼 F1~F6 和目前狀態
                // console.log(i+1 + ' : '+ ferment_tank_status[i])
                // 1 : F_InputtingBean
                // 2 : F_Waiting
                if (ferment_tank_status_N[i] == 'F_InputtingBean') {
                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  入豆中")
                } else if (ferment_tank_status_N[i] == 'F_InputtingBean_Pause') {
                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  入豆暫停")
                } else if (ferment_tank_status_N[i] == 'F_InputtingBean_Finish') {
                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  入豆完成")
                } else if (ferment_tank_status_N[i] == 'F_InputtingWater') {
                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  入水中")
                } else if (ferment_tank_status_N[i] == 'F_Waiting') {
                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "lightgray")
                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  空桶等待")
                } else if (ferment_tank_status_N[i] == 'F_Cleaning') {
                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "plum")
                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  清洗中")
                } else if (ferment_tank_status_N[i] == 'F_Fermenting') {
                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  發酵中")
                } else if (ferment_tank_status_N[i] == 'F_OutputtingBean') {
                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  可出豆")
                } else if (ferment_tank_status_N[i] == 'F_Warning') {
                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "crimson")
                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  發生錯誤")
                    $("#F"+parseInt(i+1)+"_status").css("color", "crimson")
                } else {
                    console.log('pass')
                }
            }
            
            // 桶槽出料顯示
            ferment_output_status_N = ['{{FO1}}', '{{FO2}}']
            // console.log('ferment_output_status_N: ' + ferment_output_status_N)
            for (let i=0; i<ferment_output_status_N.length; i++) {
                // 顯示對應發酵桶槽號碼 F1~F6 和目前狀態
                // console.log(i+1 + ' : '+ ferment_output_status[i])
                // 1 : F_InputtingBean
                // 2 : F_Waiting
                if (ferment_output_status_N[i] == 'FO_InputtingBean') {
                    $("#FO"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#FO"+parseInt(i+1)+"_status").text("FO" + parseInt(i+1) + " 入豆中")
                    
                } else if (ferment_output_status_N[i] == 'FO_Waiting') {
                    $("#FO"+parseInt(i+1)+"_status_dot").css("background-color", "lightgray")
                    $("#FO"+parseInt(i+1)+"_status").text("FO" + parseInt(i+1) + " 空桶等待")

                } else if (ferment_output_status_N[i] == 'FO_OutputtingBean') {
                    $("#FO"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#FO"+parseInt(i+1)+"_status").text("FO" + parseInt(i+1) + " 可出豆")

                } else {
                    console.log('pass')
                }

            }

            
            loading_F()
            // css 
            // height: 185px; 取代成 height: 210px;
            // FI2 FO2  top: 620px; 取代成 top: 645px;
        });
        $(function(){
            $('#cb_cleaning').on('change', function () {
                if ($('#cb_cleaning').prop('checked')) {
                    $("input[name='Ferment_auto_cleaning_Ftimes']").attr('disabled', false);
                    $("input[name='Ferment_auto_cleaning_Ftimes']").attr('value', '1');
                } else {
                    $("input[name='Ferment_auto_cleaning_Ftimes']").attr('disabled', true);
                }
            })
            $('#cb_calibratingEC').on('change', function () {
                if ($('#cb_calibratingEC').prop('checked')) {
                    $("input[name='Ferment_auto_calibratingEC_Ftimes']").attr('disabled', false);
                    $("input[name='Ferment_auto_calibratingEC_Ftimes']").attr('value', '1');
                } else {
                    $("input[name='Ferment_auto_calibratingEC_Ftimes']").attr('disabled', true);
                }
            })
            $('#cb_calibratingSTIR').on('change', function () {
                if ($('#cb_calibratingSTIR').prop('checked')) {
                    $("input[name='Ferment_auto_calibratingSTIR_Ftimes']").attr('disabled', false);
                    $("input[name='Ferment_auto_calibratingSTIR_Ftimes']").attr('value', '1');
                } else {
                    $("input[name='Ferment_auto_calibratingSTIR_Ftimes']").attr('disabled', true);
                }
            })
            

            // <label><input type="checkbox" id="cb_cleaning">清洗：發酵
            //     <input name="Ferment_auto_cleaning_Ftimes" class="input-text" type="text">次執行
            // </label><br>

            // <label><input type="checkbox" id="cb_calibratingEC">校正 EC
            //     <input name="Ferment_auto_calibratingEC_Ftimes" class="input-text" type="text">次執行
            // </label><br>

            // <label><input type="checkbox" id="cb_calibratingSTIR">校正攪拌棒
            //     <input name="Ferment_auto_calibratingSTIR_Ftimes" class="input-text" type="text">次執行
            // </label>
        })

        function loading_F(){
            $.get('/loading/FI1', '', function (res) {
                $("#actuator_00").text(res.input_vacuum);
                $("#sensor_00").text(res.input_UltraSonic);
            }, 'json');

            $.get('/loading/FO1', '', function (res) {
                $("#actuator_99").text(res.output_vacuum);
                $("#sensor_99").text(res.output_UltraSonic);
            }, 'json');


            $.get('/loading/F1', '', function (res) {
                $("#actuator_1").text(res.tank_vacuum);
                $("#actuator_2").text(res.tank_threewayvalve_input);
                $("#actuator_3").text(res.tank_diskvalve);
                $("#actuator_4").text(res.solenoid_tank_pump);
                $("#actuator_5").text(res.tank_solenoid_disinfect);
                $("#actuator_6").text(res.outer_solenoid_water);
                $("#actuator_7").text(res.tank_solenoid_water_in);
                $("#actuator_8").text(res.tank_solenoid_water_out);
                $("#actuator_9").text(res.tank_pump_sensor);
                $("#actuator_10").text(res.outer_threewayvalve_float);
                $("#actuator_11").text(res.tank_motor);
                $("#actuator_12").text(res.tank_heater1);
                $("#actuator_13").text(res.tank_heater2);
                $("#actuator_14").text(res.tank_temp_enable);
                $("#actuator_15").text(res.tank_temp);
                $("#sensor_1").text(res.UltraSonic);
                $("#sensor_2").text(res.SHT11_Temp);
                $("#sensor_3").text(res.SHT11_Humidity);
                $("#sensor_4").text(res.CO2);
                $("#sensor_5").text(res.PA);
                $("#sensor_6").text(res.PH);
                $("#sensor_7").text(res.ORP);
                $("#sensor_8").text(res.DO);
                $("#sensor_9").text(res.EC);
                $("#sensor_10").text(res.WaterLevel);               
            }, 'json');
        }
    </script>
    
    <style>
        .F_status_css {
            font-weight: bold;
            text-align: center;
        }
        .FermentContainer_position {
            position: absolute;
            top: 95px;
            left: 53px;
        }
        .F1_position {
            width: 110px; 
        }
        .F2_position {
            width: 110px; 
        }
        .F3_position {
            width: 110px; 
        }
        .F4_position {
            width: 110px; 
        }
        .F5_position {
            width: 110px; 
        }
        .F6_position {
            width: 110px; 
        }
        .F7_position {
            width: 110px; 
        }
        .F8_position {
            width: 110px; 
        }
        .F9_position {
            width: 110px; 
        }
        .F10_position {
            width: 110px; 
        }
        .F11_position {
            width: 110px; 
        }
        .F12_position {
            width: 110px; 
        }

        .FI1_position {
            width: 110px; 
        }

        .FI2_position {
            width: 110px; 
        }
        
        .FO1_position {
            width: 110px; 
        }
        
        .FO2_position {
            width: 110px; 
        }
        .footer{
            position: absolute;
            bottom: 0px;
            width: 100%;
            background-color: #eee;
            text-align: center;
        }
        .input-text {
            height: 25px;
            width: 40px;
            text-align: center;
            margin-left: 2px;
            margin-right: 5px;
        }
    </style>
    <script language="JavaScript">
        // 指定 10秒 刷新網頁一次
        var WebUpdate_set
        // WebUpdate_set = setInterval(function(){WebUpdate()} , 60 * 1000)

        function WebUpdate(){
            console.log("-- 狀態更新 start --")
            /*
            $.get('/loading_container_status/F', '', function (res) {
            }, 'json');
            */
            console.log("-- 狀態更新 end --")
        };
    </script>

</head>

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

        <div>

            

            <!-- 發酵貨櫃 測試按鈕-->
            <div style="text-align: center;">
                <button style="margin: 5px 10px 0px 10px;" type="submit" class="btn btn-primary" onclick="ferment_auto_status_stop()">
                    <u>狀態判斷_停止</u></button>

                <button style="margin: 5px 10px 0px 10px;" type="submit" class="btn btn-primary" onclick="ferment_auto_status_testing()">
                    <u>[測試] 發酵自動化_狀態判斷</u></button>
                <script>
                    var ferment_status_interval  // 每 5 秒更新桶槽狀態、致動器狀態、感測器數值, 放全域
                    var loadingF
                    var ferment_status_process = 0;
    
                    function ferment_auto_status_testing(){
                        console.log("------- 狀態判斷 開始 -------")
                        loadingF = setInterval(loading_F, 10*1000)
                        var Ferment_Input_bean_height = $("input[name=Ferment_Input_bean_height]").val();
                        var Ferment_Input_vacuumON_time = $("input[name=Ferment_Input_vacuumON_time]").val();
                        var Ferment_Input_vacuumOFF_time = $("input[name=Ferment_Input_vacuumOFF_time]").val();
                        var Ferment_Tank_bean_height = $("input[name=Ferment_Tank_bean_height]").val();
                        var Ferment_Tank_vacuumON_time = $("input[name=Ferment_Tank_vacuumON_time]").val();
                        var Ferment_Tank_vacuumOFF_time = $("input[name=Ferment_Tank_vacuumOFF_time]").val();
                        var Ferment_Tank_water_height = $("input[name=Ferment_Tank_water_height]").val();
                        var Ferment_Tank_fermenting_temp = $("input[name=Ferment_Tank_fermenting_temp]").val();
                        var Ferment_Tank_fermenting_time = $("input[name=Ferment_Tank_fermenting_time]").val();
                        var Ferment_Tank_fermenting_pH = $("input[name=Ferment_Tank_fermenting_pH]").val();
                        var Ferment_Tank_fermenting_DO = $("input[name=Ferment_Tank_fermenting_DO]").val();
                        var Ferment_Tank_fermenting_ORP = $("input[name=Ferment_Tank_fermenting_ORP]").val();
                        var Ferment_Tank_fermenting_EC = $("input[name=Ferment_Tank_fermenting_EC]").val();
                        var Ferment_Tank_motor_rpm = $("input[name=Ferment_Tank_motor_rpm]").val();
                        var Ferment_Tank_motor_time = $("input[name=Ferment_Tank_motor_time]").val();
                        var Ferment_Tank_WaterOut_time = $("input[name=Ferment_Tank_WaterOut_time]").val();
                        var Ferment_Tank_Disinfect_time = $("input[name=Ferment_Tank_Disinfect_time]").val();
                        var Ferment_Output_bean_height = $("input[name=Ferment_Output_bean_height]").val();
                        var Ferment_Output_vacuumON_time = $("input[name=Ferment_Output_vacuumON_time]").val();
                        var Ferment_Output_vacuumOFF_time = $("input[name=Ferment_Output_vacuumOFF_time]").val();
                        
                        var FermentAuto_fermenting = $('#cb_fermenting').prop('checked') // true false
                        var FermentAuto_cleaning = $('#cb_cleaning').prop('checked')
                        var FermentAuto_calibratingEC = $('#cb_calibratingEC').prop('checked')
                        var FermentAuto_calibratingSTIR = $('#cb_calibratingSTIR').prop('checked')
                        var Ferment_auto_cleaning_Ftimes = $("input[name=Ferment_auto_cleaning_Ftimes]").val();
                        var Ferment_auto_calibratingEC_Ftimes = $("input[name=Ferment_auto_calibratingEC_Ftimes]").val();
                        var Ferment_auto_calibratingSTIR_Ftimes = $("input[name=Ferment_auto_calibratingSTIR_Ftimes]").val();
                        var Ferment_cb_vacuum = $('#Ferment_cb_vacuum').prop('checked') // true false
                        var Ferment_cb_vacuum_time = $("input[name=Ferment_cb_vacuum_time]").val();
    
                        if ( (!(/(^[1-9]\d*$)/.test(Ferment_auto_cleaning_Ftimes)) && FermentAuto_cleaning) ||
                                    (!(/(^[1-9]\d*$)/.test(Ferment_auto_calibratingEC_Ftimes)) && FermentAuto_calibratingEC) ||
                                    (!(/(^[1-9]\d*$)/.test(Ferment_auto_calibratingSTIR_Ftimes)) && FermentAuto_calibratingSTIR) ) {
                            alert('[發酵貨櫃] 次數只接受正整數, 請重新輸入')
                            return
                        } else {
                            // 若發酵排程被勾選則為 1, 否則為 0 (預設發酵排程會不斷執行)
                            if (FermentAuto_fermenting == true) { FermentAuto_fermenting = 1
                            } else { FermentAuto_fermenting = 0 }
                            // 若清洗排程被勾選則取得輸入框次數, 否則為 0 (勾選預設為 1)
                            if (FermentAuto_cleaning == true) { FermentAuto_cleaning = Ferment_auto_cleaning_Ftimes
                            } else { FermentAuto_cleaning = 0 }
                            // 若校正 EC 排程被勾選則取得輸入框次數, 否則為 0 (勾選預設為 1)
                            if (FermentAuto_calibratingEC == true) { FermentAuto_calibratingEC = Ferment_auto_calibratingEC_Ftimes
                            } else { FermentAuto_calibratingEC = 0 }
                            // 若校正攪拌棒排程被勾選則取得輸入框次數, 否則為 0 (勾選預設為 1)
                            if (FermentAuto_calibratingSTIR == true) { FermentAuto_calibratingSTIR = Ferment_auto_calibratingSTIR_Ftimes
                            } else { FermentAuto_calibratingSTIR = 0 }
                        }
                        
                        var data = { 'command': 'Ferment_auto_parameter', 
                                     'FermentAuto_fermenting': FermentAuto_fermenting, 
                                     'FermentAuto_cleaning': FermentAuto_cleaning, 
                                     'FermentAuto_calibratingEC': FermentAuto_calibratingEC, 
                                     'FermentAuto_calibratingSTIR': FermentAuto_calibratingSTIR, 
                                     'Ferment_cb_vacuum': Ferment_cb_vacuum,
                                     'Ferment_cb_vacuum_time': Ferment_cb_vacuum_time,
                                     'Ferment_Tank_fermenting_pH': Ferment_Tank_fermenting_pH,
                                     'Ferment_Input_bean_height':Ferment_Input_bean_height,
                                     'Ferment_Input_vacuumON_time': Ferment_Input_vacuumON_time, 
                                     'Ferment_Input_vacuumOFF_time': Ferment_Input_vacuumOFF_time, 
                                     'Ferment_Tank_bean_height': Ferment_Tank_bean_height, 
                                     'Ferment_Tank_vacuumON_time': Ferment_Tank_vacuumON_time, 
                                     'Ferment_Tank_vacuumOFF_time': Ferment_Tank_vacuumOFF_time, 
                                     'Ferment_Tank_water_height': Ferment_Tank_water_height, 
                                     'Ferment_Tank_fermenting_temp': Ferment_Tank_fermenting_temp, 
                                     'Ferment_Tank_fermenting_time': Ferment_Tank_fermenting_time, 
                                     'Ferment_Tank_fermenting_pH': Ferment_Tank_fermenting_pH, 
                                     'Ferment_Tank_fermenting_DO': Ferment_Tank_fermenting_DO, 
                                     'Ferment_Tank_fermenting_ORP': Ferment_Tank_fermenting_ORP, 
                                     'Ferment_Tank_fermenting_EC': Ferment_Tank_fermenting_EC, 
                                     'Ferment_Tank_motor_rpm': Ferment_Tank_motor_rpm, 
                                     'Ferment_Tank_motor_time': Ferment_Tank_motor_time,
                                     'Ferment_Tank_WaterOut_time': Ferment_Tank_WaterOut_time,
                                     'Ferment_Tank_Disinfect_time': Ferment_Tank_Disinfect_time,
                                     'Ferment_Output_bean_height': Ferment_Output_bean_height,
                                     'Ferment_Output_vacuumON_time': Ferment_Output_vacuumON_time, 
                                     'Ferment_Output_vacuumOFF_time': Ferment_Output_vacuumOFF_time };
    
                        ferment_status_interval = setInterval(ferment_auto_status, 5*1000);
    
                        function ferment_auto_status(){
                            if (ferment_status_process == 1) { return };
    
                            ferment_status_process = 1;
                            $.get('/ferment_auto_status', data, function (res) {
                                FI1 = res.Ferment_Input_1
                                F1 = res.Ferment_Tank_1
                                F2 = res.Ferment_Tank_2
                                F3 = res.Ferment_Tank_3
                                F4 = res.Ferment_Tank_4
                                F5 = res.Ferment_Tank_5
                                F6 = res.Ferment_Tank_6
                                FO1 = res.Ferment_Output_1
                                console.log('FI1: ' + FI1)
                                console.log('F1: ' + F1)
                                console.log('F2: ' + F2)
                                console.log('F3: ' + F3)
                                console.log('F4: ' + F4)
                                console.log('F5: ' + F5)
                                console.log('F6: ' + F6)
                                console.log('FO1: ' + FO1)
    
                                // ----- 脫皮出料 PO1 狀態 --------------------------------------------------------------
                                peel_output_status = [res.Peel_Output_1]
                                for (let i=0; i<peel_output_status.length; i++) {
                                    if (peel_output_status[i] == 'PO_InputtingBean') {
                                        console.log('[動作] 脫皮出料 PO' + parseInt(i+1) + ' 入豆中')
                                        $("#PO"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                        $("#PO"+parseInt(i+1)+"_status").text("PO" + parseInt(i+1) + " 入豆中")
                                        
                                    } else if (peel_output_status[i] == 'PO_Waiting') {
                                        console.log('[動作] 脫皮出料 PO' + parseInt(i+1) + ' 空桶等待')
                                        $("#PO"+parseInt(i+1)+"_status_dot").css("background-color", "lightgray")
                                        $("#PO"+parseInt(i+1)+"_status").text("PO" + parseInt(i+1) + " 空桶等待")
    
                                    } else if (peel_output_status[i] == 'PO_OutputtingBean') {
                                        console.log('[動作] 脫皮出料 PO' + parseInt(i+1) + ' 可出豆')
                                        $("#PO"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                        $("#PO"+parseInt(i+1)+"_status").text("PO" + parseInt(i+1) + " 可出豆")
    
                                    } else {
                                        console.log('PO pass')
                                    }
                                }
                                
                                // ----- 發酵出料 FO1 狀態 --------------------------------------------------------------
                                ferment_input_status = [res.Ferment_Input_1]
                                for (let i=0; i<ferment_input_status.length; i++) {
                                    // 顯示對應發酵桶槽號碼 F1~F6 和目前狀態
                                    // console.log(i+1 + ' : '+ ferment_output_status[i])
                                    // 1 : F_InputtingBean
                                    // 2 : F_Waiting
                                    if (ferment_input_status[i] == 'FI_InputtingBean') {
                                        console.log('[動作] 發酵入料 FI' + parseInt(i+1) + ' 入豆中')
                                        $("#FI"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                        $("#FI"+parseInt(i+1)+"_status").text("FI" + parseInt(i+1) + " 入豆中")
                                        
                                    } else if (ferment_input_status[i] == 'FI_Waiting') {
                                        console.log('[動作] 發酵入料 FI' + parseInt(i+1) + ' 空桶等待')
                                        $("#FI"+parseInt(i+1)+"_status_dot").css("background-color", "lightgray")
                                        $("#FI"+parseInt(i+1)+"_status").text("FI" + parseInt(i+1) + " 空桶等待")
    
                                    } else if (ferment_input_status[i] == 'FI_OutputtingBean') {
                                        console.log('[動作] 發酵入料 FI' + parseInt(i+1) + ' 可出豆')
                                        $("#FI"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                        $("#FI"+parseInt(i+1)+"_status").text("FI" + parseInt(i+1) + " 可出豆")
    
                                    } else {
                                        console.log('pass')
                                    }
                                }
    
                                // ----- 發酵桶槽 F1~F6 狀態 --------------------------------------------------------------
                                ferment_tank_status = [res.Ferment_Tank_1, res.Ferment_Tank_2, res.Ferment_Tank_3,
                                                        res.Ferment_Tank_4, res.Ferment_Tank_5, res.Ferment_Tank_6]
                                for (let i=0; i<ferment_tank_status.length; i++) {
                                    // 顯示對應發酵桶槽號碼 F1~F6 和目前狀態
                                    // console.log(i+1 + ' : '+ ferment_tank_status[i])
                                    // 1 : F_InputtingBean
                                    // 2 : F_Waiting
                                    if (ferment_tank_status[i] == 'F_InputtingBean') {
                                        console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 入豆中')
                                        $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                        $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  入豆中")
                                        
                                    } else if (ferment_tank_status[i] == 'F_InputtingBean_Pause') {
                                        console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 入豆暫停')
                                        $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                        $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  入豆暫停")
    
                                    } else if (ferment_tank_status[i] == 'F_InputtingBean_Finish') {
                                        console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 入豆完成')
                                        $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                        $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  入豆完成")
    
                                    } else if (ferment_tank_status[i] == 'F_InputtingWater') {
                                        console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 入水中')
                                        $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                        $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  入水中")
    
                                    } else if (ferment_tank_status[i] == 'F_Waiting') {
                                        console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 空桶等待')
                                        $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "lightgray")
                                        $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  空桶等待")
    
                                    } else if (ferment_tank_status[i] == 'F_Fermenting') {
                                        console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 發酵中')
                                        $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                        $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  發酵中")
    
                                    } else if (ferment_tank_status_N[i] == 'F_Cleaning') {
                                        console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 清洗中')
                                        $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "plum")
                                        $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  清洗中")
                        
                                    } else if (ferment_tank_status[i] == 'F_OutputtingBean') {
                                        console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 可出豆')
                                        $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                        $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  可出豆")
    
                                    } else if (ferment_tank_status[i] == 'F_Warning') {
                                        console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 發生錯誤')
                                        $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "crimson")
                                        $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  發生錯誤")
                                        $("#F"+parseInt(i+1)+"_status").css("color", "crimson")
                                    } else {
                                        console.log('pass')
                                    }
                                }
    
                                // ----- 發酵出料 FO1 狀態 --------------------------------------------------------------
                                ferment_output_status = [res.Ferment_Output_1]
                                for (let i=0; i<ferment_output_status.length; i++) {
                                    // 顯示對應發酵桶槽號碼 F1~F6 和目前狀態
                                    // console.log(i+1 + ' : '+ ferment_output_status[i])
                                    // 1 : F_InputtingBean
                                    // 2 : F_Waiting
                                    if (ferment_output_status[i] == 'FO_InputtingBean') {
                                        console.log('[動作] 發酵出料 FO' + parseInt(i+1) + ' 入豆中')
                                        $("#FO"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                        $("#FO"+parseInt(i+1)+"_status").text("FO" + parseInt(i+1) + " 入豆中")
                                        
                                    } else if (ferment_output_status[i] == 'FO_Waiting') {
                                        console.log('[動作] 發酵出料 FO' + parseInt(i+1) + ' 空桶等待')
                                        $("#FO"+parseInt(i+1)+"_status_dot").css("background-color", "lightgray")
                                        $("#FO"+parseInt(i+1)+"_status").text("FO" + parseInt(i+1) + " 空桶等待")
    
                                    } else if (ferment_output_status[i] == 'FO_OutputtingBean') {
                                        console.log('[動作] 發酵出料 FO' + parseInt(i+1) + ' 可出豆')
                                        $("#FO"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                        $("#FO"+parseInt(i+1)+"_status").text("FO" + parseInt(i+1) + " 可出豆")
    
                                    } else {
                                        console.log('pass')
                                    }
                                }
    
                                ferment_status_process = 0;
    
                            }, 'json');

                            

                            
                        };
                        
                        
                    };

                    function ferment_auto_status_stop(){
                        clearInterval(ferment_status_interval);
                        clearInterval(loadingF);
                        console.log("------- 狀態自動化判斷 停止 -------")
                    };
                    
                </script>
    

            </div>



            <!-- 發酵貨櫃 狀態表格-->
            <table style="border: 3px lightsteelblue solid; margin-right: auto; margin-left: auto; text-align: center; margin-top: 5px;" cellpadding="5" border="1">
                <tr>
                    <td>
                        <!-- 脫皮機出料儲豆槽 PO11 -->
                        <div id="PO1" tabindex="0" class="PO1_position" role="button" style="text-align: center;">
                            <span id="PO1_status" class="F_status_css">PO1 status</span>
                            <div id="PO1_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                        </div>
                    </td>
                    <td style="border: lightsteelblue 1px solid;">
                        <table style="border: 0px plum solid; margin-right: auto; margin-left: auto; text-align: center;" cellpadding="5">
                            <tr>
                                <td>
                                    <!-- 發酵槽入料儲豆槽 FI1 -->
                                    <div id="FI1" tabindex="0" class="FI1_position" role="button" style="text-align: center;">
                                        <span id="FI1_status" class="F_status_css">FI1 status</span>
                                        <div id="FI1_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td style="border: lightsteelblue 1px solid;">
                        <table style="border: 0px plum solid; margin-right: auto; margin-left: auto; text-align: center;" cellpadding="5">
                            <tr>
                                <td>
                                    <!-- 發酵槽 F1 -->
                                    <div id="F1" tabindex="0" class="F1_position" role="button">
                                        <span id="F1_status" class="F_status_css">F1 status</span>
                                        <!-- F1 狀態點點-->
                                        <div id="F1_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 發酵槽 F2 -->
                                    <div id="F2" tabindex="0" class="F2_position" role="button">
                                        <span id="F2_status" class="F_status_css">F2 status</span>
                                        <div id="F2_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 發酵槽 F3 -->
                                    <div id="F3" tabindex="0" class="F3_position" role="button">
                                        <span id="F3_status" class="F_status_css">F3 status</span>
                                        <div id="F3_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 發酵槽 F4 -->
                                    <div id="F4" tabindex="0" class="F4_position" role="button">
                                        <span id="F4_status" class="F_status_css">F4 status</span>
                                        <div id="F4_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 發酵槽 F5 -->
                                    <div id="F5" tabindex="0" class="F5_position" role="button">
                                        <span id="F5_status" class="F_status_css">F5 status</span>
                                        <div id="F5_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 發酵槽 F6 -->
                                    <div id="F6" tabindex="0" class="F6_position" role="button">
                                        <span id="F6_status" class="F_status_css">F6 status</span>
                                        <div id="F6_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td style="border: lightsteelblue 1px solid;">
                         <table style="border: 0px plum solid; margin-right: auto; margin-left: auto; text-align: center;" cellpadding="5">
                            <tr>
                                <td>
                                    <!-- 發酵槽出料儲豆槽 FO1 -->
                                    <div id="FO1" tabindex="0" class="FO1_position" role="button">
                                        <span id="FO1_status" class="F_status_css">FO1 status</span>
                                        <div id="FO1_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>

                <tr>
                    <td>脫皮機儲豆槽</td>
                    <td style="border: lightsteelblue 1px solid;">
                        入料儲豆槽
                    </td>
                    <td style="border: lightsteelblue 1px solid;">
                        發酵桶槽
                    </td>
                    <td style="border: lightsteelblue 1px solid;">
                        出料儲豆槽
                    </td>
                </tr>

                <tr>
                    <td>PO2</td>
                    <td style="border: lightsteelblue 1px solid;">
                        <table style="border: 0px plum solid; margin-right: auto; margin-left: auto; text-align: center;" cellpadding="5">
                            <tr>
                                <td>
                                    <!-- 發酵槽入料儲豆槽 FI2 -->
                                    <div id="FI2" tabindex="0" class="FI2_position" role="button">
                                        <span id="FI2_status" class="F_status_css">FI2 status</span>
                                        <div id="FI2_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td style="border: lightsteelblue 1px solid;">
                        <table style="border: 0px plum solid; margin-right: auto; margin-left: auto; text-align: center;" cellpadding="5">
                            <tr>
                                <td>
                                    <!-- 發酵槽 F7 -->
                                    <div id="F7" tabindex="0" class="F7_position" role="button" style="vertical-align: bottom;">
                                        <span id="F7_status" class="F_status_css">F7 status</span>
                                        <div id="F7_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 發酵槽 F8 -->
                                    <div id="F8" tabindex="0" class="F8_position" role="button">
                                        <span id="F8_status" class="F_status_css">F8 status</span>
                                        <div id="F8_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 發酵槽 F9 -->
                                    <div id="F9" tabindex="0" class="F9_position" role="button">
                                        <span id="F9_status" class="F_status_css">F9 status</span>
                                        <div id="F9_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 發酵槽 F10 -->
                                    <div id="F10" tabindex="0" class="F10_position" role="button">
                                        <span id="F10_status" class="F_status_css">F10 status</span>
                                        <div id="F10_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 發酵槽 F11 -->
                                    <div id="F11" tabindex="0" class="F11_position" role="button">
                                        <span id="F11_status" class="F_status_css">F11 status</span>
                                        <div id="F11_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 發酵槽 F12 -->
                                    <div id="F12" tabindex="0" class="F12_position" role="button">
                                        <span id="F12_status" class="F_status_css">F12 status</span>
                                        <div id="F12_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td style="border: lightsteelblue 1px solid;">
                        <table style="border: 0px plum solid; margin-right: auto; margin-left: auto; text-align: center;" cellpadding="5">
                            <tr>
                                <td>
                                    <!-- 發酵槽出料儲豆槽 FO2 -->
                                    <div id="FO2" tabindex="0" class="FO2_position" role="button">
                                        <span id="FO2_status" class="F_status_css">FO2 status</span>
                                        <div id="FO2_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>


            <!-- 發酵貨櫃 致動器狀態 感測器數值 -->
            <div style="text-align: center;">
                <table style="border: 3px lightsteelblue solid; margin-right: auto; margin-left: auto; text-align: center; margin-top: 5px;" cellpadding="5" border="1">
                    <tr>
                        <td>
                            入料<br>Vacuum
                        </td>
                        <td>
                            桶槽<br>
                            Vacuum
                        </td>
                        <td>
                            入料<br>三通閥
                        </td>
                        <td>
                            蝴蝶閥
                        </td>
                        <td>
                            逆洗 pump<br>電磁閥
                        </td>
                        <td>
                            消毒<br>電磁閥
                        </td>
                        <td>
                            夾層入水<br>電磁閥
                        </td>
                        <td>
                            桶內入水<br>電磁閥
                        </td>
                        <td>
                            桶內排水<br>電磁閥
                        </td>
                        <td>
                            水質<br>pump
                        </td>
                        <td>
                            夾層浮選<br>三通閥
                        </td>
                        <td>
                            馬達
                        </td>
                        <td>
                            加熱器<br>1
                        </td>
                        <td>
                            加熱器<br>2
                        </td>
                        <td>
                            溫控開關
                        </td>
                        <td>
                            設定溫度
                        </td>
                        <td>
                            出料<br>Vacuum
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span id="actuator_00">x</span>
                        </td>
                        <td>
                            <span id="actuator_1">x</span>
                        </td>
                        <td>
                            <span id="actuator_2">x</span>
                        </td>
                        <td>
                            <span id="actuator_3">x</span>
                        </td>
                        <td>
                            <span id="actuator_4">x</span>
                        </td>
                        <td>
                            <span id="actuator_5">x</span>
                        </td>
                        <td>
                            <span id="actuator_6">x</span>
                        </td>
                        <td>
                            <span id="actuator_7">x</span>
                        </td>
                        <td>
                            <span id="actuator_8">x</span>
                        </td>
                        <td>
                            <span id="actuator_9">x</span>
                        </td>
                        <td>
                            <span id="actuator_10">x</span>
                        </td>
                        <td>
                            <span id="actuator_11">x</span>
                        </td>
                        <td>
                            <span id="actuator_12">x</span>
                        </td>
                        <td>
                            <span id="actuator_13">x</span>
                        </td>
                        <td>
                            <span id="actuator_14">x</span>
                        </td>
                        <td>
                            <span id="actuator_15">x</span>
                        </td>
                        <td>
                            <span id="actuator_99">x</span>
                        </td>
                        
                    </tr>
                
                </table>

                <table style="border: 3px lightsteelblue solid; margin-right: auto; margin-left: auto; text-align: center; margin-top: 5px;" cellpadding="5" border="1">
                    <tr>
                        <td>
                            入料<br>高度
                        </td>
                        <td>
                            高度
                        </td>
                        <td>
                            溫度
                        </td>
                        <td>
                            濕度
                        </td>
                        <td>
                            二氧化碳
                        </td>
                        <td>
                            大氣壓力
                        </td>
                        <td>
                            pH
                        </td>
                        <td>
                            ORP
                        </td>
                        <td>
                            DO
                        </td>
                        <td>
                            EC
                        </td>
                        <td>
                            水位計
                        </td>
                        <td>
                            出料<br>高度
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span id="sensor_00">00</span>
                        </td>
                        <td>
                            <span id="sensor_1">00</span>
                        </td>
                        <td>
                            <span id="sensor_2">00</span>
                        </td>
                        <td>
                            <span id="sensor_3">00</span>
                        </td>
                        <td>
                            <span id="sensor_4">00</span>
                        </td>
                        <td>
                            <span id="sensor_5">00</span>
                        </td>
                        <td>
                            <span id="sensor_6">00</span>
                        </td>
                        <td>
                            <span id="sensor_7">00</span>
                        </td>
                        <td>
                            <span id="sensor_8">00</span>
                        </td>
                        <td>
                            <span id="sensor_9">00</span>
                        </td>
                        <td>
                            <span id="sensor_10">00</span>
                        </td>
                        <td>
                            <span id="sensor_99">00</span>
                        </td>
                    </tr>
                </table>
            </div>



            <!-- 發酵貨櫃 參數設定-->
            <table style="border: 3px lightsteelblue solid; margin-right: auto; margin-left: auto; text-align: center; margin-top: 5px; line-height: 28px;" cellpadding="5" border="1">
                <tr>
                    <td>
                        發酵自動化<br>
                        排程
                    </td>
                    <td>
                        入料儲豆槽<br>
                        參數設定
                    </td>
                    <td>
                        桶槽<br>
                        參數設定
                    </td>
                    <td>
                        出料儲豆槽<br>
                        參數設定
                    </td>
                </tr>
                <tr>
                    <td style="padding: 10px; text-align: left; vertical-align: text-top;">
                        <label><input type="checkbox" id="cb_fermenting" checked>發酵</label><br>

                        <label><input type="checkbox" id="cb_cleaning">清洗：發酵
                            <input name="Ferment_auto_cleaning_Ftimes" class="input-text" type="text">次執行
                        </label><br>

                        <label><input type="checkbox" id="cb_calibratingEC">校正 EC：發酵
                            <input name="Ferment_auto_calibratingEC_Ftimes" class="input-text" type="text">次執行
                        </label><br>

                        <label><input type="checkbox" id="cb_calibratingSTIR">校正攪拌棒：發酵
                            <input name="Ferment_auto_calibratingSTIR_Ftimes" class="input-text" type="text">次執行
                        </label>
                    </td>
                    <td style="padding: 10px; text-align: left; vertical-align: text-top;">
                        生豆高度
                        <input name="Ferment_Input_bean_height" class="input-text" type="text" value="5">公分<br>
                        吸料時間
                        <input name="Ferment_Input_vacuumON_time" class="input-text" type="text" value="5">秒<br>
                        放料時間
                        <input name="Ferment_Input_vacuumOFF_time" class="input-text" type="text" value="10">秒<br>
                    </td>
                    <td style="padding: 10px; text-align: left; vertical-align: text-top;">
                        生豆高度
                        <input name="Ferment_Tank_bean_height" class="input-text" type="text" value="5">公分<br>
                        吸料時間
                        <input name="Ferment_Tank_vacuumON_time" class="input-text" type="text" value="5">秒<br>
                        放料時間
                        <input name="Ferment_Tank_vacuumOFF_time" class="input-text" type="text" value="10">秒<br>
                        水位高度
                        <input name="Ferment_Tank_water_height" class="input-text" type="text" value="8">公分<br>
                        馬達轉速
                        <input name="Ferment_Tank_motor_rpm" class="input-text" type="text" value="15">rpm, 
                        攪拌時間
                        <input name="Ferment_Tank_motor_time" class="input-text" type="text" value="30">秒<br>
                        <label><input type="checkbox" id="Ferment_cb_vacuum" class="input-checkbox">發酵時桶內抽真空？抽氣
                            <input name="Ferment_cb_vacuum_time" class="input-text" type="text" value="30">秒</label><br>
                        發酵溫度
                        <input name="Ferment_Tank_fermenting_temp" class="input-text" type="text" value="30">℃
                        , 且持溫時間
                        <input name="Ferment_Tank_fermenting_time" class="input-text" type="text" value="60">秒<br>
                        指定 pH
                        <input name="Ferment_Tank_fermenting_pH" class="input-text" type="text" value="5">/
                        <del>指定 DO
                        <input name="Ferment_Tank_fermenting_DO" class="input-text" type="text" value="43">/
                        指定 ORP
                        <input name="Ferment_Tank_fermenting_ORP" class="input-text" type="text" value="-0.5">/
                        指定 EC
                        <input name="Ferment_Tank_fermenting_EC" class="input-text" type="text" value="300"><br></del>
                        廢水排放
                        <input name="Ferment_Tank_WaterOut_time" class="input-text" type="text" value="60">秒, 消毒開啟
                        <input name="Ferment_Tank_Disinfect_time" class="input-text" type="text" value="10">秒<br>
                        
                    </td>
                    <td style="padding: 10px; text-align: left; vertical-align: text-top;">
                        生豆高度
                        <input name="Ferment_Output_bean_height" class="input-text" type="text" value="5">公分<br>
                        吸料時間
                        <input name="Ferment_Output_vacuumON_time" class="input-text" type="text" value="5">秒<br>
                        放料時間
                        <input name="Ferment_Output_vacuumOFF_time" class="input-text" type="text" value="10">秒<br>
                    </td>
                </tr>
            </table>

            <!-- 發酵貨櫃 測試按鈕-->
            <div style="text-align: center;">
                <button style="margin: 5px 10px 0px 10px;" type="submit" class="btn btn-primary" onclick="ferment_auto_testing()">
                    [測試] 發酵自動化_網頁控制</button>
                <script>
                    // 入料儲豆槽 入豆狀態 
                    var BeanIn_FI_Process = 0;
                    // 入豆狀態 
                    var BeanIn_F_Process = 0;
                    // 入水狀態
                    var WaterIn_F_Process = 0;
                    // 發酵狀態   
                    var Fermenting_F_Process = 0;
                    // 出料狀態
                    var WaterBeanOut_F_Process = 0;
                    // 出料儲豆槽 入豆狀態 
                    var BeanIn_FO_Process = 0;
    
                    function ferment_auto_testing(){
                        var Ferment_Input_bean_height = parseFloat($("input[name=Ferment_Input_bean_height]").val());
                        var Ferment_Input_vacuumON_time = parseFloat($("input[name=Ferment_Input_vacuumON_time]").val());
                        var Ferment_Input_vacuumOFF_time = parseFloat($("input[name=Ferment_Input_vacuumOFF_time]").val());
                        var Ferment_Tank_bean_height = parseFloat($("input[name=Ferment_Tank_bean_height]").val());
                        var Ferment_Tank_vacuumON_time = parseFloat($("input[name=Ferment_Tank_vacuumON_time]").val());
                        var Ferment_Tank_vacuumOFF_time = parseFloat($("input[name=Ferment_Tank_vacuumOFF_time]").val());
                        var Ferment_Tank_water_height = parseFloat($("input[name=Ferment_Tank_water_height]").val());
                        var Ferment_Tank_fermenting_temp = parseFloat($("input[name=Ferment_Tank_fermenting_temp]").val());
                        var Ferment_Tank_fermenting_time = parseFloat($("input[name=Ferment_Tank_fermenting_time]").val());
                        var Ferment_Tank_fermenting_pH = parseFloat($("input[name=Ferment_Tank_fermenting_pH]").val());
                        var Ferment_Tank_fermenting_DO = parseFloat($("input[name=Ferment_Tank_fermenting_DO]").val());
                        var Ferment_Tank_fermenting_ORP = parseFloat($("input[name=Ferment_Tank_fermenting_ORP]").val());
                        var Ferment_Tank_fermenting_EC = parseFloat($("input[name=Ferment_Tank_fermenting_EC]").val());
                        var Ferment_Tank_motor_rpm = parseFloat($("input[name=Ferment_Tank_motor_rpm]").val());
                        var Ferment_Tank_motor_time = parseFloat($("input[name=Ferment_Tank_motor_time]").val());
                        var Ferment_Output_bean_height = parseFloat($("input[name=Ferment_Output_bean_height]").val());
                        var Ferment_Output_vacuumON_time = parseFloat($("input[name=Ferment_Output_vacuumON_time]").val());
                        var Ferment_Output_vacuumOFF_time = parseFloat($("input[name=Ferment_Output_vacuumOFF_time]").val());
    
                        var BeanIn_FI_interval = setInterval(BeanIn_FI, 5000);
                        
                        function BeanIn_FI(){
                            if (BeanIn_FI_Process == 1) {
                                return; // 若還在處理就取消, 函式立即停止
                            }
    
                            // 取得桶內生豆高度, 若未達生豆高度則入豆
                            BeanIn_FI_Process = 1;
                            $.ajax({
                                async:false,
                                type:"GET",
                                url:"/ferment_input_UltraSonic_1",
                                dataType:'json',
                                success:function(response){
                                    var present_FIBean_height = parseFloat(response.UltraSonic)
                                    console.log("目前入料儲豆槽豆高: " + present_FIBean_height)
                                    console.log("指定入料儲豆槽豆高: " + Ferment_Input_bean_height)
                                    if ( present_FIBean_height >= Ferment_Input_bean_height ) {
                                        clearInterval(BeanIn_FI_interval);
                                        console.log("入料儲豆槽已達生豆高度！")
                                        BeanIn_F_interval = setInterval(BeanIn_F, 5000);
    
                                    } else {
                                        // aaa inputVacuum_ON()
                                        console.log("inputVacuum_ON")
                                        var time = new Date();
                                        while ((new Date() - time) < Ferment_Input_vacuumON_time * 1000) { };
                                        // aaa inputVacuum_OFF()
                                        console.log("inputVacuum_OFF")
                                        var time = new Date();
                                        while ((new Date() - time) < Ferment_Input_vacuumOFF_time * 1000) { };
                                    }
                                    BeanIn_FI_Process = 0;
                                },
                                error:function(thrownError){
                                    console.log("Error: " + thrownError)
                                    BeanIn_FI_Process = 0;
                                }
                            });
                        };
    
                        var BeanIn_F_interval;
    
                        function BeanIn_F(){
                            if (BeanIn_F_Process == 1) {
                                return; // 若還在處理就取消, 函式立即停止
                            }
                            // 取得桶內生豆高度, 若未達生豆高度則入豆
                            BeanIn_F_Process = 1;
                            $.ajax({
                                async:false,
                                type:"GET",
                                url:"/ferment_UltraSonic_1",
                                dataType:'json',
                                success:function(response){
                                    var present_FBean_height = parseFloat(response.UltraSonic)
                                    console.log("目前桶槽豆高: " + present_FBean_height)
                                    console.log("指定桶槽豆高: " + Ferment_Tank_bean_height)
                                    if ( present_FBean_height >= Ferment_Tank_bean_height ) {
                                        clearInterval(BeanIn_F_interval);
                                        console.log("桶槽豆高已達指定高度！")
                                        console.log("指定水高: " + Ferment_Tank_water_height)
    
                                        // 若桶內水還沒滿, 開啟桶內入水
                                        $.get('/ferment_UltraSonic_1', '', function (res) {
                                            if ( res.UltraSonic < Ferment_Tank_water_height ){
                                                console.log('桶內開始入水')
    
                                                // aaa tankSolenoidWaterIn_ON();
                                                console.log('tankSolenoidWaterIn_ON')
    
                                                console.log('請開啟水龍頭進水')
                                            };
                                        }, 'json');
    
                                        // 若夾層水還沒滿, 開啟夾層入水
                                        $.get('/ferment_WaterLevel_1', '', function (res) {
                                            if ( res.WaterLevel != 1 ){
                                                console.log('夾層開始入水')
    
                                                // aaa outerSolenoidWater_ON();
                                                console.log('tankSolenoidWaterIn_ON')
    
                                                console.log('請開啟水龍頭進水')
                                            };
                                        }, 'json');
    
                                        // 入水每五秒判斷
                                        WaterIn_F_interval = setInterval(WaterIn_F, 5000);
    
                                    } else {
                                        // aaa tankVacuum_ON()
                                        console.log("tankVacuum_ON")
                                        var time = new Date();
                                        while ((new Date() - time) < Ferment_Input_vacuumON_time * 1000) { };
                                        // aaa tankVacuum_OFF()
                                        console.log("tankVacuum_OFF")
                                        var time = new Date();
                                        while ((new Date() - time) < Ferment_Input_vacuumOFF_time * 1000) { };
                                    }
                                    BeanIn_F_Process = 0;
                                },
                                error:function(thrownError){
                                    console.log("Error: " + thrownError)
                                    BeanIn_F_Process = 0;
                                }
                            });
                        };
    
                        // 入豆排程
                        var Fermenting_F_interval
    
                        function WaterIn_F(){
                            if(WaterIn_F_Process == 1){
                                return;     // 若還在處理就取消, 函式立即停止
                            }
                            // 取得桶內目前水位、取得夾層是否達水位計
                            WaterIn_F_Process = 1;
                            $.ajax({
                                async:false,
                                type:"GET",
                                url:"/ferment_WaterIn_" + tank_num,
                                dataType:"JSON",
                                success:function(response){
                                    console.log("指定入水高度: " + Ferment_Tank_water_height)
                                    var present_tank_water_height = parseInt(response.UltraSonic)
                                    console.log("目前水位高度: " + present_tank_water_height)
                                    var present_WaterLevel = response.WaterLevel
                                    console.log("目前夾層水位計高度: " + present_WaterLevel)
                                    if (present_WaterLevel == 1 && present_tank_water_height >= Ferment_Tank_water_height) {
                                        clearInterval(WaterIn_F_interval);
                                        console.log("入水完成！")
    
                                        console.log("指定溫度: " + Ferment_Tank_fermenting_temp)
                                        console.log("指定時間: " + Ferment_Tank_fermenting_time)
    
                                        // aaa tankMotor_ON()
                                        console.log("tankMotor_ON")
    
                                        // 取得桶內溫度, 若低於指定溫度則開啟加熱器
                                        $.get('/ferment_SHT11_' + tank_num, '', function(res){
                                            if (res.SHT11_Temp < Ferment_Tank_fermenting_temp){
                                                // aaa setTemp(Ferment_Tank_fermenting_temp, Ferment_Tank_fermenting_time)
                                                console.log("setTemp(" + Ferment_Tank_fermenting_temp + ", " + Ferment_Tank_fermenting_time + ")")
                                            }
                                        });
    
                                        // -- 發酵 --
                                        console.log("進入發酵流程")
                                        Fermenting_F_interval = setInterval(Fermenting_F, 5000); 
                                    }
                                    else if (present_WaterLevel == 1) {
                                        // aaa outerSolenoidWater_OFF()
                                        console.log("outerSolenoidWater_OFF")
                                        console.log("保溫夾層入水完成, 桶內加水中")
                                    }
                                    else if (present_tank_water_height > Ferment_Tank_water_height) {
                                        // aaa tankSolenoidWaterIn_OFF()
                                        console.log("tankSolenoidWaterIn_OFF")
                                        console.log("桶內入水完成, 保溫夾層加水中")
                                    }
                                    WaterIn_F_Process = 0;
                                },
                                error:function(thrownError){
                                    console.log("Error: " + thrownError)
                                    WaterIn_F_Process = 0;
                                }
                            });  
                        };
    
                        // 出水排豆排程
                        var WaterBeanOut_F_interval
    
                        function Fermenting_F(){
                            if (Fermenting_F_Process == 1) {
                                return;                                
                            }
    
                            // 取得現在溫度
                            Fermenting_F_Process = 1;
                            $.ajax({
                                async:false,
                                type:"GET",
                                url:"/ferment_SHT11_" + tank_num,
                                dataType:"json",
                                success:function(response){
                                    var present_Temp = response.SHT11_Temp
                                    console.log("現在溫度: " + present_Temp)
    
                                    if (present_Temp >= Ferment_Tank_fermenting_temp) {
                                        clearInterval(Fermenting_F_interval)
                                        console.log("已達指定溫度！")
    
                                        console.log("發酵 " + Ferment_Tank_fermenting_time + " 秒")
                                        var time = new Date();
                                        while ((new Date() - time) < Ferment_Tank_fermenting_time * 1000) { };
    
                                        console.log("發酵完成, 準備出豆")
    
                                        // aaa tankTempEnable_OFF()
                                        console.log("tankTempEnable_OFF")
                                        // aaa tankMotor_OFF()
                                        console.log("tankMotor_OFF")
                                        // aaa tankSolenoidWaterOut_ON()
                                        console.log("tankSolenoidWaterOut_ON")
                                        console.log("暫停 1 分鐘排放廢水")
                                        var time = new Date();
                                        while ((new Date() - time) < 60 * 1000) { };
                                        // aaa tankSolenoidWaterOut_OFF()
                                        console.log("tankSolenoidWaterOut_OFF")
    
                                        WaterBeanOut_F_interval = setInterval(WaterBeanOut_F, 5000);
                                    }
                                    Fermenting_F_Process = 0;
                                },
                                error:function(thrownError){
                                    console.log("Error: " + thrownError)
                                    Fermenting_F_Process = 0;
                                }
                            });
    
                        };
    
                        function WaterBeanOut_F(){
                            // -- 出料 --
                            // 設定空桶高度
                            var testing_tank_empty_height_F = 3.0;
                            console.log("設定空桶高度: " + testing_tank_empty_height_F)
                            if (WaterBeanOut_F_Process == 1){
                                return;
                            }
    
                            // 取得桶內生豆高度
                            WaterBeanOut_F_Process = 1;
                            $.ajax({
                                async:false,
                                type:"GET",
                                url:"/ferment_UltraSonic_" + tank_num,
                                dataType:"json",
                                success:function(response){
                                    var present_Bean_height = parseFloat(response.UltraSonic);
                                    console.log("目前發酵豆高/水位: " + present_Bean_height)
                                    if (present_Bean_height >　testing_tank_empty_height_F) {
                                        // aaa outputVacuum_ON()
                                        console.log("outputVacuum_ON")
                                        var time = new Date();
                                        while ((new Date() - time) < Ferment_Output_vacuumON_time * 1000) { };
                                        // aaa outputVacuum_OFF()
                                        console.log("outputVacuum_OFF")
                                        var time = new Date();
                                        while ((new Date() - time) < Ferment_Output_vacuumOFF_time * 1000) { };
                                    }　else {
                                        clearInterval(WaterBeanOut_F_interval);
                                        console.log("發酵完成！槽內已無生豆")
                                    }
                                    WaterBeanOut_F_Process = 0;
                                },
                                error:function(thrownError){
                                    console.log("Error: " + thrownError)
                                    WaterBeanOut_F_Process = 0;
                                }
                            })
                        };
    
    
                    }
                </script>

                            
                <button style="margin: 5px 10px 0px 10px;" type="submit" class="btn btn-primary" onclick="ferment_auto()">
                    [測試] MQTT + 每 60 秒更新貨櫃狀態</button>
                <script>
                    function ferment_auto(){
                        var Ferment_Input_bean_height = $("input[name=Ferment_Input_bean_height]").val();
                        var Ferment_Input_vacuumON_time = $("input[name=Ferment_Input_vacuumON_time]").val();
                        var Ferment_Input_vacuumOFF_time = $("input[name=Ferment_Input_vacuumOFF_time]").val();
                        var Ferment_Tank_bean_height = $("input[name=Ferment_Tank_bean_height]").val();
                        var Ferment_Tank_vacuumON_time = $("input[name=Ferment_Tank_vacuumON_time]").val();
                        var Ferment_Tank_vacuumOFF_time = $("input[name=Ferment_Tank_vacuumOFF_time]").val();
                        var Ferment_Tank_water_height = $("input[name=Ferment_Tank_water_height]").val();
                        var Ferment_Tank_fermenting_temp = $("input[name=Ferment_Tank_fermenting_temp]").val();
                        var Ferment_Tank_fermenting_time = $("input[name=Ferment_Tank_fermenting_time]").val();
                        var Ferment_Tank_fermenting_pH = $("input[name=Ferment_Tank_fermenting_pH]").val();
                        var Ferment_Tank_fermenting_DO = $("input[name=Ferment_Tank_fermenting_DO]").val();
                        var Ferment_Tank_fermenting_ORP = $("input[name=Ferment_Tank_fermenting_ORP]").val();
                        var Ferment_Tank_fermenting_EC = $("input[name=Ferment_Tank_fermenting_EC]").val();
                        var Ferment_Tank_motor_rpm = $("input[name=Ferment_Tank_motor_rpm]").val();
                        var Ferment_Tank_motor_time = $("input[name=Ferment_Tank_motor_time]").val();
                        var Ferment_Tank_Disinfect_time = $("input[name=Ferment_Tank_Disinfect_time]").val();
                        var Ferment_Output_bean_height = $("input[name=Ferment_Output_bean_height]").val();
                        var Ferment_Output_vacuumON_time = $("input[name=Ferment_Output_vacuumON_time]").val();
                        var Ferment_Output_vacuumOFF_time = $("input[name=Ferment_Output_vacuumOFF_time]").val();

                        var FermentAuto_fermenting = $('#cb_fermenting').prop('checked') // true false
                        var FermentAuto_cleaning = $('#cb_cleaning').prop('checked')
                        var FermentAuto_calibratingEC = $('#cb_calibratingEC').prop('checked')
                        var FermentAuto_calibratingSTIR = $('#cb_calibratingSTIR').prop('checked')
                        var Ferment_auto_cleaning_Ftimes = $("input[name=Ferment_auto_cleaning_Ftimes]").val();
                        var Ferment_auto_calibratingEC_Ftimes = $("input[name=Ferment_auto_calibratingEC_Ftimes]").val();
                        var Ferment_auto_calibratingSTIR_Ftimes = $("input[name=Ferment_auto_calibratingSTIR_Ftimes]").val();

                        if ( (!(/(^[1-9]\d*$)/.test(Ferment_auto_cleaning_Ftimes)) && FermentAuto_cleaning) ||
                                    (!(/(^[1-9]\d*$)/.test(Ferment_auto_calibratingEC_Ftimes)) && FermentAuto_calibratingEC) ||
                                    (!(/(^[1-9]\d*$)/.test(Ferment_auto_calibratingSTIR_Ftimes)) && FermentAuto_calibratingSTIR) ) {
                            alert('[發酵貨櫃] 次數只接受正整數, 請重新輸入')
                            return
                        } else {
                            // 若發酵排程被勾選則為 1, 否則為 0 (預設發酵排程會不斷執行)
                            if (FermentAuto_fermenting == true) { FermentAuto_fermenting = 1
                            } else { FermentAuto_fermenting = 0 }
                            // 若清洗排程被勾選則取得輸入框次數, 否則為 0 (勾選預設為 1)
                            if (FermentAuto_cleaning == true) { FermentAuto_cleaning = Ferment_auto_cleaning_Ftimes
                            } else { FermentAuto_cleaning = 0 }
                            // 若校正 EC 排程被勾選則取得輸入框次數, 否則為 0 (勾選預設為 1)
                            if (FermentAuto_calibratingEC == true) { FermentAuto_calibratingEC = Ferment_auto_calibratingEC_Ftimes
                            } else { FermentAuto_calibratingEC = 0 }
                            // 若校正攪拌棒排程被勾選則取得輸入框次數, 否則為 0 (勾選預設為 1)
                            if (FermentAuto_calibratingSTIR == true) { FermentAuto_calibratingSTIR = Ferment_auto_calibratingSTIR_Ftimes
                            } else { FermentAuto_calibratingSTIR = 0 }
                        }
                        
                        
                        var data = { 'command': 'Ferment_auto_parameter', 
                                    'FermentAuto_fermenting': FermentAuto_fermenting, 
                                    'FermentAuto_cleaning': FermentAuto_cleaning, 
                                    'FermentAuto_calibratingEC': FermentAuto_calibratingEC, 
                                    'FermentAuto_calibratingSTIR': FermentAuto_calibratingSTIR, 
                                    'Ferment_Input_bean_height':Ferment_Input_bean_height,
                                    'Ferment_Input_vacuumON_time': Ferment_Input_vacuumON_time, 
                                    'Ferment_Input_vacuumOFF_time': Ferment_Input_vacuumOFF_time, 
                                    'Ferment_Tank_bean_height': Ferment_Tank_bean_height, 
                                    'Ferment_Tank_vacuumON_time': Ferment_Tank_vacuumON_time, 
                                    'Ferment_Tank_vacuumOFF_time': Ferment_Tank_vacuumOFF_time, 
                                    'Ferment_Tank_water_height': Ferment_Tank_water_height, 
                                    'Ferment_Tank_fermenting_temp': Ferment_Tank_fermenting_temp, 
                                    'Ferment_Tank_fermenting_time': Ferment_Tank_fermenting_time, 
                                    'Ferment_Tank_fermenting_pH': Ferment_Tank_fermenting_pH, 
                                    'Ferment_Tank_fermenting_DO': Ferment_Tank_fermenting_DO, 
                                    'Ferment_Tank_fermenting_ORP': Ferment_Tank_fermenting_ORP, 
                                    'Ferment_Tank_fermenting_EC': Ferment_Tank_fermenting_EC, 
                                    'Ferment_Tank_motor_rpm': Ferment_Tank_motor_rpm, 
                                    'Ferment_Tank_motor_time': Ferment_Tank_motor_time,
                                    'Ferment_Output_bean_height': Ferment_Output_bean_height,
                                    'Ferment_Output_vacuumON_time': Ferment_Output_vacuumON_time, 
                                    'Ferment_Output_vacuumOFF_time': Ferment_Output_vacuumOFF_time };
                        $.post('/mqtt/101', data, function (res) {
                            console.log('data: ', data)
                            console.log('res: ', res)

                        }, 'text')
                        
                        var ferment_interval = setInterval(testing_F_auto, 30*1000)
                    }
                </script>

                <button style="margin: 5px 10px 0px 10px;" type="submit" class="btn btn-primary" onclick="testing_F_auto()">
                    [測試] 發酵貨櫃狀態</button>

                <script>
                    function test(){
                        var FermentAuto_fermenting = $('#cb_fermenting').prop('checked') // true false
                        var FermentAuto_cleaning = $('#cb_cleaning').prop('checked')
                        var FermentAuto_calibratingEC = $('#cb_calibratingEC').prop('checked')
                        var FermentAuto_calibratingSTIR = $('#cb_calibratingSTIR').prop('checked')
                        /*
                        if ($('#cb_fermenting').prop('checked')) {
                            console.log("發酵自動化：加入發酵排程");
                        }
                        if ($('#cb_cleaning').prop('checked')) {
                            console.log("發酵自動化：加入清洗排程");
                        }
                        if ($('#cb_calibratingEC').prop('checked')) {
                            console.log("發酵自動化：加入校正 EC 排程");
                        }
                        if ($('#cb_calibratingSTIR').prop('checked')) {
                            console.log("發酵自動化：加入校正攪拌棒排程");
                        }
                        */
                        Ferment_auto_cleaning_Ftimes = $("input[name=Ferment_auto_cleaning_Ftimes]").val();
                        console.log('Ferment_auto_cleaning_Ftimes: ' + Ferment_auto_cleaning_Ftimes)
                        if ( !(/(^[1-9]\d*$)/.test(Ferment_auto_cleaning_Ftimes)) ){
                            console.log('不可為小數')
                        }

                        console.log(FermentAuto_fermenting)
                        console.log(FermentAuto_cleaning)
                        console.log(FermentAuto_calibratingEC)
                        console.log(FermentAuto_calibratingSTIR)

                    };

                    function testing_F_auto(){
                        var FermentAuto_fermenting = $('#cb_fermenting').prop('checked') // true false
                        var FermentAuto_cleaning = $('#cb_cleaning').prop('checked')
                        var FermentAuto_calibratingEC = $('#cb_calibratingEC').prop('checked')
                        var FermentAuto_calibratingSTIR = $('#cb_calibratingSTIR').prop('checked')

                        var Ferment_auto_cleaning_Ftimes = $("input[name=Ferment_auto_cleaning_Ftimes]").val();
                        var Ferment_auto_calibratingEC_Ftimes = $("input[name=Ferment_auto_calibratingEC_Ftimes]").val();
                        var Ferment_auto_calibratingSTIR_Ftimes = $("input[name=Ferment_auto_calibratingSTIR_Ftimes]").val();
                        
                        if ((!FermentAuto_fermenting) && (!FermentAuto_cleaning) && !FermentAuto_calibratingEC && !FermentAuto_calibratingSTIR) {
                            alert('[發酵貨櫃] 未勾選任何排程, 自動化結束')
                            return
                        } else if ( (!(/(^[1-9]\d*$)/.test(Ferment_auto_cleaning_Ftimes)) && FermentAuto_cleaning) ||
                                    (!(/(^[1-9]\d*$)/.test(Ferment_auto_calibratingEC_Ftimes)) && FermentAuto_calibratingEC) ||
                                    (!(/(^[1-9]\d*$)/.test(Ferment_auto_calibratingSTIR_Ftimes)) && FermentAuto_calibratingSTIR) ) {
                            alert('[發酵貨櫃] 次數只接受正整數, 請重新輸入')
                            return
                        } else {
                            // 若發酵排程被勾選則為 1, 否則為 0 (預設發酵排程會不斷執行)
                            if (FermentAuto_fermenting == true) { FermentAuto_fermenting = 1
                            } else { FermentAuto_fermenting = 0 }
                            // 若清洗排程被勾選則取得輸入框次數, 否則為 0 (勾選預設為 1)
                            if (FermentAuto_cleaning == true) { FermentAuto_cleaning = Ferment_auto_cleaning_Ftimes
                            } else { FermentAuto_cleaning = 0 }
                            // 若校正 EC 排程被勾選則取得輸入框次數, 否則為 0 (勾選預設為 1)
                            if (FermentAuto_calibratingEC == true) { FermentAuto_calibratingEC = Ferment_auto_calibratingEC_Ftimes
                            } else { FermentAuto_calibratingEC = 0 }
                            // 若校正攪拌棒排程被勾選則取得輸入框次數, 否則為 0 (勾選預設為 1)
                            if (FermentAuto_calibratingSTIR == true) { FermentAuto_calibratingSTIR = Ferment_auto_calibratingSTIR_Ftimes
                            } else { FermentAuto_calibratingSTIR = 0 }
                        }

                        var Ferment_Input_vacuumON_time = $("input[name=Ferment_Input_vacuumON_time]").val();
                        var Ferment_Input_vacuumOFF_time = $("input[name=Ferment_Input_vacuumOFF_time]").val();

                        var Ferment_Tank_bean_height = $("input[name=Ferment_Tank_bean_height]").val();
                        var Ferment_Tank_vacuumON_time = $("input[name=Ferment_Tank_vacuumON_time]").val();
                        var Ferment_Tank_vacuumOFF_time = $("input[name=Ferment_Tank_vacuumOFF_time]").val();
                        var Ferment_Tank_water_height = $("input[name=Ferment_Tank_water_height]").val();
                        var Ferment_Tank_fermenting_temp = $("input[name=Ferment_Tank_fermenting_temp]").val();
                        var Ferment_Tank_fermenting_time = $("input[name=Ferment_Tank_fermenting_time]").val();
                        var Ferment_Tank_fermenting_pH = $("input[name=Ferment_Tank_fermenting_pH]").val();
                        var Ferment_Tank_fermenting_DO = $("input[name=Ferment_Tank_fermenting_DO]").val();
                        var Ferment_Tank_fermenting_ORP = $("input[name=Ferment_Tank_fermenting_ORP]").val();
                        var Ferment_Tank_fermenting_EC = $("input[name=Ferment_Tank_fermenting_EC]").val();
                        var Ferment_Tank_motor_rpm = $("input[name=Ferment_Tank_motor_rpm]").val();
                        var Ferment_Tank_Disinfect_time = $("input[name=Ferment_Tank_Disinfect_time]").val();
                        
                        var Ferment_Output_vacuumON_time = $("input[name=Ferment_Output_vacuumON_time]").val();
                        var Ferment_Output_vacuumOFF_time = $("input[name=Ferment_Output_vacuumOFF_time]").val();
                        
                        var data = { 'command': 'Ferment_auto_parameter', 
                                    'FermentAuto_fermenting': FermentAuto_fermenting, 
                                    'FermentAuto_cleaning': FermentAuto_cleaning, 
                                    'FermentAuto_calibratingEC': FermentAuto_calibratingEC, 
                                    'FermentAuto_calibratingSTIR': FermentAuto_calibratingSTIR, 

                                    'Ferment_Input_vacuumON_time': Ferment_Input_vacuumON_time, 
                                    'Ferment_Input_vacuumOFF_time': Ferment_Input_vacuumOFF_time, 
                                    'Ferment_Tank_bean_height': Ferment_Tank_bean_height, 
                                    'Ferment_Tank_vacuumON_time': Ferment_Tank_vacuumON_time, 
                                    'Ferment_Tank_vacuumOFF_time': Ferment_Tank_vacuumOFF_time, 
                                    'Ferment_Tank_water_height': Ferment_Tank_water_height, 
                                    'Ferment_Tank_fermenting_temp': Ferment_Tank_fermenting_temp, 
                                    'Ferment_Tank_fermenting_time': Ferment_Tank_fermenting_time, 
                                    'Ferment_Tank_fermenting_pH': Ferment_Tank_fermenting_pH, 
                                    'Ferment_Tank_fermenting_DO': Ferment_Tank_fermenting_DO, 
                                    'Ferment_Tank_fermenting_ORP': Ferment_Tank_fermenting_ORP, 
                                    'Ferment_Tank_fermenting_EC': Ferment_Tank_fermenting_EC, 
                                    'Ferment_Tank_motor_rpm': Ferment_Tank_motor_rpm, 
                                    'Ferment_Output_vacuumON_time': Ferment_Output_vacuumON_time, 
                                    'Ferment_Output_vacuumOFF_time': Ferment_Output_vacuumOFF_time };
                        $.get('/ferment_auto_status', data, function (res) {
                            console.log('FI1: ' + res.Ferment_Input_1)
                            console.log('F1: ' + res.Ferment_Tank_1)
                            console.log('F2: ' + res.Ferment_Tank_2)
                            console.log('F3: ' + res.Ferment_Tank_3)
                            console.log('F4: ' + res.Ferment_Tank_4)
                            console.log('F5: ' + res.Ferment_Tank_5)
                            console.log('F6: ' + res.Ferment_Tank_6)
                            console.log('FO1: ' + res.Ferment_Output_1)

                            // ----- 發酵出料 FO1 狀態 --------------------------------------------------------------
                            ferment_input_status = [res.Ferment_Input_1]
                            for (let i=0; i<ferment_input_status.length; i++) {
                                // 顯示對應發酵桶槽號碼 F1~F6 和目前狀態
                                // console.log(i+1 + ' : '+ ferment_output_status[i])
                                // 1 : F_InputtingBean
                                // 2 : F_Waiting
                                if (ferment_input_status[i] == 'FI_InputtingBean') {
                                    console.log('[動作] 發酵入料 FI' + parseInt(i+1) + ' 入豆中')
                                    $("#FI"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                    $("#FI"+parseInt(i+1)+"_status").text("FI" + parseInt(i+1) + " 入豆中")
                                    
                                } else if (ferment_input_status[i] == 'FI_Waiting') {
                                    console.log('[動作] 發酵入料 FI' + parseInt(i+1) + ' 空桶等待')
                                    $("#FI"+parseInt(i+1)+"_status_dot").css("background-color", "lightgray")
                                    $("#FI"+parseInt(i+1)+"_status").text("FI" + parseInt(i+1) + " 空桶等待")

                                } else if (ferment_input_status[i] == 'FI_OutputtingBean') {
                                    console.log('[動作] 發酵入料 FI' + parseInt(i+1) + ' 可出豆')
                                    $("#FI"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                    $("#FI"+parseInt(i+1)+"_status").text("FI" + parseInt(i+1) + " 可出豆")

                                } else {
                                    console.log('pass')
                                }
                            }

                            // ----- 發酵桶槽 F1~F6 狀態 --------------------------------------------------------------
                            ferment_tank_status = [res.Ferment_Tank_1, res.Ferment_Tank_2, res.Ferment_Tank_3,
                                                    res.Ferment_Tank_4, res.Ferment_Tank_5, res.Ferment_Tank_6]
                            for (let i=0; i<ferment_tank_status.length; i++) {
                                // 顯示對應發酵桶槽號碼 F1~F6 和目前狀態
                                // console.log(i+1 + ' : '+ ferment_tank_status[i])
                                // 1 : F_InputtingBean
                                // 2 : F_Waiting
                                if (ferment_tank_status[i] == 'F_InputtingBean') {
                                    console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 入豆中')
                                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  入豆中")
                                    
                                } else if (ferment_tank_status[i] == 'F_InputtingBean_Pause') {
                                    console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 入豆暫停')
                                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  入豆暫停")

                                } else if (ferment_tank_status[i] == 'F_InputtingBean_Finish') {
                                    console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 入豆完成')
                                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  入豆完成")

                                } else if (ferment_tank_status[i] == 'F_InputtingWater') {
                                    console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 入水中')
                                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  入水中")

                                } else if (ferment_tank_status[i] == 'F_Waiting') {
                                    console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 空桶等待')
                                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "lightgray")
                                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  空桶等待")

                                } else if (ferment_tank_status[i] == 'F_Fermenting') {
                                    console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 發酵中')
                                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  發酵中")

                                } else if (ferment_tank_status_N[i] == 'F_Cleaning') {
                                    console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 清洗中')
                                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "plum")
                                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  清洗中")
                    
                                } else if (ferment_tank_status[i] == 'F_OutputtingBean') {
                                    console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 可出豆')
                                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  可出豆")

                                } else if (ferment_tank_status[i] == 'F_Warning') {
                                    console.log('[動作] 發酵桶槽 F' + parseInt(i+1) + ' 發生錯誤')
                                    $("#F"+parseInt(i+1)+"_status_dot").css("background-color", "crimson")
                                    $("#F"+parseInt(i+1)+"_status").text("F" + parseInt(i+1) + "  發生錯誤")
                                    $("#F"+parseInt(i+1)+"_status").css("color", "crimson")
                                } else {
                                    console.log('pass')
                                }
                            }

                            // ----- 發酵出料 FO1 狀態 --------------------------------------------------------------
                            ferment_output_status = [res.Ferment_Output_1]
                            for (let i=0; i<ferment_output_status.length; i++) {
                                // 顯示對應發酵桶槽號碼 F1~F6 和目前狀態
                                // console.log(i+1 + ' : '+ ferment_output_status[i])
                                // 1 : F_InputtingBean
                                // 2 : F_Waiting
                                if (ferment_output_status[i] == 'FO_InputtingBean') {
                                    console.log('[動作] 發酵出料 FO' + parseInt(i+1) + ' 入豆中')
                                    $("#FO"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                    $("#FO"+parseInt(i+1)+"_status").text("FO" + parseInt(i+1) + " 入豆中")
                                    
                                } else if (ferment_output_status[i] == 'FO_Waiting') {
                                    console.log('[動作] 發酵出料 FO' + parseInt(i+1) + ' 空桶等待')
                                    $("#FO"+parseInt(i+1)+"_status_dot").css("background-color", "lightgray")
                                    $("#FO"+parseInt(i+1)+"_status").text("FO" + parseInt(i+1) + " 空桶等待")

                                } else if (ferment_output_status[i] == 'FO_OutputtingBean') {
                                    console.log('[動作] 發酵出料 FO' + parseInt(i+1) + ' 可出豆')
                                    $("#FO"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                    $("#FO"+parseInt(i+1)+"_status").text("FO" + parseInt(i+1) + " 可出豆")

                                } else {
                                    console.log('pass')
                                }
                            }
                            /*
                            console.log(res.Ferment_Input_2)
                            console.log(res.Ferment_Tank_7)
                            console.log(res.Ferment_Tank_8)
                            console.log(res.Ferment_Tank_9)
                            console.log(res.Ferment_Tank_10)
                            console.log(res.Ferment_Tank_11)
                            console.log(res.Ferment_Tank_12)
                            console.log(res.Ferment_Output_1)
                            console.log(res.Ferment_Output_2)
                            */
                        }, 'json');
                        // console.log("-- 自動化程式 end --")
                    }
                </script>
    
            </div>
            
            <br>
            <br>

        </div>


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

</body>

</html>