wxr
2020-09-09 c3e1b733fc45bd9f0b88bfb560cfa87a270b079b
HDL_ON/UI/UI2/2-Classification/FunctionControlZoneBLL.cs
@@ -8,6 +8,56 @@
    public partial class FunctionControlZone
    {
        /// <summary>
        /// 更新开关状态
        /// </summary>
        /// <param name="upfunc"></param>
        public static void UpdataOnOffState(Function upfunc)
        {
            if(bodyDiv!= null)
            {
                Application.RunOnMainThread(() => {
                    if(bodyDiv.Tag.ToString() == upfunc.sid)
                    {
                        for (var o = 0; o < bodyDiv.ChildrenCount; o++)
                        {
                            if (bodyDiv.GetChildren(o).GetType() == typeof(Button))
                            {
                                var btn = bodyDiv.GetChildren(o) as Button;
                                if (btn.Tag != null)
                                {
                                    if (btn.Tag.ToString() == upfunc.sid + "_Switch")// + "_DimmerBar")
                                    {
                                        btn.IsSelected = upfunc.trait_on_off.value.ToString() == "on";
                                    }
                                }
                            }
                            else if (bodyDiv.GetChildren(o).GetType() == typeof(DiyImageSeekBar))
                            {
                                var btn = bodyDiv.GetChildren(o) as DiyImageSeekBar;
                                if (btn.Tag != null)
                                {
                                    if (btn.Tag.ToString() == upfunc.sid + "_DimmerBar")
                                    {
                                        //btn.Progress = (upfunc as Light).trait_brightness.value.value.ToString() == "on";
                                    }
                                }
                            }
                        }
                    }
                });
            }
        }
        /// <summary>
        /// 更新亮度状态
        /// </summary>
        /// <param name="upfunc"></param>
        static void UpdataBrightnessState(Function upfunc)
        {
        }
        /// <summary>
        /// 加载功能收藏按钮事件
        /// </summary>
        void LoadEvent_FunctionCollection()
@@ -83,40 +133,17 @@
        /// </summary>
        void LoadEvent_LightDimming(DiyImageSeekBar dimmerControlBar)
        {
            //if (function.functionType == FunctionType.Dimmer || function.functionType == FunctionType.RGB)
            //{
            //    if (dimmerControlBar == null)
            //        return;
            //    var light = function as Light;
            //    dimmerControlBar.OnProgressChangedEvent += (sender, e) =>
            //    {
            //        if ((DateTime.Now - light.refreshTime).TotalMilliseconds > 200)//调光命令发送间隔事件
            //        {
            //            new System.Threading.Thread(() =>
            //            {
            //                light.refreshTime = DateTime.Now;
            //                light.brightness = e;
            //                Control.Send(CommandType_A.write, function);
            //            })
            //            { IsBackground = true }.Start();
            //        }
            //    };
            //    dimmerControlBar.OnStopTrackingTouchEvent += (sender, e) =>
            //    {
            //        light.brightness = dimmerControlBar.Progress;
            //        Control.Send(CommandType_A.write, function);
            //    };
            //}
            if(function.functionType == FunctionType.Dimmer || function.functionType == FunctionType.RGB)
            {
                var light = function as Light;
                dimmerControlBar.OnStartTrackingTouchEvent = (sender, e) => {
                    onDimmerBar = true;
                    (bodyDiv.Parent as VerticalScrolViewLayout).ScrollEnabled = false;
                };
                dimmerControlBar.OnStopTrackingTouchEvent = (sender, e) => {
                    onDimmerBar = false;
                    (bodyDiv.Parent as VerticalScrolViewLayout).ScrollEnabled = true;
                    light.brightness = dimmerControlBar.Progress;
                    //Control.Send(CommandType_A.write, light);
                    System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
                    d.Add("brightness", light.brightness.ToString());
                    Control.SendWriteCommand(light, d);
@@ -134,25 +161,21 @@
                    }
                    else
                    {
                        if (200 < (DateTime.Now - light.refreshTime).TotalMilliseconds)
                        var tm = (DateTime.Now - light.refreshTime).TotalMilliseconds;
                        Console.WriteLine("skip time "+tm);
                        if (300 < tm)
                        {
                            light.refreshTime = DateTime.Now;
                            new System.Threading.Thread(() =>
                            {
                                //Control.Send(CommandType_A.write, light);
                                System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
                                d.Add("brightness", light.brightness.ToString());
                                Control.SendWriteCommand(light, d);
                            })
                            { IsBackground = true }.Start();
                        }
                        else
                        {
                            MainPage.Log("skip dimmer control!!");
                        }
                    }
                };
            }
        }