HDL Home App 第二版本 旧平台金堂用 正在使用
hxb
2022-08-30 25429f085093d89d543a0b90e30d0d62d1b7dac9
ZigbeeApp/Shared/Phone/MainPage/ControlForm/DeviceMiniLightDetailCardForm.cs
@@ -31,10 +31,6 @@
        /// </summary>
        private SeekBarControl seekBarColor = null;
        /// <summary>
        /// MaxLevel
        /// </summary>
        private const int MaxLevel = 254;
        /// <summary>
        /// 亮度进度值是否在改变中
        /// </summary>
        private bool isLightProgressing = false;
@@ -42,10 +38,6 @@
        /// 色温进度值是否在改变中
        /// </summary>
        private bool isColorProgressing = false;
        /// <summary>
        /// 能否发送进度值
        /// </summary>
        private bool canSetProgressValue = true;
        /// <summary>
        /// 1:发送的是小夜灯  2:发送的是蜂鸣器
        /// </summary>
@@ -102,7 +94,7 @@
            seekBarLight.ProgressTextSize = 14;
            seekBarLight.ProgressTextColor = UserCenterColor.Current.TextGrayColor2;
            seekBarLight.Gravity = Gravity.Frame;
            seekBarLight.Progress = (int)(((ColorTemperatureLight)this.device).Level * 1.0 / MaxLevel * 100);
            seekBarLight.Progress = HdlDeviceCommonLogic.Current.CalculateLightLevelPersent(((ColorTemperatureLight)this.device).Level);
            frameWhiteBack.AddChidren(seekBarLight);
            //色温
@@ -140,7 +132,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 +194,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,16 +216,13 @@
            {
                if (Common.Config.Instance.Home.IsVirtually == false)
                {
                    if (this.canSetProgressValue == true)
                    {
                        //能够发送进度值的时候,才记录
                        nowLightValue = value;
                    }
                    //能够发送进度值的时候,才记录
                    nowLightValue = value;
                }
                else
                {
                    //如果住宅为虚拟住宅,直接改缓存
                    ((ColorTemperatureLight)this.device).Level = value * MaxLevel / 100;
                    ((ColorTemperatureLight)this.device).Level = HdlDeviceCommonLogic.Current.CalculateLightLevel(value);
                    //亮度 XX
                    this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + "  " + HdlDeviceOtherLogic.Current.GetDeviceStatu(this.device));
                }
@@ -270,11 +252,8 @@
                seekBarColor.SetCustomText(value * 100 + "K");
                if (Common.Config.Instance.Home.IsVirtually == false)
                {
                    if (this.canSetProgressValue == true)
                    {
                        //能够发送进度值的时候,才记录
                        nowColorValue = value;
                    }
                    //能够发送进度值的时候,才记录
                    nowColorValue = value;
                }
                else
                {
@@ -282,8 +261,13 @@
                    ((ColorTemperatureLight)this.device).ColorTemperature = value * 100;
                }
            };
            if (Config.Instance.Home.IsVirtually == true)
            {
                //虚拟住宅
                return;
            }
            //开一个线程,监视是否滑动的滑动条,每秒检测一次
                //开一个线程,监视是否滑动的滑动条,每秒检测一次
            HdlThreadLogic.Current.RunThread(() =>
            {
                while (this.Parent != null)
@@ -293,7 +277,7 @@
                    if (nowLightValue != oldLightValue)
                    {
                        oldLightValue = nowLightValue;
                        ((ColorTemperatureLight)this.device).SetLevel((int)(oldLightValue * MaxLevel / 100.0));
                        ((ColorTemperatureLight)this.device).SetLevel(HdlDeviceCommonLogic.Current.CalculateLightLevel(oldLightValue));
                    }
                    //发送色温值
                    if (nowColorValue != oldColorValue)
@@ -303,20 +287,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(HdlDeviceCommonLogic.Current.CalculateLightLevel(nowLightValue));
                }
                if (nowColorValue != oldColorValue)
                {
                    //发送色温值
                    int value = 1000000 / (nowColorValue * 100);
                    ((ColorTemperatureLight)this.device).SetColorTemperature(value);
                }
            });
        }
@@ -331,17 +312,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 +339,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 +347,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[] { 255 });
                }
                else
                {
                    this.device.SwitchControl(1);
                }
            }
            else
            {
@@ -490,41 +471,37 @@
            {
                //亮度是必须要刷新的  亮度 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)
            {
                //当进度值在手动变更中时,不接收推送
                int progress = HdlDeviceCommonLogic.Current.CalculateLightLevelPersent(((ColorTemperatureLight)this.device).Level);
                if (seekBarLight.Progress != progress)
                {
                    seekBarLight.Progress = progress;
                }
            }
            if (this.isColorProgressing == false)
            {
                //当进度值在手动变更中时,不接收推送
                seekBarColor.Progress = (int)(((ColorTemperatureLight)this.device).ColorTemperature / 100);
                //设置自定义的文本
                seekBarColor.SetCustomText(seekBarColor.Progress * 100 + "K");
            }
        }
        #endregion