wei
2021-02-01 8da70e1a39328e1769b02bb1e05303916bb30eb5
HDL_ON/UI/UI2/FuntionControlView/Light/ColorTureLampPageBLL.cs
old mode 100755 new mode 100644
@@ -12,37 +12,43 @@
        /// </summary>
        public static void UpdataStates(Light uFunction)
        {
            Application.RunOnMainThread(() =>
            Application.RunOnMainThread((Action)(() =>
            {
                try
                {
                    if (bodyView == null)
                        return;
                    if (uFunction.functionType == bodyView.light.functionType && uFunction.sid == bodyView.light.sid)
                    if (uFunction.spk == bodyView.light.spk && uFunction.sid == bodyView.light.sid)
                    {
                        if (uFunction.trait_on_off.curValue.ToString() == "on")
                        {
                            bodyView.dimmerBar.SetProgressBarColors(CSS_Color.AuxiliaryColor1, CSS_Color.AuxiliaryColor1);
                            if (!bodyView.onDimmerBar)
                            {
                                bodyView.dimmerBar.Progress = uFunction.brightness;
                            }
                            bodyView.btnBrightnessText.Text = uFunction.brightness + "%";
                            bodyView.btnBrightnessText.Y = ((100 - uFunction.brightness) * Application.GetRealHeight(222 - 16 - 16) / 100) + Application.GetRealWidth(40);
                            }
                            bodyView.btnBrightnessText.Text = uFunction.brightness + "%";
                            bodyView.btnBrightnessText.Y = ((100 - uFunction.brightness) * Application.GetRealHeight(222 - 16) / 100) + Application.GetRealWidth(80);
                        }
                        else
                        {
                            bodyView.dimmerBar.SetProgressBarColors(CSS_Color.DividingLineColor, CSS_Color.DividingLineColor);
                        }
                        bodyView.btnSwitch.IsSelected = uFunction.trait_on_off.curValue.ToString() == "on";
                        bodyView.barColorTemplatrue.Enable = uFunction.trait_on_off.curValue.ToString() == "on";
                        var cct = 27;
                        int.TryParse(uFunction.Attr_CCT.curValue.ToString(), out cct);
                        bodyView.barColorTemplatrue.Progress = cct / 100;
                        //设置初始值
                        bodyView.barColorTemplatrue.SetCustomText(bodyView.barColorTemplatrue.Progress * 100 + "K");
                    }
                }
                catch (Exception ex)
                {
                    MainPage.Log($"{bodyView.GetType().Name } UpdataStates error : {ex.Message}");
                }
            });
            }));
        }
        void LoadEventList()
@@ -64,11 +70,11 @@
        /// </summary>
        void LoadEvet_ChangeFadeTime()
        {
            barFadeTime.OnProgressChangedEvent = (sender, e) =>
            {
                light.fadeTime = e;
                light.SaveFunctionData(true);
            };
            //barFadeTime.OnStopTrackingTouchEvent = (sender, e) =>
            //{
            //    light.fadeTime = e;
            //    light.SaveFunctionData(true);
            //};
        }
        /// <summary>
@@ -78,9 +84,29 @@
        {
            barColorTemplatrue.OnProgressChangedEvent += (sender, value) =>
            {
                //设置自定义的文本
                barColorTemplatrue.SetCustomText(value * 100 + "K");
                new System.Threading.Thread(() =>
                {
                    Application.RunOnMainThread(() =>
                    {
                        //设置自定义的文本
                        barColorTemplatrue.SetCustomText(value * 100 + "K");
                        light.Attr_CCT.curValue = value * 100;
                        //System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
                        //d.Add(FunctionAttributeKey.CCT, light.Attr_CCT.curValue.ToString());
                        //Control.Ins.SendWriteCommand(light, d);
                    });
                    //System.Threading.Thread.Sleep(200);
                }).Start();
            };
            barColorTemplatrue.OnStopTrackingTouchEvent = (sender, value) =>
            {
                light.Attr_CCT.curValue = value * 100;
                System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
                d.Add(FunctionAttributeKey.CCT, light.Attr_CCT.curValue.ToString());
                Control.Ins.SendWriteCommand(light, d);
            };
        }
        /// <summary>
@@ -90,7 +116,7 @@
        {
            btnCollection.MouseUpEventHandler += (sender, e) => {
                btnCollection.IsSelected = light.collect = btnCollection_Out.IsSelected = !btnCollection.IsSelected;
                light.SaveFunctionData(true);
                light.CollectFunction();
            };
        }
