黄学彪
2020-09-01 dee21bf452a8979d0515d13e534fbb69ed9715dd
ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceMiniLightDetailCardForm.cs
@@ -43,10 +43,6 @@
        /// </summary>
        private bool isColorProgressing = false;
        /// <summary>
        /// 能否发送进度值
        /// </summary>
        private bool canSetProgressValue = true;
        /// <summary>
        /// 1:发送的是小夜灯  2:发送的是蜂鸣器
        /// </summary>
        private int sendDiv = 0;
@@ -140,7 +136,7 @@
            seekBarColor.ProgressChangeDelayTime = 0;
            frameWhiteBack.AddChidren(seekBarColor);
            //显示自定义文本
            seekBarColor.ShowCustomTextView(Application.GetRealWidth(150), 15, UserCenterColor.Current.TextGrayColor3);
            seekBarColor.ShowCustomTextView(Application.GetRealWidth(200), 15, UserCenterColor.Current.TextGrayColor3);
            //设置初始值
            int colorValue = ((ColorTemperatureLight)this.device).ColorTemperature;
            if (colorValue == 0) { colorValue = 3000; }
@@ -202,13 +198,6 @@
                this.SetLightSwitchCommand(!btnMiniSwitch.IsSelected);
            };
            btnMiniSwitch.IsSelected = ((LightBase)this.device).OnOffStatus == 1;
            this.canSetProgressValue = btnMiniSwitch.IsSelected;
            if (btnMiniSwitch.IsSelected == false)
            {
                //在没有打开夜灯开关之前,不允许滑动
                seekBarLight.Enable = false;
                seekBarColor.Enable = false;
            }
            //亮度开始滑动的事件
            seekBarLight.OnStartTrackingTouchEvent += (sender, e) =>
@@ -231,11 +220,8 @@
            {
                if (Common.Config.Instance.Home.IsVirtually == false)
                {
                    if (this.canSetProgressValue == true)
                    {
                        //能够发送进度值的时候,才记录
                        nowLightValue = value;
                    }
                    //能够发送进度值的时候,才记录
                    nowLightValue = value;
                }
                else
                {
@@ -270,11 +256,8 @@
                seekBarColor.SetCustomText(value * 100 + "K");
                if (Common.Config.Instance.Home.IsVirtually == false)
                {
                    if (this.canSetProgressValue == true)
                    {
                        //能够发送进度值的时候,才记录
                        nowColorValue = value;
                    }
                    //能够发送进度值的时候,才记录
                    nowColorValue = value;
                }
                else
                {
@@ -282,8 +265,13 @@
                    ((ColorTemperatureLight)this.device).ColorTemperature = value * 100;
                }
            };
            if (Config.Instance.Home.IsVirtually == true)
            {
                //虚拟住宅
                return;
            }
            //开一个线程,监视是否滑动的滑动条,每秒检测一次
                //开一个线程,监视是否滑动的滑动条,每秒检测一次
            HdlThreadLogic.Current.RunThread(() =>
            {
                while (this.Parent != null)
@@ -303,20 +291,17 @@
                        ((ColorTemperatureLight)this.device).SetColorTemperature(value);
                    }
                }
                if (this.canSetProgressValue == true)
                //界面关闭时
                if (nowLightValue != oldLightValue)
                {
                    //界面关闭时
                    if (nowLightValue != oldLightValue)
                    {
                        //发送亮度值
                        ((ColorTemperatureLight)this.device).SetLevel((int)(nowLightValue * MaxLevel / 100.0));
                    }
                    if (nowColorValue != oldColorValue)
                    {
                        //发送色温值
                        int value = 1000000 / (nowColorValue * 100);
                        ((ColorTemperatureLight)this.device).SetColorTemperature(value);
                    }
                    //发送亮度值
                    ((ColorTemperatureLight)this.device).SetLevel((int)(nowLightValue * MaxLevel / 100.0));
                }
                if (nowColorValue != oldColorValue)
                {
                    //发送色温值
                    int value = 1000000 / (nowColorValue * 100);
                    ((ColorTemperatureLight)this.device).SetColorTemperature(value);
                }
            });
        }
