From 5a5a2b696866f947b6025d26c3302e8ffef46435 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期一, 11 一月 2021 16:11:20 +0800 Subject: [PATCH] 2021-01-11 1.更新MQTT连接和本地搜索网关方法。2.子账号相关接口完善 --- Crabtree/SmartHome/UI/SimpleControl/Phone/Room/UserRoom.cs | 432 ++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 292 insertions(+), 140 deletions(-) diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Room/UserRoom.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Room/UserRoom.cs index e514a4b..bc97f19 100644 --- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Room/UserRoom.cs +++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Room/UserRoom.cs @@ -59,11 +59,13 @@ if (btn.Tag.ToString () == DeviceType.LightEnergySocket.ToString () + "_Voltage" || btn.Tag.ToString () == DeviceType.LightEnergySwitch.ToString () + "_Voltage") { btn.Text = energy.ToString () + " W"; } - } else if (updataType == 11) { - if (btn.Tag.ToString () == DeviceType.LightEnergySocket.ToString () + "_Electric" || btn.Tag.ToString () == DeviceType.LightEnergySwitch.ToString () + "_Electric") { - btn.Text = ((double)(Convert.ToDouble (energy) / 10)).ToString () + " kw.h"; - } } + //2020-07-01 瀹㈡埛鎻愬嚭闅愯棌kwh + //else if (updataType == 11) { + // if (btn.Tag.ToString () == DeviceType.LightEnergySocket.ToString () + "_Electric" || btn.Tag.ToString () == DeviceType.LightEnergySwitch.ToString () + "_Electric") { + // btn.Text = ((double)(Convert.ToDouble (energy) / 10)).ToString () + " kw.h"; + // } + //} } } } @@ -214,7 +216,7 @@ } }); } catch (Exception ex) { - Console.WriteLine (ex.Message); + Utlis.WriteLine (ex.Message); } finally { //Application.RunOnMainThread (() => { // MainPage.Loading.Hide (); @@ -230,7 +232,7 @@ { foreach (var thread in UserMiddle.updateSensorhreadList) { thread.Abort (); - Console.WriteLine ("abortThread"); + Utlis.WriteLine ("abortThread"); } UserMiddle.updateSensorhreadList.Clear (); EnergtLightList.Clear (); @@ -243,6 +245,29 @@ UserMiddle.FavoritePageView.ScrollEnabled = true; UserMiddle.RoomPageView.ScrollEnabled = true; base.RemoveFromParent (); + } + + /// <summary> + /// + /// </summary> + /// <param name="stateCodeStr"></param> + void ShowGetHomePagerErrorInfo (string stateCodeStr) + { + string mes = ""; + //2020-01-06 寰呰ˉ鍏� + if (stateCodeStr == ErrorCode.NetworkError) { + mes = ErrorCode.NetworkError; + } else { + mes = ErrorCode.OperationFailed + ErrorCode.Reason + stateCodeStr; + + } + if (!string.IsNullOrEmpty (mes)) { + Application.RunOnMainThread (() => { + new Alert ("", mes, Language.StringByID (R.MyInternationalizationString.Close)).Show (); + }); + } + + } public void InitRoomView (string RoomFilePath) @@ -362,7 +387,7 @@ Height = Application.GetRealHeight (26), UnSelectedImagePath = "Room/godown.png", }; - NameButton.Text = UserConfig.Instance.CurrentRegion.RegionName; + NameButton.Text = UserConfig.Instance.CurrentRegion.Name; topView.AddChidren (btnGoDownTip); //椤堕儴鏍囬鎸夐挳鍒囨崲浣忓畢鍖哄煙 @@ -370,13 +395,28 @@ MainPage.Loading.Start (); System.Threading.Tasks.Task.Run (() => { if (UserConfig.Instance.HomeLists.Count == 0) { - var requestObj2 = new HomeListObj (); - var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2); - var revertObj2 = MainPage.RequestHttps ("HomeList", requestJson2); - if (revertObj2.StateCode == "SUCCESS") { - var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RegionInfoRes>> (revertObj2.ResponseData.ToString ()); - UserConfig.Instance.HomeLists = responseDataObj; - UserConfig.Instance.SaveUserConfig (); + //var requestObj2 = new GetHomePagerObj (); + //requestObj2.ReqDto.LoginAccessToken = MainPage.LoginUser.LoginTokenString; + ////var requestObj2 = new HomeListObj (); + //var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2); + //var revertObj2 = MainPage.RequestHttps (API.GetHomePager, requestJson2); + //if (revertObj2.StateCode.ToUpper() == StateCode.SUCCESS) { + // var mResidenceRes = Newtonsoft.Json.JsonConvert.DeserializeObject<ResidenceRes> (revertObj2.ResponseData.ToString ()); + + // if (mResidenceRes.PageData != null && mResidenceRes.PageData.Count > 0) { + // UserConfig.Instance.HomeLists = mResidenceRes.PageData; + // UserConfig.Instance.SaveUserConfig (); + // } + //} else { + // ShowGetHomePagerErrorInfo (revertObj2.StateCode); + //} + + //鑾峰彇浣忓畢鍒楄〃 + var revertObjCode = HttpServerRequest.Current.GetHomePager (); + if (revertObjCode == StateCode.SUCCESS) { + + } else { + IMessageCommon.Current.ShowErrorInfoAlter (revertObjCode); } } Application.RunOnMainThread (() => { @@ -420,13 +460,13 @@ Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/Point.png", SelectedImagePath = "Item/Point.png", - Visible = homeTemp.RegionID != UserConfig.Instance.CurrentRegion.RegionID + Visible = homeTemp.Id != UserConfig.Instance.CurrentRegion.Id }; rowView.AddChidren (btnPoint); var btnName = new Button () { - Width = Application.GetRealWidth (550), - Text = homeTemp.RegionName, + Width = Application.GetRealWidth (300), + Text = homeTemp.Name, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (90), TextColor = SkinStyle.Current.TextColor1, @@ -434,7 +474,7 @@ rowView.AddChidren (btnName); btnName.MouseUpEventHandler += (ss, ee) => { - if (UserConfig.Instance.CurrentRegion.RegionID == homeTemp.RegionID) { + if (UserConfig.Instance.CurrentRegion.Id == homeTemp.Id) { return; } MainPage.Loading.Start ("Please wait..."); @@ -442,13 +482,13 @@ try { var backuplist = IO.FileUtils.ReadFiles (); int index = 0; - string oldRegionRootPath = IO.FileUtils.CreateRegionBackup (UserConfig.Instance.CurrentRegion.RegionName); + string oldRegionRootPath = IO.FileUtils.CreateRegionBackup (UserConfig.Instance.CurrentRegion.Id); IO.FileUtils.DeleteRegionFiles (oldRegionRootPath); foreach (var fileName in backuplist) { System.IO.FileInfo fileInfo = new System.IO.FileInfo (IO.FileUtils.RootPath + fileName); if (fileInfo.Exists) { fileInfo.MoveTo (oldRegionRootPath + fileName); - Console.WriteLine ("move file : " + fileName); + Utlis.WriteLine ("move file : " + fileName); } index++; Application.RunOnMainThread (() => { @@ -457,7 +497,7 @@ }); } IO.FileUtils.DeleteAllFile (); - string newRegionRootPath = IO.FileUtils.CreateRegionBackup (homeTemp.RegionName); + string newRegionRootPath = IO.FileUtils.CreateRegionBackup (homeTemp.Id); IO.FileUtils.RestoreRegionFiles (newRegionRootPath); UserConfig.Instance.RefreshUserConfig (); UserConfig.Instance.CurrentRegion = homeTemp; @@ -471,14 +511,14 @@ new Alert ("", Language.StringByID (R.MyInternationalizationString.SwitchRegionSuccessfully), Language.StringByID (R.MyInternationalizationString.Close)).Show (); this.InitRoomView (roomFilePath); - EquipmentPublicClass.CheckLinkRemote (2); + EquipmentPublicClass.CheckLinkRemote (UserConfig.Instance.internetStatus); }); } catch (Exception ex) { Application.RunOnMainThread (() => { new Alert ("", Language.StringByID (R.MyInternationalizationString.CheckInternet), Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); - Console.WriteLine (ex.Message); + Utlis.WriteLine (ex.Message); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); @@ -487,7 +527,7 @@ } }); }; - if (homeTemp.RegionID == UserConfig.Instance.CurrentRegion.RegionID) { + if (homeTemp.Id == UserConfig.Instance.CurrentRegion.Id) { Button btnCheck = new Button () { X = Application.GetRealWidth (20), Y = Application.GetRealHeight (25), @@ -631,24 +671,21 @@ CommonPage.RefreshAir = () => { var airQualityR = CommonPage.AirQuality; - if (airQualityR != null && - airQualityR.data != null && - airQualityR.data.city != null && - airQualityR.data.condition != null) { - AirQCity = btnCity.Text = airQualityR.data.city.name; - AirQTemp = btnTemp.Text = airQualityR.data.condition.temp + "掳"; - if (airQualityR.data.aqi != null) { - AirQAirPM25 = btnPM25.Text = "PM2.5 " + airQualityR.data.aqi.pm25; + if (airQualityR != null) { + AirQCity = btnCity.Text = airQualityR.city; + AirQTemp = btnTemp.Text = airQualityR.airQTemp + "掳"; + if (airQualityR.airQAirPM25 != null) { + AirQAirPM25 = btnPM25.Text = "PM2.5 " + airQualityR.airQAirPM25; } else { - if (string.IsNullOrEmpty (airQualityR.data.condition.condition)) - btnPM25.Text = airQualityR.data.condition.condition; + if (string.IsNullOrEmpty (airQualityR.airQAirWeather)) + btnPM25.Text = airQualityR.airQAirWeather; } - AirQHumidity = btnHumidity.Text = airQualityR.data.condition.humidity; + AirQHumidity = btnHumidity.Text = airQualityR.airQHumidity; AirQHumidityIcon = btnHumidityIcon.UnSelectedImagePath = "AirQuality/HumidityIcon.png"; AirQAirPM25Icon = btnPM25Icon.UnSelectedImagePath = "AirQuality/PM25Icon.png"; - AirLineNullBackgroundColor = btnAirLineNull.BackgroundColor = SkinStyle.Current.White20Transparent; + btnAirLineNull.BackgroundColor = SkinStyle.Current.White20Transparent; #region - switch (airQualityR.data.condition.condition) { + switch (airQualityR.airQAirWeather) { case "鏅�": case "Sunny": case "鏅村ぉ": @@ -818,6 +855,7 @@ #endregion } }; + CommonPage.RefreshAir (); } else { @@ -886,13 +924,16 @@ SelectedTextColor = SkinStyle.Current.TextColor1, }; acRowView.AddChidren (tempDeviceName); + //2020-08-28 澧炲姞闀挎寜淇敼璁惧澶囨敞 + ButtonNameAddMouseLongEventHandler (tempDeviceName, devcieCommon); + tempDeviceName.MouseUpEventHandler += openACControlPageEvent; Button btnMode = new Button () { X = Application.GetRealWidth (20), Y = Application.GetRealHeight (40), - Width = Application.GetRealWidth (100), - Height = Application.GetRealHeight (100), + Width = Application.GetMinRealAverage (100), + Height = Application.GetMinRealAverage (100), Tag = "Mode" }; acRowView.AddChidren (btnMode); @@ -902,8 +943,8 @@ Button btnWind = new Button () { X = btnMode.Right + Application.GetRealWidth (0), Y = Application.GetRealHeight (40), - Width = Application.GetRealWidth (100), - Height = Application.GetRealHeight (100), + Width = Application.GetMinRealAverage (100), + Height = Application.GetMinRealAverage (100), Tag = "Wind" }; acRowView.AddChidren (btnWind); @@ -935,13 +976,17 @@ }; acRowView.AddChidren (tempSiwtch); tempSiwtch.MouseUpEventHandler += (sender3, e3) => { - tempSiwtch.IsSelected = !tempSiwtch.IsSelected; - ac.Power = tempSiwtch.IsSelected ? (byte)1 : (byte)0; - if (ac.Type == DeviceType.ACPanel) { - Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 3, ac.Power, ac.LoopID }); - } else if (ac.Type == DeviceType.ACDevice || ac.Type == DeviceType.HVAC || ac.Type == DeviceType.ACInfrared) { - Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new [] { ac.LoopID, ac.TemperatureMode, ac.IndoorTemperature, ac.CoolTemperature, ac.HeatTemperature, ac.AutoTemperature, ac.ChuShiTemperature, ac.RealModeAndFanSpeed, ac.Power, ac.SetMode, ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode }); - } + //tempSiwtch.IsSelected = !tempSiwtch.IsSelected; + //ac.Power = tempSiwtch.IsSelected ? (byte)1 : (byte)0; + + SendControlAc (ac, tempSiwtch.IsSelected ? (byte)0 : (byte)1); + //if (ac.Type == DeviceType.ACPanel) { + // //2020-02-10 寰呬慨鏀� + // Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 3, ac.Power, ac.LoopID }); + //} else if (ac.Type == DeviceType.ACDevice || ac.Type == DeviceType.HVAC || ac.Type == DeviceType.ACInfrared) { + // //2020-02-10 寰呬慨鏀� + // Control.ControlBytesSend (Command.SetACMode, ac.SubnetID, ac.DeviceID, new [] { ac.LoopID, ac.TemperatureMode, ac.IndoorTemperature, ac.CoolTemperature, ac.HeatTemperature, ac.AutoTemperature, ac.ChuShiTemperature, ac.RealModeAndFanSpeed, ac.Power, ac.SetMode, ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode }); + //} }; if (0 < ac.Power) { @@ -995,6 +1040,10 @@ IsMoreLines = true }; fhRowView.AddChidren (tempDeviceName); + + //2020-08-28 澧炲姞闀挎寜淇敼璁惧澶囨敞 + ButtonNameAddMouseLongEventHandler (tempDeviceName, devcieCommon); + tempDeviceName.MouseUpEventHandler += (sender2, e2) => { UserFHPage fhView = new UserFHPage (fh, room); if (roomFilePath == Room.FavoriteRoom) { @@ -1047,8 +1096,10 @@ fh.Status = tempSiwtch.IsSelected ? (byte)1 : (byte)0; System.Threading.Tasks.Task.Run (() => { if (fh.Type == DeviceType.FoolHeatPanel) { + //2020-02-10 寰呬慨鏀� Control.ControlBytesSend (Command.InstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 20, fh.Status, fh.LoopID }); } else if (fh.Type == DeviceType.FoolHeat) { + //2020-02-10 寰呬慨鏀� fh = fh.Serverx_FH_CMD (FoolHeat.CommandType.Switch); } }); @@ -1111,6 +1162,13 @@ }; DeviceRowView.AddChidren (btnName); + //2020-08-28 澧炲姞闀挎寜淇敼璁惧澶囨敞 + ButtonNameAddMouseLongEventHandler (btnName, devcieCommon); + + //btnName.MouseLongEventHandler += (sender, e)=>{ + // RemarkDeviceName (devcieCommon, SimpleControl.CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (devcieCommon)), btnName); + //}; + Button tempSwitch = new Button () { Width = Application.GetMinRealAverage (90), Height = Application.GetMinRealAverage (53), @@ -1145,14 +1203,17 @@ }; tempSwitch.IsSelected = fanModule.Switch == 0 ? false : true; tempSwitch.MouseUpEventHandler += (sender3, e3) => { - tempSwitch.IsSelected = !tempSwitch.IsSelected; - if (tempSwitch.IsSelected) { - fanModule.Switch = fanModule.WindSpeed; - } else { - fanModule.Switch = 0; - } - Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, fanModule.Switch }); - IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ()); + //tempSwitch.IsSelected = !tempSwitch.IsSelected; + //if (tempSwitch.IsSelected) { + // fanModule.Switch = fanModule.WindSpeed; + //} else { + // fanModule.Switch = 0; + //} + //Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID, new byte [] { fanModule.LoopID, fanModule.Switch }); + + int mSetSwitch = tempSwitch.IsSelected ? 0 : fanModule.WindSpeed; + SendControl.SendControlSetSingleLight (fanModule, new byte [] { fanModule.LoopID, (byte)mSetSwitch }); + //IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ()); }; #endregion } else if (devcieCommon.Type == DeviceType.LightDimming || devcieCommon.Type == DeviceType.LightDALI) { @@ -1235,18 +1296,23 @@ }; tempSwitch.MouseUpEventHandler += (sender3, e3) => { - tempSwitch.IsSelected = !tempSwitch.IsSelected; - if (tempSwitch.IsSelected) { - Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.LoopID, dimming.LastOpenBrightness, 0, 0 }); - tempLightSeekBar.Progress = dimming.CurrentBrightness = dimming.LastOpenBrightness; - tempLightSeekBar.ThumbColor = SkinStyle.Current.SelectedColor; + //tempSwitch.IsSelected = !tempSwitch.IsSelected; + if (!tempSwitch.IsSelected) { + SendControl.SendControlSetSingleLight (dimming, new byte [] { dimming.LoopID, dimming.LastOpenBrightness, 0, 0 }); + + //Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.LoopID, dimming.LastOpenBrightness, 0, 0 }); + //tempLightSeekBar.Progress = dimming.CurrentBrightness = dimming.LastOpenBrightness; + //tempLightSeekBar.ThumbColor = SkinStyle.Current.SelectedColor; + //dimming.CurrentBrightness = dimming.LastOpenBrightness; } else { - Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.LoopID, 0, 0, 0 }); - tempLightSeekBar.Progress = 0; - tempLightSeekBar.ThumbColor = SkinStyle.Current.ThumbColor; - dimming.CurrentBrightness = 0; + SendControl.SendControlSetSingleLight (dimming, new byte [] { dimming.LoopID, 0, 0, 0 }); + + //Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.LoopID, 0, 0, 0 }); + //tempLightSeekBar.Progress = 0; + //tempLightSeekBar.ThumbColor = SkinStyle.Current.ThumbColor; + //dimming.CurrentBrightness = 0; } - btnValues.Text = dimming.CurrentBrightness + "%"; + //btnValues.Text = dimming.CurrentBrightness + "%"; }; if (dimming.CurrentBrightness > 0) { tempSwitch.IsSelected = true; @@ -1322,7 +1388,7 @@ }; proessView.AddChidren (btnMaxBrightness); horizontalSeekBar.ProgressChanged += (sender2, e4) => { - Console.WriteLine (DateTime.Now.ToString ()); + Utlis.WriteLine (DateTime.Now.ToString ()); btnMaxBrightness.Text = horizontalSeekBar.Progress + "%"; System.Threading.Tasks.Task.Run (() => { if ((System.DateTime.Now - (DateTime)(horizontalSeekBar.Tag)).TotalMilliseconds < 100) { @@ -1346,11 +1412,15 @@ tempSwitch.IsSelected = dimming.CurrentBrightness > 0 ? true : false; tempSwitch.MouseUpEventHandler += (sender3, e3) => { - tempSwitch.IsSelected = !tempSwitch.IsSelected; - if (tempSwitch.IsSelected) { - Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.PhysicsLoopID, 100, 0, 0 }); + //tempSwitch.IsSelected = !tempSwitch.IsSelected; + if (!tempSwitch.IsSelected) { + SendControl.SendControlSetSingleLight (dimming, new byte [] { dimming.PhysicsLoopID, 100, 0, 0 }); + + //Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.PhysicsLoopID, 100, 0, 0 }); } else { - Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.PhysicsLoopID, 0, 0, 0 }); + SendControl.SendControlSetSingleLight (dimming, new byte [] { dimming.PhysicsLoopID, 0, 0, 0 }); + + //Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.PhysicsLoopID, 0, 0, 0 }); } }; #endregion @@ -1369,13 +1439,16 @@ btnIcon.SelectedImagePath = "Item/Light.png"; tempSwitch.IsSelected = dimming.CurrentBrightness > 0 ? true : false; tempSwitch.MouseUpEventHandler += (sender3, e3) => { - tempSwitch.IsSelected = !tempSwitch.IsSelected; - if (tempSwitch.IsSelected) { - dimming.CurrentBrightness = 100; - Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.PhysicsLoopID, 100, 0, 0 }); + //tempSwitch.IsSelected = !tempSwitch.IsSelected; + if (!tempSwitch.IsSelected) { + //dimming.CurrentBrightness = 100; + SendControl.SendControlSetSingleLight (dimming, new byte [] { dimming.PhysicsLoopID, 100, 0, 0 }); + + //Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.PhysicsLoopID, 100, 0, 0 }); } else { - dimming.CurrentBrightness = 0; - Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.PhysicsLoopID, 0, 0, 0 }); + //dimming.CurrentBrightness = 0; + SendControl.SendControlSetSingleLight (dimming, new byte [] { dimming.PhysicsLoopID, 0, 0, 0 }); + //Control.ControlBytesSend (Command.SetSingleLight, dimming.SubnetID, dimming.DeviceID, new byte [] { dimming.PhysicsLoopID, 0, 0, 0 }); } }; #endregion @@ -1453,6 +1526,7 @@ lightLigicBytes [6] = e2 [0]; lightLigicBytes [7] = e2 [1]; lightLigicBytes [8] = e2 [2]; + //2020-02-10 寰呬慨鏀� Control.ControlBytesSend (Command.SetLogicLoopColor, rgbLight.SubnetID, rgbLight.DeviceID, lightLigicBytes, SendCount.Zero); colorChangeTime = DateTime.Now; btnColor.BackgroundColor = (uint)(0xFF000000 + lightLigicBytes [6] * 256 * 256 + lightLigicBytes [7] * 256 + lightLigicBytes [8]); @@ -1755,19 +1829,24 @@ tempSwitch.IsSelected = rgbLight.CurrentBrightness > 0 ? true : false; tempSwitch.MouseUpEventHandler += (sender3, e3) => { - tempSwitch.IsSelected = !tempSwitch.IsSelected; - if (tempSwitch.IsSelected) { - rgbLight.CurrentBrightness = 100; - Control.ControlBytesSend (Command.SetSingleLight, rgbLight.SubnetID, rgbLight.DeviceID, new byte [] { rgbLight.LoopID, 100, 0, 0 }); + //tempSwitch.IsSelected = !tempSwitch.IsSelected; + if (!tempSwitch.IsSelected) { + //rgbLight.CurrentBrightness = 100; + SendControl.SendControlSetSingleLight (rgbLight, new byte [] { rgbLight.LoopID, 100, 0, 0 }); + + //Control.ControlBytesSend (Command.SetSingleLight, rgbLight.SubnetID, rgbLight.DeviceID, new byte [] { rgbLight.LoopID, 100, 0, 0 }); } else { - rgbLight.CurrentBrightness = 0; - Control.ControlBytesSend (Command.SetSingleLight, rgbLight.SubnetID, rgbLight.DeviceID, new byte [] { rgbLight.LoopID, 0, 0, 0 }); + //rgbLight.CurrentBrightness = 0; + SendControl.SendControlSetSingleLight (rgbLight, new byte [] { rgbLight.LoopID, 0, 0, 0 }); + + //Control.ControlBytesSend (Command.SetSingleLight, rgbLight.SubnetID, rgbLight.DeviceID, new byte [] { rgbLight.LoopID, 0, 0, 0 }); } }; #endregion - } else if (devcieCommon.Type == DeviceType.LightSwitch || - devcieCommon.Type == DeviceType.LightEnergySocket || - devcieCommon.Type == DeviceType.LightEnergySwitch || devcieCommon.Type == DeviceType.LightSwitchSocket) { + } else if (devcieCommon.Type == DeviceType.LightSwitch + || devcieCommon.Type == DeviceType.LightEnergySocket + || devcieCommon.Type == DeviceType.LightEnergySwitch + || devcieCommon.Type == DeviceType.LightSwitchSocket) { #region 缁х數鍣� LightSwitch switchLight = devcieCommon as LightSwitch; tempSwitch.IsSelected = switchLight.CurrentBrightness == 100 ? true : false; @@ -1794,33 +1873,40 @@ }; DeviceRowView.AddChidren (btnEnergy); EnergtLightList.Add (devcieCommon); - - Button btnElectric = new Button () { - Width = Application.GetRealWidth (200), - Height = Application.GetRealHeight (35), - X = Application.GetRealWidth (320), - Y = tempSwitch.Bottom, - TextColor = SkinStyle.Current.TextColor1, - TextAlignment = TextAlignment.CenterRight, - SelectedTextColor = SkinStyle.Current.TextColor1, - Tag = devcieCommon.Type.ToString () + "_Electric", - Text = "0 kw.h" - }; - DeviceRowView.AddChidren (btnElectric); + //2020-07-01 瀹㈡埛鎻愬嚭闅愯棌kwh + //Button btnElectric = new Button () { + // Width = Application.GetRealWidth (200), + // Height = Application.GetRealHeight (35), + // X = Application.GetRealWidth (320), + // Y = tempSwitch.Bottom, + // TextColor = SkinStyle.Current.TextColor1, + // TextAlignment = TextAlignment.CenterRight, + // SelectedTextColor = SkinStyle.Current.TextColor1, + // Tag = devcieCommon.Type.ToString () + "_Electric", + // Text = "0 kw.h" + //}; + //DeviceRowView.AddChidren (btnElectric); } tempSwitch.MouseUpEventHandler += (sender3, e3) => { - tempSwitch.IsSelected = !tempSwitch.IsSelected; - if (tempSwitch.IsSelected) { - switchLight.CurrentBrightness = 100; - Control.ControlBytesSend (Command.SetSingleLight, switchLight.SubnetID, switchLight.DeviceID, new byte [] { switchLight.LoopID, 100, 0, 0 }); + //tempSwitch.IsSelected = !tempSwitch.IsSelected; + if (!tempSwitch.IsSelected) { + //switchLight.CurrentBrightness = 100; + SendControl.SendControlSetSingleLight (switchLight, new byte [] { switchLight.LoopID, 100, 0, 0 }); + + //Control.ControlBytesSend (Command.SetSingleLight, switchLight.SubnetID, switchLight.DeviceID, new byte [] { switchLight.LoopID, 100, 0, 0 }); } else { - switchLight.CurrentBrightness = 0; - Control.ControlBytesSend (Command.SetSingleLight, switchLight.SubnetID, switchLight.DeviceID, new byte [] { switchLight.LoopID, 0, 0, 0 }); + //switchLight.CurrentBrightness = 0; + SendControl.SendControlSetSingleLight (switchLight, new byte [] { switchLight.LoopID, 0, 0, 0 }); + //Control.ControlBytesSend (Command.SetSingleLight, switchLight.SubnetID, switchLight.DeviceID, new byte [] { switchLight.LoopID, 0, 0, 0 }); } - new System.Threading.Thread (() => { - Control.ControlBytesSend (Command.ReadAnalogValue, switchLight.SubnetID, switchLight.DeviceID, new byte [] { 10, switchLight.LoopID }, SendCount.Zero); - Control.ControlBytesSend (Command.ReadAnalogValue, switchLight.SubnetID, switchLight.DeviceID, new byte [] { 11, switchLight.LoopID }, SendCount.Zero); - }) { IsBackground = true }.Start (); + + if (devcieCommon.Type == DeviceType.LightEnergySocket || devcieCommon.Type == DeviceType.LightEnergySwitch) { + new System.Threading.Thread (() => { + Control.ControlBytesSend (Command.ReadAnalogValue, switchLight.SubnetID, switchLight.DeviceID, new byte [] { 10, switchLight.LoopID }, SendCount.Zero); + //2020-07-01 瀹㈡埛鎻愬嚭闅愯棌kwh + //Control.ControlBytesSend (Command.ReadAnalogValue, switchLight.SubnetID, switchLight.DeviceID, new byte [] { 11, switchLight.LoopID }, SendCount.Zero); + }) { IsBackground = true }.Start (); + } }; #endregion } else if (devcieCommon.Type == DeviceType.CurtainModel) { @@ -1928,7 +2014,7 @@ try { InfraredMode infraredTV = devcieCommon as InfraredMode;// Newtonsoft.Json.JsonConvert.DeserializeObject<InfraredMode> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); if (infraredTV != null) - Console.WriteLine (infraredTV.InfraredType); + Utlis.WriteLine (infraredTV.InfraredType); if (infraredTV.InfraredType == InfraredType.TV) { btnIcon.UnSelectedImagePath = "Item/InfraredTV.png"; btnIcon.SelectedImagePath = "Item/InfraredTV.png"; @@ -1943,12 +2029,13 @@ tempSwitch.MouseUpEventHandler += (sender3, e3) => { infraredTV.isOpen = tempSwitch.IsSelected = !tempSwitch.IsSelected; int RandKey = new Random ().Next (0, 255); + //2020-02-10 寰呬慨鏀� Control.ControlBytesSend (Command.InfraredControl, infraredTV.SubnetID, infraredTV.DeviceID, new byte [] { Convert.ToByte (infraredTV.Port), infraredTV.LoopID, (byte)InfraredCode_TV.Power, 0, 0, (byte)RandKey }); IO.FileUtils.SaveEquipmentMessage (infraredTV, infraredTV.LoopID.ToString ()); }; } } catch (Exception ex) { - Console.WriteLine (ex.ToString ()); + Utlis.WriteLine (ex.ToString ()); continue; } #endregion @@ -1986,14 +2073,14 @@ }; DeviceRowView.AddChidren (tempSwitch); if (udDevice.ActionType == 0) { - tempSwitch.Text = udDevice.ON_Text; - //tempSwitch.TextID = R.MyInternationalizationString.ON; + //tempSwitch.Text = udDevice.ON_Text; + tempSwitch.TextID = R.MyInternationalizationString.ON; } else if (udDevice.ActionType == 1) { - tempSwitch.Text = udDevice.OFF_Text; - //tempSwitch.TextID = R.MyInternationalizationString.OFF; + //tempSwitch.Text = udDevice.OFF_Text; + tempSwitch.TextID = R.MyInternationalizationString.OFF; } else if (udDevice.ActionType == 2) { - tempSwitch.Text = udDevice.OFF_Text; - //tempSwitch.TextID = R.MyInternationalizationString.OFF; + //tempSwitch.Text = udDevice.OFF_Text; + tempSwitch.TextID = R.MyInternationalizationString.OFF; Button tempON = new Button () { Width = Application.GetRealWidth (110), @@ -2009,6 +2096,7 @@ DeviceRowView.AddChidren (tempON); tempON.MouseUpEventHandler += (sender3, e3) => { if (udDevice.UniversalType == 0xE01C) { + //2020-02-10 寰呬慨鏀� Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 255 }, SendCount.Zero); } DeviceRowView.BorderColor = SkinStyle.Current.Transparent; @@ -2018,24 +2106,26 @@ DeviceRowView.BorderColor = SkinStyle.Current.SelectedColor; tempON.BorderColor = SkinStyle.Current.SelectedColor; }; - tempSwitch.MouseUpEventHandler += (sender3, e3) => { - if (udDevice.UniversalType == 0xE01C) { - if (udDevice.ActionType == 0) { - Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 255 }, SendCount.Zero); - } else if (udDevice.ActionType == 1) { - Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 0 }, SendCount.Zero); - } else if (udDevice.ActionType == 2) { - Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 0 }, SendCount.Zero); - } - } - DeviceRowView.BorderColor = SkinStyle.Current.Transparent; - tempSwitch.BorderColor = SkinStyle.Current.BorderColor; - }; - tempSwitch.MouseDownEventHandler += (sende3r, e3) => { - DeviceRowView.BorderColor = SkinStyle.Current.SelectedColor; - tempSwitch.BorderColor = SkinStyle.Current.SelectedColor; - }; } + tempSwitch.MouseUpEventHandler += (sender3, e3) => { + if (udDevice.UniversalType == 0xE01C) { + if (udDevice.ActionType == 0) { + //2020-02-10 寰呬慨鏀� + Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 255 }, SendCount.Zero); + } else if (udDevice.ActionType == 1) { + Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 0 }, SendCount.Zero); + } else if (udDevice.ActionType == 2) { + Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 0 }, SendCount.Zero); + } + } + DeviceRowView.BorderColor = SkinStyle.Current.Transparent; + tempSwitch.BorderColor = SkinStyle.Current.BorderColor; + }; + tempSwitch.MouseDownEventHandler += (sende3r, e3) => { + DeviceRowView.BorderColor = SkinStyle.Current.SelectedColor; + tempSwitch.BorderColor = SkinStyle.Current.SelectedColor; + }; + #endregion } else if (devcieCommon.Type.ToString ().Contains ("Sensor")) { #region 浼犳劅鍣� @@ -2228,23 +2318,29 @@ } } } catch (Exception ex) { - Console.WriteLine ("exddd :" + ex.ToString ()); + Utlis.WriteLine ("exddd :" + ex.ToString ()); } finally { + //2020-02-14 澧炲姞璇荤姸鎬佹搷浣� + UserMiddle.ReadAllDeviceStatus (false, true); + readEnergyThead = new Thread ((obj) => { - while (readEnergy) { - System.Threading.Thread.Sleep (500); + while (readEnergy && !Control.IsEnterBackground) { + try { for(int i=0;i<EnergtLightList.Count;i++){ + var c = EnergtLightList [i]; Control.ControlBytesSend (Command.ReadAnalogValue, c.SubnetID, c.DeviceID, new byte [] { 10, c.LoopID }, SendCount.Zero); - Control.ControlBytesSend (Command.ReadAnalogValue, c.SubnetID, c.DeviceID, new byte [] { 11, c.LoopID }, SendCount.Zero); + //2020-07-01 瀹㈡埛鎻愬嚭闅愯棌kwh + //Control.ControlBytesSend (Command.ReadAnalogValue, c.SubnetID, c.DeviceID, new byte [] { 11, c.LoopID }, SendCount.Zero); #if DEBUG Application.RunOnMainThread (() => { - Console.WriteLine ($"璇诲彇 { c.Name } 鐢佃兘"); + Utlis.WriteLine ($"璇诲彇 { c.Name } 鐢佃兘"); }); #endif + System.Threading.Thread.Sleep (500); } - System.Threading.Thread.Sleep (9500); + System.Threading.Thread.Sleep (10000); } catch { EnergtLightList = new List<Common> (); } @@ -2262,5 +2358,61 @@ } } } + + /// <summary> + /// 绌鸿皟鎺у埗锛屽甫杩斿洖缁撴灉 + /// </summary> + /// <param name="mAcData"></param> + /// <param name="bPower"></param> + void SendControlAc (AC mAcData, byte bPower) + { + MainPage.Loading.Start ("Sending..."); + System.Threading.Tasks.Task.Run (() => { + byte [] returnBytes = null; + if (mAcData.Type == DeviceType.ACPanel) { + returnBytes = Control.ControlBytesSendHasReturn (Command.InstructionPanelKey, mAcData.SubnetID, mAcData.DeviceID, new byte [] { 3, bPower, mAcData.LoopID }); + } else if (mAcData.Type == DeviceType.ACDevice || mAcData.Type == DeviceType.HVAC || mAcData.Type == DeviceType.ACInfrared) { + + returnBytes = Control.ControlBytesSendHasReturn (Command.SetACMode, mAcData.SubnetID, mAcData.DeviceID, new [] { mAcData.LoopID, mAcData.TemperatureMode, mAcData.IndoorTemperature, mAcData.CoolTemperature, mAcData.HeatTemperature, mAcData.AutoTemperature, mAcData.ChuShiTemperature, mAcData.RealModeAndFanSpeed, bPower, mAcData.SetMode, mAcData.SetFanSpeed, mAcData.SetTemperature, mAcData.ShaoFanMode }); + } + + Application.RunOnMainThread (() => { + if (returnBytes == null) { + new Alert ("", mAcData.Name + ErrorCode.ControlFailure, "Close").Show (); + } + MainPage.Loading.Hide (); + }); + }); + } + + /// <summary> + /// + /// </summary> + /// <param name="btnName"></param> + /// <param name="devcieCommon"></param> + void ButtonNameAddMouseLongEventHandler (Button btnName,Common devcieCommon) + { + //2020-08-28 澧炲姞闀挎寜淇敼璁惧澶囨敞 + btnName.MouseLongEventHandler += (sender, e) => { + RemarkDeviceName (devcieCommon, SimpleControl.CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (devcieCommon)), btnName); + }; + } + + /// <summary> + /// + /// </summary> + /// <param name="commonDevice"></param> + /// <param name="commonBytes"></param> + /// <param name="btnEquipment"></param> + void RemarkDeviceName (Common commonDevice, byte[] commonBytes, Button btnEquipment) + { + Action successAction = () => { + GenericDialog.Current.RefreshRemark (commonDevice); + //if (!roomDeviceFilePathList.Contains (filePath)) { + // roomDeviceFilePathList.Add (filePath); + //} + }; + GenericDialog.Current.ShowModifyRemarksDialog (commonDevice, commonBytes, btnEquipment, successAction); + } } } \ No newline at end of file -- Gitblit v1.8.0