@@ -102,50 +128,59 @@
            dimmerBar.OnStartTrackingTouchEvent = (sender, e) => {
                onDimmerBar = true;
            };
            dimmerBar.OnStopTrackingTouchEvent = (sender, e) => {
            dimmerBar.OnStopTrackingTouchEvent = (sender, e) =>
            {
                onDimmerBar = false;
                light.brightness = dimmerBar.Progress;
                //Control.Send(CommandType_A.write, light);
                System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
                d.Add(FunctionAttributeKey.Brightness, light.brightness.ToString());
                Control.Ins.SendWriteCommand(light, d);
                light.fadeTime = barFadeTime.Progress;
                //light.fadeTime = barFadeTime.Progress;
                btnBrightnessText.Text = dimmerBar.Progress + "%";
                dimmerBar.SetProgressBarColors(CSS_Color.AuxiliaryColor1, CSS_Color.AuxiliaryColor1);
            };
            dimmerBar.OnProgressChangedEvent = (sender, e) => {
                light.fadeTime = 0;
                if (!btnSwitch.IsSelected)
                {
                    dimmerBar.SetProgressBarColors(CSS_Color.AuxiliaryColor1, CSS_Color.AuxiliaryColor1);
                }
                btnSwitch.IsSelected = e > 0 ? true : false;
                light.brightness = e;
                light.trait_on_off.curValue = e > 0 ? "on" : "off";
            dimmerBar.OnProgressChangedEvent = (sender, e) =>
            {
                dimmerBar.SetProgressBarColors(CSS_Color.AuxiliaryColor1, CSS_Color.AuxiliaryColor1);
                //light.fadeTime = 0;
                //if (!btnSwitch.IsSelected)
                //{
                //    dimmerBar.SetProgressBarColors(CSS_Color.AuxiliaryColor1, CSS_Color.AuxiliaryColor1);
                //}
                //btnSwitch.IsSelected = e > 0 ? true : false;
                //light.brightness = e;
                //light.trait_on_off.curValue = e > 0 ? "on" : "off";
                if (e == 0 || e == 100)
                {
                    //Control.Send(CommandType_A.write, this.light);
                    System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
                    d.Add(FunctionAttributeKey.Brightness, light.brightness.ToString());
                    Control.Ins.SendWriteCommand(light, d);
                }
                else
                {
                    if (200 < (DateTime.Now - light.refreshTime).TotalMilliseconds)
                    {
                        light.refreshTime = DateTime.Now;
                        new System.Threading.Thread(() =>
                        {
                            System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
                            d.Add(FunctionAttributeKey.Brightness, light.brightness.ToString());
                            Control.Ins.SendWriteCommand(light, d);
                        })
                        { IsBackground = true }.Start();
                    }
                }
                //if (e == 0 || e == 100)
                //{
                //    System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
                //    d.Add(FunctionAttributeKey.Brightness, light.brightness.ToString());
                //    Control.Ins.SendWriteCommand(light, d);
                //}
                //else
                //{
                //    if (200 < (DateTime.Now - light.refreshTime).TotalMilliseconds)
                //    {
                //        light.refreshTime = DateTime.Now;
                //        new System.Threading.Thread(() =>
                //        {
                //            System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
                //            d.Add(FunctionAttributeKey.Brightness, light.brightness.ToString());
                //            Control.Ins.SendWriteCommand(light, d);
                //        })
                //        { IsBackground = true }.Start();
                //    }
                //}
                btnBrightnessText.Y = ((100 - dimmerBar.Progress) * Application.GetRealHeight(222 - 16 - 16) / 100) + Application.GetRealWidth(40);
                btnBrightnessText.Text = light.brightness + "%";
                //btnBrightnessText.Y = ((100 - dimmerBar.Progress) * Application.GetRealHeight(222 - 16 - 16) / 100) + Application.GetRealWidth(40);
                //btnBrightnessText.Text = light.brightness + "%";
                btnBrightnessText.Y = ((100 - dimmerBar.Progress) * Application.GetRealHeight(222 - 16) / 100) + Application.GetRealWidth(80);
                btnBrightnessText.Text = dimmerBar.Progress + "%";
            };
        }
        /// <summary>
@@ -155,7 +190,7 @@
        {
            btnSwitch.MouseUpEventHandler += (sender, e) =>
            {
                light.fadeTime = barFadeTime.Progress;
                //light.fadeTime = barFadeTime.Progress;
                btnSwitch.IsSelected = !btnSwitch.IsSelected;
                if (btnSwitch.IsSelected)
                {
@@ -170,6 +205,7 @@
                    light.trait_on_off.curValue = btnSwitch.IsSelected ? "on" : "off";
                    System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
                    d.Add(FunctionAttributeKey.OnOff, light.trait_on_off.curValue.ToString());
                    d.Add(FunctionAttributeKey.FadeTime, light.fadeTime.ToString());
                    if (btnSwitch.IsSelected)
                    {
                        d.Add(FunctionAttributeKey.Brightness, light.lastBrightness.ToString());