@@ -331,17 +316,21 @@
        /// <param name="isOpen"></param>
        private void SetLightSwitchCommand(bool isOpen)
        {
            //获取当前亮度
            int level = Convert.ToInt32(this.device.GetType().InvokeMember("Level", System.Reflection.BindingFlags.GetField, null, this.device, null));
            //如果住宅是虚拟住宅
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                ((LightBase)this.device).OnOffStatus = isOpen == true ? 1 : 0;
                if (((LightBase)this.device).OnOffStatus == 1 && level == 0)
                {
                    //如果当前是打开状态,并且亮度为0的话,则需要变成100%亮度
                    this.device.GetType().InvokeMember("Level", System.Reflection.BindingFlags.SetField, null, this.device, new object[] { 100 });
                }
                //刷新开关状态
                this.RefreshSwitchStatu(isOpen);
                return;
            }
            //当按下开关按钮时,不能再发送进度值
            this.canSetProgressValue = false;
            //检测是否获取网关反馈的结果,如果网关没有回复,则会弹出消息
            this.StartCheckResponeResult(new List<ButtonBase> { this.btnMiniSwitch.btnIcon }, (result) =>
@@ -354,18 +343,6 @@
                         bool statu = ((LightBase)this.device).OnOffStatus == 1;
                         //刷新开关状态
                         this.RefreshSwitchStatu(statu);
                         if (statu == true)
                         {
                             //当是打开状态时,网关说它会默认把亮度变成100%
                             //以防万一,这里再次读取一下
                             HdlThreadLogic.Current.RunThread(() =>
                             {
                                 ((ColorTemperatureLight)device).ReadLevel();
                                 System.Threading.Thread.Sleep(300);
                                 ((ColorTemperatureLight)device).ReadColorTemperature();
                             });
                         }
                     }
                 });
             });
@@ -374,7 +351,15 @@
            if (isOpen == true)
            {
                //打开
                this.device.SwitchControl(1);
                if (level == 0)
                {
                    //如果当前是打开状态,并且亮度为0的话,则需要变成100%亮度
                    this.device.GetType().InvokeMember("SetLevel", System.Reflection.BindingFlags.InvokeMethod, null, this.device, new object[] { 254 });
                }
                else
                {
                    this.device.SwitchControl(1);
                }
            }
            else
            {
@@ -490,41 +475,33 @@
            {
                //亮度是必须要刷新的  亮度 XX
                this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + "  " + HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
                if (this.isLightProgressing == false)
                {
                    //当进度值在手动变更中时,不接收推送
                    seekBarLight.Progress = (int)(((ColorTemperatureLight)this.device).Level * 1.0 / MaxLevel * 100);
                }
                if (this.isColorProgressing == false)
                {
                    //当进度值在手动变更中时,不接收推送
                    seekBarColor.Progress = (int)(((ColorTemperatureLight)this.device).ColorTemperature / 100);
                    //设置自定义的文本
                    seekBarColor.SetCustomText(seekBarColor.Progress * 100 + "K");
                }
                if (this.btnMiniSwitch.IsSelected == false)
                {
                    this.btnMiniSwitch.IsSelected = true;
                }
                //滑动条可以滑动
                seekBarLight.Enable = true;
                seekBarColor.Enable = true;
            }
            else
            {
                //变更字样:关闭
                this.SetStatuText(Language.StringByID(R.MyInternationalizationString.Close));
                if (this.btnMiniSwitch.IsSelected == true)
                {
                    this.btnMiniSwitch.IsSelected = false;
                    //变更字样:关闭
                    this.SetStatuText(Language.StringByID(R.MyInternationalizationString.Close));
                }
                //滑动条不可以滑动
                seekBarLight.Enable = false;
                seekBarColor.Enable = false;
            }
            //回复的结果说,处于打开状态才能发送
            this.canSetProgressValue = isOpen;
            if (this.isLightProgressing == false)
            {
                //当进度值在手动变更中时,不接收推送
                seekBarLight.Progress = (int)(((ColorTemperatureLight)this.device).Level * 1.0 / MaxLevel * 100);
            }
            if (this.isColorProgressing == false)
            {
                //当进度值在手动变更中时,不接收推送
                seekBarColor.Progress = (int)(((ColorTemperatureLight)this.device).ColorTemperature / 100);
                //设置自定义的文本
                seekBarColor.SetCustomText(seekBarColor.Progress * 100 + "K");
            }
        }
        #endregion