| | |
| | | namespace HDL_ON.UI
|
| | | {
|
| | | public partial class ColorTureLampPage
|
| | | {
|
| | | { |
| | | /// <summary> |
| | | /// 通知更新界面的时间 |
| | | /// </summary> |
| | | DateTime notiyUpdateTime = DateTime.MinValue; |
| | | System.Threading.Thread updateUiThread; |
| | | object lockObj = new object();
|
| | | /// <summary>
|
| | | /// 更新功能状态
|
| | | /// </summary>
|
| | | public static void UpdataStatus(Function updataTemp)
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | {
|
| | | try
|
| | | {
|
| | | if (bodyView == null)
|
| | | return;
|
| | | if (updataTemp.spk == bodyView.function.spk && updataTemp.sid == bodyView.function.sid)
|
| | | {
|
| | | if (updataTemp.trait_on_off.curValue.ToString() == "on")
|
| | | {
|
| | | bodyView.dimmerBar.SetProgressBarColors(CSS_Color.AuxiliaryColor1, CSS_Color.AuxiliaryColor1);
|
| | | if (!bodyView.onDimmerBar)
|
| | | {
|
| | | bodyView.dimmerBar.Progress = Convert.ToInt32(updataTemp.GetAttrState(FunctionAttributeKey.Brightness));
|
| | | }
|
| | | if (updataTemp.GetAttrState(FunctionAttributeKey.Brightness) != "0")
|
| | | {
|
| | | bodyView.btnBrightnessText.Text = updataTemp.GetAttrState(FunctionAttributeKey.Brightness) + "%";
|
| | | bodyView.btnBrightnessText.Y = ((100 - Convert.ToInt32(updataTemp.GetAttrState(FunctionAttributeKey.Brightness))) * Application.GetRealHeight(222 - 16) / 100) + Application.GetRealWidth(80);
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | bodyView.dimmerBar.SetProgressBarColors(CSS_Color.DividingLineColor, CSS_Color.DividingLineColor);
|
| | | }
|
| | | bodyView.btnSwitch.IsSelected = updataTemp.trait_on_off.curValue.ToString() == "on";
|
| | | bodyView.barColorTemplatrue.Enable = updataTemp.trait_on_off.curValue.ToString() == "on";
|
| | | var cct = 27;
|
| | | int.TryParse(updataTemp.GetAttrState(FunctionAttributeKey.CCT), 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}");
|
| | | }
|
| | | });
|
| | | { |
| | | if(bodyView == null) |
| | | { |
| | | return; |
| | | } |
| | | lock (bodyView.lockObj) |
| | | { |
| | | MainPage.Log($"收到更新" + DateTime.Now.Ticks); |
| | | bodyView.notiyUpdateTime = DateTime.Now; |
| | | if (bodyView.updateUiThread == null) |
| | | { |
| | | bodyView.updateUiThread = new System.Threading.Thread(() => |
| | | { |
| | | while (true) |
| | | { |
| | | System.Threading.Thread.Sleep(1500); |
| | | if (bodyView == null) |
| | | { |
| | | return; |
| | | } |
| | | if (DateTime.Now.AddMilliseconds(-1500) > bodyView.notiyUpdateTime) |
| | | { |
| | | MainPage.Log("没有新数据,更新UI"); |
| | | break; |
| | | } |
| | | else |
| | | { |
| | | MainPage.Log("有新数据,继续等待"); |
| | | } |
| | | } |
| | | |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | try |
| | | { |
| | | if (bodyView == null) |
| | | return; |
| | | if (updataTemp.spk == bodyView.function.spk && updataTemp.sid == bodyView.function.sid) |
| | | { |
| | | if (updataTemp.trait_on_off.curValue.ToString() == "on") |
| | | { |
| | | bodyView.dimmerBar.SetProgressBarColors(CSS_Color.AuxiliaryColor1, CSS_Color.AuxiliaryColor1); |
| | | if (!bodyView.onDimmerBar) |
| | | { |
| | | bodyView.dimmerBar.Progress = Convert.ToInt32(updataTemp.GetAttrState(FunctionAttributeKey.Brightness)); |
| | | } |
| | | if (updataTemp.GetAttrState(FunctionAttributeKey.Brightness) != "0") |
| | | { |
| | | bodyView.btnBrightnessText.Text = updataTemp.GetAttrState(FunctionAttributeKey.Brightness) + "%"; |
| | | bodyView.btnBrightnessText.Y = ((100 - Convert.ToInt32(updataTemp.GetAttrState(FunctionAttributeKey.Brightness))) * Application.GetRealHeight(222 - 16) / 100) + Application.GetRealWidth(80); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | bodyView.dimmerBar.SetProgressBarColors(CSS_Color.DividingLineColor, CSS_Color.DividingLineColor); |
| | | } |
| | | bodyView.btnSwitch.IsSelected = updataTemp.trait_on_off.curValue.ToString() == "on"; |
| | | bodyView.barColorTemplatrue.Enable = updataTemp.trait_on_off.curValue.ToString() == "on"; |
| | | var cct = 27; |
| | | int.TryParse(updataTemp.GetAttrState(FunctionAttributeKey.CCT), 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}"); |
| | | } |
| | | finally |
| | | { |
| | | bodyView.updateUiThread = null; |
| | | } |
| | | |
| | | }); |
| | | |
| | | bodyView.updateUiThread.IsBackground = true; |
| | | bodyView.updateUiThread.Start(); |
| | | }); |
| | | } |
| | | } |
| | | }
|
| | |
|
| | | void LoadEventList()
|
| | |
| | | curDimmerStatus = onDimmerBar = true;
|
| | | };
|
| | | dimmerBar.OnProgressChangedEvent = (sender, e) =>
|
| | | {
|
| | | //dimmerBar.SetProgressBarColors(CSS_Color.AuxiliaryColor1, CSS_Color.AuxiliaryColor1);
|
| | | if (!btnSwitch.IsSelected)
|
| | | { |
| | | //dimmerBar.SetProgressBarColors(CSS_Color.AuxiliaryColor1, CSS_Color.AuxiliaryColor1); |
| | | if (!btnSwitch.IsSelected)
|
| | | {
|
| | | dimmerBar.SetProgressBarColors(CSS_Color.AuxiliaryColor1, CSS_Color.AuxiliaryColor1);
|
| | | }
|
| | |
| | | d.Add(FunctionAttributeKey.Brightness, e.ToString());
|
| | | Control.Ins.SendWriteCommand(function, d);
|
| | | }
|
| | | else
|
| | | {
|
| | | if (350 < (DateTime.Now - function.refreshTime).TotalMilliseconds)
|
| | | {
|
| | | function.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, e.ToString());
|
| | | Control.Ins.SendWriteCommand(function, d);
|
| | | })
|
| | | { IsBackground = true }.Start();
|
| | | }
|
| | | }
|
| | | //else
|
| | | //{
|
| | | // if (350 < (DateTime.Now - function.refreshTime).TotalMilliseconds)
|
| | | // {
|
| | | // function.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, e.ToString());
|
| | | // Control.Ins.SendWriteCommand(function, d);
|
| | | // })
|
| | | // { IsBackground = true }.Start();
|
| | | // }
|
| | | //}
|
| | |
|
| | |
|
| | | btnBrightnessText.Y = ((100 - dimmerBar.Progress) * Application.GetRealHeight(222 - 16) / 100) + Application.GetRealWidth(80);
|