From 965290476c027deb96891cde1095d9a100581a6b Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期四, 20 二月 2020 09:13:32 +0800 Subject: [PATCH] 2020-02-20 1.优化更新。 --- Crabtree/SmartHome/UI/SimpleControl/Phone/Light/UserLightPage.cs | 119 ++++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 89 insertions(+), 30 deletions(-) diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Light/UserLightPage.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Light/UserLightPage.cs index 41a7e05..dad8fa1 100644 --- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Light/UserLightPage.cs +++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Light/UserLightPage.cs @@ -279,11 +279,20 @@ btnSceneRemark.MouseUpEventHandler += (sender, e) => { try { + if (CommonPage.IsRemote) { + if (!SmartHome.MqttCommon.IsGatewayOnline) { + new Alert ("", "Gateway offline" + ErrorCode.ControlFailure, "Close").Show (); + return; + } + } btnLastClickScene.RemoveFromParent (); lightSceneView.AddChidren (btnLastClickScene); - MainPage.Loading.Start (); + //MainPage.Loading.Start (); + MainPage.Loading.Start ("Sending..."); + int controlDeviceIndex = 0; System.Threading.Tasks.Task.Run (() => { foreach (var deviceFilePath in scene.DeviceFilePathList) { + controlDeviceIndex++; if (deviceFilePath.Split ('_') [1] == DeviceType.LightDimming.ToString ()) { var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightDimming> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); if (device == null) { @@ -305,13 +314,15 @@ } } } - Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, 0, delayTime }); + byte [] returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, 0, delayTime }); + ShowErrorTip (returnBytes, device, "..." + controlDeviceIndex.ToString () + @"/" + scene.DeviceFilePathList.Count.ToString ()); } else if (deviceFilePath.Split ('_') [1] == DeviceType.LightSwitch.ToString ()) { var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); if (device == null) { continue; } - Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, 0, 0 }); + byte [] returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, 0, 0 }); + ShowErrorTip (returnBytes, device, "..." + controlDeviceIndex.ToString () + @"/" + scene.DeviceFilePathList.Count.ToString ()); } else if (deviceFilePath.Split ('_') [1] == DeviceType.LightLogic.ToString ()) { var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightLogic> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); if (device != null) { @@ -339,12 +350,47 @@ } } } + + Application.RunOnMainThread (() => { + MainPage.Loading.Hide (); + }); }); - } catch { } finally { + } catch { MainPage.Loading.Hide (); + } finally { + //MainPage.Loading.Hide (); } }; } + } + + void ShowErrorTip (byte[] replyBytes, Common mCommon, string mes) + { + try { + + if (replyBytes == null) { + Application.RunOnMainThread (() => { + string tipString = Language.StringByID (R.MyInternationalizationString.ControlFailure); + var btnTip = new Button () { + Height = Application.GetRealHeight (140), + Text = mCommon.Name + tipString + mes, + BackgroundColor = SkinStyle.Current.TitileView, + }; + MainPage.MainFrameLayout.AddChidren (btnTip); + btnTip.MouseUpEventHandler += (sender, e) => { + btnTip.RemoveFromParent (); + }; + System.Threading.Tasks.Task.Run (() => { + System.Threading.Thread.Sleep (3000); + Application.RunOnMainThread (() => { + btnTip.RemoveFromParent (); + }); + }); + + }); + } + } catch { } + } void LightSceneDialog (Scene scene = null) @@ -603,9 +649,9 @@ }; lightView.AddTag ("UpdataKey", common.CommonLoopID); lightListView.AddChidren (lightView); - Button BtnLightViewNull = new Button () { - Y = Application.GetRealHeight(127), - Height = Application.GetRealHeight(3), + Button BtnLightViewNull = new Button () { + Y = Application.GetRealHeight (127), + Height = Application.GetRealHeight (3), BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.MainColor, }; @@ -633,16 +679,21 @@ }; lightView.AddChidren (tempSiwtch); tempSiwtch.MouseUpEventHandler += (sender3, e3) => { - tempSiwtch.IsSelected = !tempSiwtch.IsSelected; - if (tempSiwtch.IsSelected) { - lightSwitch.CurrentBrightness = 100; - } else { - lightSwitch.CurrentBrightness = 0; - } + //tempSiwtch.IsSelected = !tempSiwtch.IsSelected; + //if (tempSiwtch.IsSelected) { + // lightSwitch.CurrentBrightness = 100; + //} else { + // lightSwitch.CurrentBrightness = 0; + //} + int mSetBrightness = tempSiwtch.IsSelected ? 0 : 100; if (lightSwitch.Type == DeviceType.LightMixSwitch) { - Control.ControlBytesSend (Command.SetSingleLight, lightSwitch.SubnetID, lightSwitch.DeviceID, new byte [] { (lightSwitch as LightMixSwitch).PhysicsLoopID, (byte)lightSwitch.CurrentBrightness, lightSwitch.DelayTimeHeight, lightSwitch.DelayTimeLow }); - } else - Control.ControlBytesSend (Command.SetSingleLight, lightSwitch.SubnetID, lightSwitch.DeviceID, new byte [] { lightSwitch.LoopID, lightSwitch.CurrentBrightness, lightSwitch.DelayTimeHeight, lightSwitch.DelayTimeLow }); + SendControl.SendControlSetSingleLight (lightSwitch, new byte [] { (lightSwitch as LightMixSwitch).PhysicsLoopID, (byte)mSetBrightness, lightSwitch.DelayTimeHeight, lightSwitch.DelayTimeLow }); + //Control.ControlBytesSend (Command.SetSingleLight, lightSwitch.SubnetID, lightSwitch.DeviceID, new byte [] { (lightSwitch as LightMixSwitch).PhysicsLoopID, (byte)lightSwitch.CurrentBrightness, lightSwitch.DelayTimeHeight, lightSwitch.DelayTimeLow }); + } else { + //Control.ControlBytesSend (Command.SetSingleLight, lightSwitch.SubnetID, lightSwitch.DeviceID, new byte [] { lightSwitch.LoopID, lightSwitch.CurrentBrightness, lightSwitch.DelayTimeHeight, lightSwitch.DelayTimeLow }); + SendControl.SendControlSetSingleLight (lightSwitch, new byte [] { lightSwitch.LoopID, (byte)mSetBrightness, lightSwitch.DelayTimeHeight, lightSwitch.DelayTimeLow }); + + } }; if (lightSwitch.CurrentBrightness == 100) { @@ -1039,21 +1090,25 @@ tempLightSeekBar.AddTag ("UpdataKey", lightDimming.CommonLoopID); tempSwitch.MouseUpEventHandler += (sender3, e3) => { - tempSwitch.IsSelected = !tempSwitch.IsSelected; + //tempSwitch.IsSelected = !tempSwitch.IsSelected; if (lightDimming.LastOpenBrightness == 0) { lightDimming.LastOpenBrightness = 100; } - if (tempSwitch.IsSelected) { - tempLightSeekBar.Progress = lightDimming.LastOpenBrightness; - IO.FileUtils.WriteFileByBytes ("Equipment_" + typeof (LightDimming).Name + "_" + lightDimming.SubnetID.ToString () + "_" + lightDimming.DeviceID.ToString () + "_" + (lightDimming.LoopID < 10 ? "0" + lightDimming.LoopID.ToString () : lightDimming.LoopID.ToString ()), - CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (lightDimming))); - } else { - tempLightSeekBar.Progress = 0; - } - lightDimming.CurrentBrightness = (byte)tempLightSeekBar.Progress; + //if (!tempSwitch.IsSelected) { + // lightDimming.CurrentBrightness = lightDimming.LastOpenBrightness; + // //tempLightSeekBar.Progress = lightDimming.LastOpenBrightness; + // IO.FileUtils.WriteFileByBytes ("Equipment_" + typeof (LightDimming).Name + "_" + lightDimming.SubnetID.ToString () + "_" + lightDimming.DeviceID.ToString () + "_" + (lightDimming.LoopID < 10 ? "0" + lightDimming.LoopID.ToString () : lightDimming.LoopID.ToString ()), + // CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (lightDimming))); + //} else { + // //tempLightSeekBar.Progress = 0; + // lightDimming.CurrentBrightness = 0; + //} + //lightDimming.CurrentBrightness = (byte)tempLightSeekBar.Progress; + + int mSetBrightness = tempSwitch.IsSelected ? 0 : lightDimming.LastOpenBrightness; byte delayHeight = 0; byte delayLow = 0; - if (lightDimming.CurrentBrightness == 0) { + if (mSetBrightness == 0) { delayHeight = Convert.ToByte (lightDimming.CustomDelayTimeClose / 256); delayLow = Convert.ToByte (lightDimming.CustomDelayTimeClose % 256); } else { @@ -1061,10 +1116,14 @@ delayLow = Convert.ToByte (lightDimming.CustomDelayTimeOpen % 256); } if (lightDimming.Type == DeviceType.LightMixDimming) { - Control.ControlBytesSend (Command.SetSingleLight, lightDimming.SubnetID, lightDimming.DeviceID, new byte [] { (lightDimming as LightMixDimming).PhysicsLoopID, (byte)tempLightSeekBar.Progress, delayHeight, delayLow }, SendCount.Zero); - } else - Control.ControlBytesSend (Command.SetSingleLight, lightDimming.SubnetID, lightDimming.DeviceID, new byte [] { lightDimming.LoopID, (byte)tempLightSeekBar.Progress, delayHeight, delayLow }, SendCount.Zero); - tempLightSeekBar.Progress = lightDimming.CurrentBrightness; + SendControl.SendControlSetSingleLight (lightDimming, new byte [] { (lightDimming as LightMixDimming).PhysicsLoopID, (byte)mSetBrightness, delayHeight, delayLow }); + //Control.ControlBytesSend (Command.SetSingleLight, lightDimming.SubnetID, lightDimming.DeviceID, new byte [] { (lightDimming as LightMixDimming).PhysicsLoopID, (byte)tempLightSeekBar.Progress, delayHeight, delayLow }, SendCount.Zero); + } else { + //Control.ControlBytesSend (Command.SetSingleLight, lightDimming.SubnetID, lightDimming.DeviceID, new byte [] { lightDimming.LoopID, (byte)tempLightSeekBar.Progress, delayHeight, delayLow }, SendCount.Zero); + SendControl.SendControlSetSingleLight (lightDimming, new byte [] { lightDimming.LoopID, (byte)mSetBrightness, delayHeight, delayLow }); + + } + //tempLightSeekBar.Progress = lightDimming.CurrentBrightness; }; if (lightDimming.CurrentBrightness > 0) { -- Gitblit v1.8.0