<!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">
    -->
    <script>
        $(document).ready(function(){
            $("#coffee_title").text('乾燥自動化');

            // 桶槽入料顯示
            dry_input_status_N = ['{{DI1}}', '{{DI2}}']
            console.log('dry_input_status_N: ' + dry_input_status_N)
            for (let i=0; i<dry_input_status_N.length; i++) {
                // 顯示對應乾燥桶槽號碼 D1~D6 和目前狀態
                // console.log(i+1 + ' : '+ dry_input_status_N[i])
                // 1 : F_InputtingBean
                // 2 : F_Waiting
                if (dry_input_status_N[i] == 'DI_InputtingBean') {
                    $("#DI"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#DI"+parseInt(i+1)+"_status").text("DI" + parseInt(i+1) + " 入豆中")
                } else if (dry_input_status_N[i] == 'DI_Waiting') {
                    $("#DI"+parseInt(i+1)+"_status_dot").css("background-color", "lightgray")
                    $("#DI"+parseInt(i+1)+"_status").text("DI" + parseInt(i+1) + " 空桶等待")
                } else if (dry_input_status_N[i] == 'DI_OutputtingBean') {
                    $("#DI"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#DI"+parseInt(i+1)+"_status").text("DI" + parseInt(i+1) + " 可出豆")
                } else {
                    console.log('pass')
                }
            }

            // 桶槽狀態顯示
            dry_tank_status_N = ['{{D1}}', '{{D2}}', '{{D3}}', '{{D4}}', '{{D5}}', '{{D6}}', 
                                    '{{D7}}', '{{D8}}', '{{D9}}', '{{D10}}', '{{D11}}', '{{D12}}']
            console.log('dry_tank_status_N: ' + dry_tank_status_N)
            for (let i=0; i<dry_tank_status_N.length; i++) {
                // 顯示對應乾燥桶槽號碼 D1~D6 和目前狀態
                // console.log(i+1 + ' : '+ dry_tank_status_N[i])
                // 1 : D_InputtingBean
                // 2 : D_Waiting
                if (dry_tank_status_N[i] == 'D_InputtingBean') {
                    $("#D"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#D"+parseInt(i+1)+"_status").text("D" + parseInt(i+1) + "  入豆中")
                } else if (dry_tank_status_N[i] == 'D_InputtingBean_Pause') {
                    $("#D"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#D"+parseInt(i+1)+"_status").text("D" + parseInt(i+1) + "  入豆暫停")
                } else if (dry_tank_status_N[i] == 'D_InputtingBean_Finish') {
                    $("#D"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#D"+parseInt(i+1)+"_status").text("D" + parseInt(i+1) + "  入豆完成")
                } else if (dry_tank_status_N[i] == 'D_Waiting') {
                    $("#D"+parseInt(i+1)+"_status_dot").css("background-color", "lightgray")
                    $("#D"+parseInt(i+1)+"_status").text("D" + parseInt(i+1) + "  空桶等待")
                } else if (dry_tank_status_N[i] == 'D_Cleaning') {
                    $("#D"+parseInt(i+1)+"_status_dot").css("background-color", "plum")
                    $("#D"+parseInt(i+1)+"_status").text("D" + parseInt(i+1) + "  清洗中")
                } else if (dry_tank_status_N[i] == 'D_Drying') {
                    $("#D"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#D"+parseInt(i+1)+"_status").text("D" + parseInt(i+1) + "  乾燥中")
                } else if (dry_tank_status_N[i] == 'D_OutputtingBean') {
                    $("#D"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#D"+parseInt(i+1)+"_status").text("D" + parseInt(i+1) + "  可出豆")
                } else if (dry_tank_status_N[i] == 'D_Warning') {
                    $("#D"+parseInt(i+1)+"_status_dot").css("background-color", "crimson")
                    $("#D"+parseInt(i+1)+"_status").text("D" + parseInt(i+1) + "  發生錯誤")
                    $("#D"+parseInt(i+1)+"_status").css("color", "crimson")
                } else {
                    console.log('pass')
                }
            }
            
            // 桶槽出料顯示
            dry_output_status_N = ['{{DO1}}', '{{DO2}}']
            console.log('dry_output_status_N: ' + dry_output_status_N)
            for (let i=0; i<dry_output_status_N.length; i++) {
                // 顯示對應乾燥桶槽號碼 D1~D6 和目前狀態
                // console.log(i+1 + ' : '+ dry_output_status[i])
                // 1 : D_InputtingBean
                // 2 : D_Waiting
                if (dry_output_status_N[i] == 'DO_InputtingBean') {
                    $("#DO"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                    $("#DO"+parseInt(i+1)+"_status").text("DO" + parseInt(i+1) + " 入豆中")
                    
                } else if (dry_output_status_N[i] == 'DO_Waiting') {
                    $("#DO"+parseInt(i+1)+"_status_dot").css("background-color", "lightgray")
                    $("#DO"+parseInt(i+1)+"_status").text("DO" + parseInt(i+1) + " 空桶等待")

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

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

            }

            // css 
            // height: 185px; 取代成 height: 210px;
            // DI2 DO2  top: 620px; 取代成 top: 645px;
        });
    </script>
    
    <style>
        .D_status_css {
            font-weight: bold;
            text-align: center;
        }
        .DryContainer_position {
            position: absolute;
            top: 95px;
            left: 53px;
        }
        .D1_position {
            width: 110px;
        }
        .D2_position {
            width: 110px;
        }
        .D3_position {
            width: 110px;
        }
        .D4_position {
            width: 110px;
        }
        .D5_position {
            width: 110px;
        }
        .D6_position {
            width: 110px;
        }
        .D7_position {
            width: 110px;
        }
        .D8_position {
            width: 110px;
        }
        .D9_position {
            width: 110px;
        }
        .D10_position {
            width: 110px;
        }
        .D11_position {
            width: 110px;
        }
        .D12_position {
            width: 110px;
        }

        .DI1_position {
            width: 110px;
        }

        .DI2_position {
            width: 110px;
        }
        
        .DO1_position {
            width: 110px;
        }
        
        .DO2_position {
            width: 110px;
        }
        .footer{
            position: absolute;
            bottom: 0px;
            width: 100%;
            background-color: #eee;
            text-align: center;
        }
        
    </style>
    <script language="JavaScript">
        // 指定 10秒 刷新網頁一次
        var WebUpdate_set
        // WebUpdate_set = setInterval(function(){WebUpdate()} , 60 * 1000)

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

</head>

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

        <div>

            <!-- 乾燥貨櫃 狀態表格-->
            <table style="border: 3px lightsteelblue solid; margin-right: auto; margin-left: auto; text-align: center; margin-top: 10px;" cellpadding="5" border="1">
                <tr>
                    <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>
                                    <!-- 乾燥槽入料儲豆槽 DI1 -->
                                    <div id="DI1" tabindex="0" class="DI1_position" role="button" style="text-align: center;">
                                        <span id="DI1_status" class="D_status_css">DI1 status</span>
                                        <div id="DI1_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>
                                    <!-- 乾燥槽 D1 -->
                                    <div id="D1" tabindex="0" class="D1_position" role="button">
                                        <span id="D1_status" class="D_status_css">D1 status</span>
                                        <!-- D1 狀態點點-->
                                        <div id="D1_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 乾燥槽 D2 -->
                                    <div id="D2" tabindex="0" class="D2_position" role="button">
                                        <span id="D2_status" class="D_status_css">D2 status</span>
                                        <div id="D2_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 乾燥槽 D3 -->
                                    <div id="D3" tabindex="0" class="D3_position" role="button">
                                        <span id="D3_status" class="D_status_css">D3 status</span>
                                        <div id="D3_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 乾燥槽 D4 -->
                                    <div id="D4" tabindex="0" class="D4_position" role="button">
                                        <span id="D4_status" class="D_status_css">D4 status</span>
                                        <div id="D4_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 乾燥槽 D5 -->
                                    <div id="D5" tabindex="0" class="D5_position" role="button">
                                        <span id="D5_status" class="D_status_css">D5 status</span>
                                        <div id="D5_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 乾燥槽 D6 -->
                                    <div id="D6" tabindex="0" class="D6_position" role="button">
                                        <span id="D6_status" class="D_status_css">D6 status</span>
                                        <div id="D6_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>
                                    <!-- 乾燥槽出料儲豆槽 DO1 -->
                                    <div id="DO1" tabindex="0" class="DO1_position" role="button">
                                        <span id="DO1_status" class="D_status_css">DO1 status</span>
                                        <div id="DO1_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>

                <tr>
                    <td style="border: lightsteelblue 1px solid;">
                        入料儲豆槽
                    </td>
                    <td style="border: lightsteelblue 1px solid;">
                        乾燥桶槽
                    </td>
                    <td style="border: lightsteelblue 1px solid;">
                        出料儲豆槽
                    </td>
                </tr>

                <tr>
                    <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>
                                    <!-- 乾燥槽入料儲豆槽 DI2 -->
                                    <div id="DI2" tabindex="0" class="DI2_position" role="button">
                                        <span id="DI2_status" class="D_status_css">DI2 status</span>
                                        <div id="DI2_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>
                                    <!-- 乾燥槽 D7 -->
                                    <div id="D7" tabindex="0" class="D7_position" role="button" style="vertical-align: bottom;">
                                        <span id="D7_status" class="D_status_css">D7 status</span>
                                        <div id="D7_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 乾燥槽 D8 -->
                                    <div id="D8" tabindex="0" class="D8_position" role="button">
                                        <span id="D8_status" class="D_status_css">D8 status</span>
                                        <div id="D8_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 乾燥槽 D9 -->
                                    <div id="D9" tabindex="0" class="D9_position" role="button">
                                        <span id="D9_status" class="D_status_css">D9 status</span>
                                        <div id="D9_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 乾燥槽 D10 -->
                                    <div id="D10" tabindex="0" class="D10_position" role="button">
                                        <span id="D10_status" class="D_status_css">D10 status</span>
                                        <div id="D10_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 乾燥槽 D11 -->
                                    <div id="D11" tabindex="0" class="D11_position" role="button">
                                        <span id="D11_status" class="D_status_css">D11 status</span>
                                        <div id="D11_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                                <td>
                                    <!-- 乾燥槽 D12 -->
                                    <div id="D12" tabindex="0" class="D12_position" role="button">
                                        <span id="D12_status" class="D_status_css">D12 status</span>
                                        <div id="D12_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>
                                    <!-- 乾燥槽出料儲豆槽 DO2 -->
                                    <div id="DO2" tabindex="0" class="DO2_position" role="button">
                                        <span id="DO2_status" class="D_status_css">DO2 status</span>
                                        <div id="DO2_status_dot" style="width: 110px; height: 20px; background-color: black;"></div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>



            <!-- 乾燥貨櫃 參數設定-->
            <table style="border: 3px lightsteelblue solid; margin-right: auto; margin-left: auto; text-align: center; margin-top: 10px;" cellpadding="5" border="1">
                <tr>
                    <td>
                        入料儲豆槽<br>
                        參數設定
                    </td>
                    <td>
                        桶槽<br>
                        參數設定
                    </td>
                    <td>
                        出料儲豆槽<br>
                        參數設定
                    </td>
                </tr>
                <tr>
                    <td style="padding: 10px; text-align: left; vertical-align: text-top;">
                        吸料時間&nbsp; 
                        <input name="Dry_Input_vacuumON_time" type="text" value="10" style="width:50px;">&nbsp; 秒<br>
                        放料時間&nbsp; 
                        <input name="Dry_Input_vacuumOFF_time" type="text" value="10" style="width:50px;">&nbsp; 秒<br>
                    </td>
                    <td style="padding: 10px; text-align: left; vertical-align: text-top;">
                        指定生豆高度&nbsp; 
                        <input name="Dry_Tank_bean_height" type="text" value="100" style="width:50px;">&nbsp; 公分<br>
                        吸料時間&nbsp; 
                        <input name="Dry_Tank_vacuumON_time" type="text" value="10" style="width:50px;">&nbsp; 秒,&nbsp; 
                        放料時間&nbsp; 
                        <input name="Dry_Tank_vacuumOFF_time" type="text" value="10" style="width:50px;">&nbsp; 秒<br>
                        馬達轉速&nbsp; 
                        <input name="Dry_Tank_motor_rpm" type="text" value="30" style="width:50px;">&nbsp; rpm<br>
                        ----- 溫度權重設定 ----------------------------------------------<br>
                        [上]桶內溫度×權重&nbsp;
                        <input name="Dry_Tank_TempWeight_SHT11" type="text" value="0.5" style="width:50px;">
                        +
                        [下]生豆溫度×權重&nbsp; 
                        <input name="Dry_Tank_TempWeight_soil" type="text" value="0.5" style="width:50px;">
                        <br>
                        ----- 乾燥完成條件 (輸入 0 代表不設定) ------------------------<br>
                        指定乾燥溫度&nbsp; 
                        <input name="Dry_Tank_drying_temp" type="text" value="40" style="width:50px;">&nbsp; ℃
                        , 且指定持溫時間&nbsp; 
                        <input name="Dry_Tank_drying_time" type="text" value="30" style="width:50px;">&nbsp; 分鐘<br>
                        指定 EC &nbsp; 
                        <input name="Dry_Tank_drying_EC" type="text" value="300" style="width:50px;">&nbsp;&nbsp;/&nbsp;
                        指定濕度 &nbsp; 
                        <input name="Dry_Tank_drying_Humidity" type="text" value="30" style="width:50px;">&nbsp;%<br>
                    </td>
                    <td style="padding: 10px; text-align: left; vertical-align: text-top;">
                        吸料時間&nbsp; 
                        <input name="Dry_Output_vacuumON_time" type="text" value="10" style="width:50px;">&nbsp; 秒<br>
                        放料時間&nbsp; 
                        <input name="Dry_Output_vacuumOFF_time" type="text" value="10" style="width:50px;">&nbsp; 秒<br>
                    </td>
                </tr>
            </table>

            <center><button style="margin: 15px 10px 0px 10px;" type="submit" class="btn btn-primary" onclick="dry_auto()">
                [測試] MQTT + 每 60 秒更新貨櫃狀態</button></center>
            <script>
                function dry_auto(){
                    var Dry_Input_vacuumON_time = $("input[name=Dry_Input_vacuumON_time]").val();
                    var Dry_Input_vacuumOFF_time = $("input[name=Dry_Input_vacuumOFF_time]").val();
                    var Dry_Tank_bean_height = $("input[name=Dry_Tank_bean_height]").val();
                    var Dry_Tank_vacuumON_time = $("input[name=Dry_Tank_vacuumON_time]").val();
                    var Dry_Tank_vacuumOFF_time = $("input[name=Dry_Tank_vacuumOFF_time]").val();
                    var Dry_Tank_drying_temp = $("input[name=Dry_Tank_drying_temp]").val();
                    var Dry_Tank_drying_time = $("input[name=Dry_Tank_drying_time]").val();
                    var Dry_Tank_drying_EC = $("input[name=Dry_Tank_drying_EC]").val();
                    var Dry_Tank_motor_rpm = $("input[name=Dry_Tank_motor_rpm]").val();
                    var Dry_Tank_TempWeight_SHT11 = $("input[name=Dry_Tank_TempWeight_SHT11]").val();
                    var Dry_Tank_TempWeight_soil = $("input[name=Dry_Tank_TempWeight_soil]").val();
                    var Dry_Tank_drying_Humidity = $("input[name=Dry_Tank_drying_Humidity]").val();
                    var Dry_Output_vacuumON_time = $("input[name=Dry_Output_vacuumON_time]").val();
                    var Dry_Output_vacuumOFF_time = $("input[name=Dry_Output_vacuumOFF_time]").val();
                    
                    var data = { "command": "Dry_auto_parameter", 
                                 "Dry_Input_vacuumON_time": Dry_Input_vacuumON_time, 
                                 "Dry_Input_vacuumOFF_time": Dry_Input_vacuumOFF_time, 
                                 "Dry_Tank_bean_height": Dry_Tank_bean_height, 
                                 "Dry_Tank_vacuumON_time": Dry_Tank_vacuumON_time, 
                                 "Dry_Tank_vacuumOFF_time": Dry_Tank_vacuumOFF_time, 
                                 "Dry_Tank_drying_temp": Dry_Tank_drying_temp, 
                                 "Dry_Tank_drying_time": Dry_Tank_drying_time, 
                                 "Dry_Tank_drying_EC": Dry_Tank_drying_EC, 
                                 "Dry_Tank_motor_rpm": Dry_Tank_motor_rpm, 
                                 "Dry_Tank_TempWeight_SHT11": Dry_Tank_TempWeight_SHT11, 
                                 "Dry_Tank_TempWeight_soil": Dry_Tank_TempWeight_soil, 
                                 "Dry_Tank_drying_Humidity": Dry_Tank_drying_Humidity, 
                                 "Dry_Output_vacuumON_time": Dry_Output_vacuumON_time, 
                                 "Dry_Output_vacuumOFF_time": Dry_Output_vacuumOFF_time };

                    $.post('/mqtt/101', data, function (res) {
                        console.log('data: ', data)
                        console.log('res: ', res)

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

            <center><button style="margin: 15px 10px 0px 10px;" type="submit" class="btn btn-primary" onclick="testing_D_auto()">
                [測試] 乾燥貨櫃狀態</button></center>
            
            <script>
                function testing_D_auto(){
                    $.get('/dry_auto_status', '', function (res) {
                        Dry_Input_1_STATUS = res.Dry_Input_1
                        console.log('DI1: ' + res.Dry_Input_1)
                        console.log('D1: ' + res.Dry_Tank_1)
                        console.log('D2: ' + res.Dry_Tank_2)
                        console.log('D3: ' + res.Dry_Tank_3)
                        console.log('D4: ' + res.Dry_Tank_4)
                        console.log('D5: ' + res.Dry_Tank_5)
                        console.log('D6: ' + res.Dry_Tank_6)
                        console.log('DO1: ' + res.Dry_Output_1)

                        // ----- 乾燥入料 FI1 狀態 --------------------------------------------------------------
                        dry_input_status = [res.Dry_Input_1]
                        console.log('dry_input_status: ' + dry_input_status)
                        for (let i=0; i<dry_input_status.length; i++) {
                            // 顯示對應乾燥桶槽號碼 D1~D6 和目前狀態
                            // console.log(i+1 + ' : '+ dry_input_status[i])
                            // 1 : F_InputtingBean
                            // 2 : F_Waiting
                            if (dry_input_status[i] == 'DI_InputtingBean') {
                                console.log('[動作] 乾燥入料 DI' + parseInt(i+1) + ' 入豆中')
                                $("#DI"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                $("#DI"+parseInt(i+1)+"_status").text("DI" + parseInt(i+1) + " 入豆中")
                            } else if (dry_input_status[i] == 'DI_Waiting') {
                                console.log('[動作] 乾燥入料 DI' + parseInt(i+1) + ' 空桶等待')
                                $("#DI"+parseInt(i+1)+"_status_dot").css("background-color", "lightgray")
                                $("#DI"+parseInt(i+1)+"_status").text("DI" + parseInt(i+1) + " 空桶等待")
                            } else if (dry_input_status[i] == 'DI_OutputtingBean') {
                                console.log('[動作] 乾燥入料 DI' + parseInt(i+1) + ' 可出豆')
                                $("#DI"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                $("#DI"+parseInt(i+1)+"_status").text("DI" + parseInt(i+1) + " 可出豆")
                            } else {
                                console.log('pass')
                            }
                        }

                        // ----- 乾燥桶槽 F1~F6 狀態 --------------------------------------------------------------
                        dry_tank_status = [res.Dry_Tank_1, res.Dry_Tank_2, res.Dry_Tank_3, res.Dry_Tank_4, res.Dry_Tank_5, res.Dry_Tank_6]
                        console.log('dry_tank_status: ' + dry_tank_status)
                        for (let i=0; i<dry_tank_status.length; i++) {
                            // 顯示對應乾燥桶槽號碼 D1~D6 和目前狀態
                            // console.log(i+1 + ' : '+ dry_tank_status[i])
                            // 1 : D_InputtingBean
                            // 2 : D_Waiting
                            if (dry_tank_status[i] == 'D_InputtingBean') {
                                console.log('[動作] 乾燥桶槽 D' + parseInt(i+1) + ' 入豆中')
                                $("#D"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                $("#D"+parseInt(i+1)+"_status").text("D" + parseInt(i+1) + "  入豆中")
                            } else if (dry_tank_status[i] == 'D_InputtingBean_Pause') {
                                console.log('[動作] 乾燥桶槽 D' + parseInt(i+1) + ' 入豆暫停')
                                $("#D"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                $("#D"+parseInt(i+1)+"_status").text("D" + parseInt(i+1) + "  入豆暫停")
                            } else if (dry_tank_status[i] == 'D_InputtingBean_Finish') {
                                console.log('[動作] 乾燥桶槽 D' + parseInt(i+1) + ' 入豆完成')
                                $("#D"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                $("#D"+parseInt(i+1)+"_status").text("D" + parseInt(i+1) + "  入豆完成")
                            } else if (dry_tank_status[i] == 'D_Waiting') {
                                console.log('[動作] 乾燥桶槽 D' + parseInt(i+1) + ' 空桶等待')
                                $("#D"+parseInt(i+1)+"_status_dot").css("background-color", "lightgray")
                                $("#D"+parseInt(i+1)+"_status").text("D" + parseInt(i+1) + "  空桶等待")
                            } else if (dry_tank_status[i] == 'D_Cleaning') {
                                console.log('[動作] 乾燥桶槽 D' + parseInt(i+1) + ' 清洗中')
                                $("#D"+parseInt(i+1)+"_status_dot").css("background-color", "plum")
                                $("#D"+parseInt(i+1)+"_status").text("D" + parseInt(i+1) + "  清洗中")
                            } else if (dry_tank_status[i] == 'D_Drying') {
                                console.log('[動作] 乾燥桶槽 D' + parseInt(i+1) + ' 乾燥中')
                                $("#D"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                $("#D"+parseInt(i+1)+"_status").text("D" + parseInt(i+1) + "  乾燥中")
                            } else if (dry_tank_status[i] == 'D_OutputtingBean') {
                                console.log('[動作] 乾燥桶槽 D' + parseInt(i+1) + ' 可出豆')
                                $("#D"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                $("#D"+parseInt(i+1)+"_status").text("D" + parseInt(i+1) + "  可出豆")
                            } else if (dry_tank_status[i] == 'D_Warning') {
                                console.log('[動作] 乾燥桶槽 D' + parseInt(i+1) + ' 發生錯誤')
                                $("#D"+parseInt(i+1)+"_status_dot").css("background-color", "crimson")
                                $("#D"+parseInt(i+1)+"_status").text("D" + parseInt(i+1) + "  發生錯誤")
                                $("#D"+parseInt(i+1)+"_status").css("color", "crimson")
                            } else {
                                console.log('pass')
                            }
                        }

                        // ----- 乾燥出料 FO1 狀態 --------------------------------------------------------------
                        dry_output_status = [res.Dry_Output_1]
                        console.log('dry_output_status: ' + dry_output_status)
                        for (let i=0; i<dry_output_status.length; i++) {
                            // 顯示對應乾燥桶槽號碼 D1~D6 和目前狀態
                            // console.log(i+1 + ' : '+ dry_output_status[i])
                            // 1 : D_InputtingBean
                            // 2 : D_Waiting
                            if (dry_output_status[i] == 'DO_InputtingBean') {
                                console.log('[動作] 乾燥出料 DO' + parseInt(i+1) + ' 入豆中')
                                $("#DO"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                $("#DO"+parseInt(i+1)+"_status").text("DO" + parseInt(i+1) + " 入豆中")
                            } else if (dry_output_status[i] == 'DO_Waiting') {
                                console.log('[動作] 乾燥出料 DO' + parseInt(i+1) + ' 空桶等待')
                                $("#DO"+parseInt(i+1)+"_status_dot").css("background-color", "lightgray")
                                $("#DO"+parseInt(i+1)+"_status").text("DO" + parseInt(i+1) + " 空桶等待")
                            } else if (dry_output_statu[i] == 'DO_OutputtingBean') {
                                console.log('[動作] 乾燥出料 DO' + parseInt(i+1) + ' 可出豆')
                                $("#DO"+parseInt(i+1)+"_status_dot").css("background-color", "MediumSeaGreen")
                                $("#DO"+parseInt(i+1)+"_status").text("DO" + parseInt(i+1) + " 可出豆")
                            } else {
                                console.log('pass')
                            }
                        }

                        
                        /*
                        console.log(res.Dry_Input_2)
                        console.log(res.Dry_Tank_7)
                        console.log(res.Dry_Tank_8)
                        console.log(res.Dry_Tank_9)
                        console.log(res.Dry_Tank_10)
                        console.log(res.Dry_Tank_11)
                        console.log(res.Dry_Tank_12)
                        console.log(res.Dry_Output_1)
                        console.log(res.Dry_Output_2)
                        */
                    }, 'json');
                    // console.log("-- 自動化程式 end --")
                }
            </script>



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

</body>

</html>