HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-01-09 fa6bcb2e9907772480f99205f36ec2a1ce735a22
ZigbeeApp/Shared/Phone/UserCenter/Device/AirConditioner/IndoorUnitSettionForm.cs
@@ -20,6 +20,14 @@
        /// 当前选择的网关
        /// </summary>
        private AC deviceAc = null;
        /// <summary>
        /// 摆风模式(用二进制来玩自定义模式 0:不使用 1:使用)
        /// </summary>
        private int swingMode = 0;
        /// <summary>
        /// 固定预留的数据
        /// </summary>
        private string fixValue = null;
        #endregion
@@ -39,8 +47,27 @@
            //初始化右上角菜单
            this.InitTopRightMenu();
            //初始化中部控件
            this.InitMiddleFrame();
            HdlThreadLogic.Current.RunThread(() =>
            {
                //开启进度条
                this.ShowProgressBar();
                //读取空调摆风模式
                var result = this.ReadAirConditionerSwingModeSupport();
                if (result == false)
                {
                    //关闭进度条
                    this.CloseProgressBar(ShowReLoadMode.YES);
                    return;
                }
                //关闭进度条
                this.CloseProgressBar();
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //初始化中部控件
                    this.InitMiddleFrame();
                });
            });
        }
        /// <summary>
@@ -125,6 +152,43 @@
                form.AddForm(deviceAc);
            };
            //摆风
            var rowSwing = new FrameRowControl(listview.rowSpace / 2);
            rowSwing.UseClickStatu = false;
            listview.AddChidren(rowSwing);
            rowSwing.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uAirConditionerSwing), 400);
            rowSwing.AddBottomLine();
            var btnSwingSwitch = rowSwing.AddMostRightSwitchIcon();
            if (this.swingMode == 1)
            {
                btnSwingSwitch.IsSelected = true;
            }
            btnSwingSwitch.ButtonClickEvent += (sender, e) =>
            {
                //不能再点击
                btnSwingSwitch.CanClick = false;
                string statu = btnSwingSwitch.IsSelected == true ? "1" : "0";
                //将二进制转换为十进制
                int sendData = Convert.ToInt32(this.fixValue + statu, 2);
                HdlThreadLogic.Current.RunThread(async () =>
                {
                    var result = await HdlDeviceAirConditionerLogic.Current.SetUseAcSwingFunctionStatu(deviceAc, sendData);
                    if (result == true)
                    {
                        HdlThreadLogic.Current.RunMain(() =>
                        {
                            btnSwingSwitch.IsSelected = !btnSwingSwitch.IsSelected;
                            this.swingMode = this.swingMode == 1 ? 0 : 1;
                            deviceAc.UseSwingFunction = btnSwingSwitch.IsSelected;
                            deviceAc.ReSave();
                        });
                    }
                    //能够继续点击
                    btnSwingSwitch.CanClick = true;
                });
            };
            //初始化桌布完成
            tableContr.FinishInitControl(bodyFrameLayout, this.listview);
            tableContr = null;
@@ -191,5 +255,56 @@
        }
        #endregion
        #region ■ 读取空调摆风模式___________________
        /// <summary>
        /// 读取空调摆风模式
        /// </summary>
        private bool ReadAirConditionerSwingModeSupport()
        {
            string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(deviceAc);
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("ReadAirConditionerModeSupport", ReceiveComandDiv.A设备属性上报, (report) =>
            {
                string checkKeys = Common.LocalDevice.Current.GetDeviceMainKeys(report);
                if (checkKeys != mainkeys || report.DeviceStatusReport.CluterID != 514)
                {
                    return;
                }
                for (int i = 0; i < report.DeviceStatusReport.AttriBute.Count; i++)
                {
                    var data = report.DeviceStatusReport.AttriBute[i];
                    if (data.AttributeId == 4097)
                    {
                        HdlGatewayReceiveLogic.Current.RemoveEvent("ReadAirConditionerModeSupport");
                        //转换为二进制
                        var value = Convert.ToString(data.AttriButeData, 2).PadLeft(16, '0');
                        //这个设置是放在后面的
                        this.fixValue = value.Substring(0, value.Length - 15);
                        this.swingMode = Convert.ToInt32(value.Substring(this.fixValue.Length));
                    }
                }
            });
            //获取是否启用空调摆风模式的状态(打开 或者 关闭)
            deviceAc.ReadUseSwingFunctionStatu();
            int timeOut = 0;
            while (this.fixValue == null && timeOut <= 30)
            {
                System.Threading.Thread.Sleep(100);
                timeOut++;
            }
            if (this.fixValue == null)
            {
                //获取空调摆风状态失败
                string msg = Language.StringByID(R.MyInternationalizationString.uGetAirConditionerSwingFunctionFail);
                msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
                this.ShowMassage(ShowMsgType.Tip, msg);
                return false;
            }
            return true;
        }
        #endregion
    }
}