From 9137222ece9b978eb97b5598f2eee6e070bcf9d6 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期五, 28 二月 2020 15:22:16 +0800
Subject: [PATCH] 2020-02-28 更新

---
 Crabtree/SmartHome/UI/SimpleControl/Phone/Room/UserRoom.cs |  223 +++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 158 insertions(+), 65 deletions(-)

diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Room/UserRoom.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Room/UserRoom.cs
index e514a4b..64b2713 100644
--- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Room/UserRoom.cs
+++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Room/UserRoom.cs
@@ -245,6 +245,29 @@
             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)
         {
             try {
@@ -362,7 +385,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 +393,20 @@
                     MainPage.Loading.Start ();
                     System.Threading.Tasks.Task.Run (() => {
                         if (UserConfig.Instance.HomeLists.Count == 0) {
-                            var requestObj2 = new HomeListObj ();
+                            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 ("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 revertObj2 = MainPage.RequestHttps (API.GetHomePager, requestJson2);
+                            if (revertObj2.StateCode.ToUpper() == "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);
                             }
                         }
                         Application.RunOnMainThread (() => {
@@ -420,13 +450,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 +464,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,7 +472,7 @@
                                         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);
@@ -457,7 +487,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,7 +501,7 @@
                                                 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 (() => {
@@ -487,7 +517,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),
@@ -935,13 +965,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) {
@@ -1047,8 +1081,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);
                             }
                         });
@@ -1145,14 +1181,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 +1274,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;
@@ -1346,11 +1390,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 +1417,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 +1504,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,13 +1807,17 @@
                             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
@@ -1809,13 +1865,16 @@
                                 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);
@@ -1943,6 +2002,7 @@
                                     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 ());
                                     };
@@ -2009,6 +2069,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;
@@ -2021,6 +2082,7 @@
                                 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);
@@ -2230,11 +2292,15 @@
             } catch (Exception ex) {
                 Console.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);
@@ -2243,8 +2309,9 @@
                                     Console.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 +2329,31 @@
                 }
             }
         }
+
+        /// <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 ();
+                });
+            });
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.8.0