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/Room/UserRoom.cs |  165 ++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 114 insertions(+), 51 deletions(-)

diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Room/UserRoom.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Room/UserRoom.cs
index 42f6436..64b2713 100644
--- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Room/UserRoom.cs
+++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Room/UserRoom.cs
@@ -501,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 (() => {
@@ -965,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) {
@@ -1077,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);
                             }
                         });
@@ -1175,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) {
@@ -1265,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;
@@ -1376,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
@@ -1399,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
@@ -1483,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]);
@@ -1785,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
@@ -1839,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);
@@ -1973,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 ());
                                     };
@@ -2039,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;
@@ -2051,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);
@@ -2260,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);
@@ -2273,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> ();
                         }
@@ -2292,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