wxr
2020-04-21 f718d23a262a5a8e1241fdeaeb4153399f95e79d
HDL_ON/UI/UI2/2-Classification/FunctionControlZoneBLL.cs
@@ -76,31 +76,69 @@
        /// </summary>
        void LoadEvent_LightDimming(DiyImageSeekBar dimmerControlBar)
        {
            if (function.functionType == FunctionType.Dimmer || function.functionType == FunctionType.RGB)
            //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)
            {
                if (dimmerControlBar == null)
                    return;
                var light = function as Light;
                dimmerControlBar.OnProgressChangedEvent += (sender, e) =>
                {
                    if ((DateTime.Now - light.refreshTime).TotalMilliseconds > 200)//调光命令发送间隔事件
                dimmerControlBar.OnStartTrackingTouchEvent = (sender, e) => {
                    onDimmerBar = true;
                };
                dimmerControlBar.OnStopTrackingTouchEvent = (sender, e) => {
                    onDimmerBar = false;
                    light.brightness = dimmerControlBar.Progress;
                    Control.Send(CommandType_A.write, light);
                };
                dimmerControlBar.OnProgressChangedEvent = (sender, e) => {
                    light.brightness = e;
                    light.on_off = e > 0 ? "on" : "off";
                    if (e == 0 || e == 100)
                    {
                        new System.Threading.Thread(() =>
                        Control.Send(CommandType_A.write, light);
                    }
                    else
                    {
                        if (200 < (DateTime.Now - light.refreshTime).TotalMilliseconds)
                        {
                            light.refreshTime = DateTime.Now;
                            light.brightness = e;
                            Control.Send(CommandType_A.write, function);
                        })
                        { IsBackground = true }.Start();
                            new System.Threading.Thread(() =>
                            {
                                Control.Send(CommandType_A.write, light);
                            })
                            { IsBackground = true }.Start();
                        }
                        else
                        {
                            MainPage.Log("skip dimmer control!!");
                        }
                    }
                };
                dimmerControlBar.OnStopTrackingTouchEvent += (sender, e) =>
                {
                    light.brightness = dimmerControlBar.Progress;
                    Control.Send(CommandType_A.write, function);
                };
            }
        }
        #endregion