using System; using System.Collections.Generic; using Shared.SimpleControl; namespace Shared.SimpleControl.Phone { /// /// 空调控制界面 /// public class UserACPage : FrameLayout { /// /// 当前视图 /// static UserACPage curView; FrameLayout acBodyView; AC ac; Room room; ACMethod acM; Button btnInterior; Button btnACSwitch; Button btnSetTemperature; Button btnModeIcon; Button btnWindIcon; Button btnModeText; Button btnWindModeText; Button btnReduceTemperature; Button BtnAddTemperature; Button btnACModeRight; Button btnACModeLeft; Button btnACWindRight; Button btnACWindLeft; static DateTime controlTime = DateTime.MinValue; static string TempTypeString = "°C"; /// /// 构造函数 /// /// Room. public UserACPage (AC ac, Room room) { this.ac = ac; this.room = room; curView = this; acM = new ACMethod (); BackgroundColor = SkinStyle.Current.MainColor; if (ac.TemperatureMode == 0) { TempTypeString = "°C"; } else { TempTypeString = "°F"; } readStatus (ac); } /// /// 更新室内温度-针对面板单一状态更新 /// public static void UpdateIndoorTemp (string updateFalg, byte indoorTemp) { Application.RunOnMainThread (() => { if (curView == null) { return; } if (curView.ac.CommonLoopID != updateFalg) { return; } if (controlTime.AddSeconds (0.8) > DateTime.Now) { return; } try { if (curView.ac.TemperatureMode == 1) { var f = curView.ac.IndoorTemperature * 9 / 5 + 32; curView.btnInterior.Text = f.ToString () + "°F"; } else { curView.btnInterior.Text = indoorTemp + "°C"; } } catch (Exception ex) { Console.WriteLine (ex.ToString ()); } }); } /// /// 更新工作温度-针对面板单一状态更新 /// public static void UpdateWorkingTemp (string updateFalg, byte workingTemp) { if (curView == null) { return; } if (curView.ac.CommonLoopID != updateFalg) { return; } if (controlTime.AddSeconds (0.8) > DateTime.Now) { return; } Application.RunOnMainThread (() => { curView.btnSetTemperature.Text = workingTemp + TempTypeString; curView.ac.SetTemperature = workingTemp; }); } /// /// 更新地热开关状态-针对面板单一状态更新 /// public static void UpdatePower (string updateFalg, byte power) { if (curView == null) { return; } if (curView.ac.CommonLoopID != updateFalg) { return; } if (controlTime.AddSeconds (0.8) > DateTime.Now) { return; } Application.RunOnMainThread (() => { if (power == 1) { //考虑到其他人控制的情况下,得使当前界面更新的数据和别人控制的一样 curView.btnReduceTemperature.Enable = true; curView.BtnAddTemperature.Enable = true; curView.btnACModeLeft.Enable = true; curView.btnACModeRight.Enable = true; curView.btnACWindRight.Enable = true; curView.btnACWindLeft.Enable = true; curView.btnACSwitch.IsSelected = true; } else { curView.btnACSwitch.IsSelected = false; curView.btnReduceTemperature.Enable = false; curView.BtnAddTemperature.Enable = false; curView.btnACModeLeft.Enable = false; curView.btnACModeRight.Enable = false; curView.btnACWindRight.Enable = false; curView.btnACWindLeft.Enable = false; curView.btnACSwitch.IsSelected = false; } #region 更新用户主界面灯光点亮总数 int acOponeCount = 0; foreach (var room in Room.Lists) { if (string.IsNullOrEmpty (room.Name)) { continue; } foreach (var acTemp in room.DeviceList) { if (acTemp.Type == DeviceType.HVAC || acTemp.Type == DeviceType.ACInfrared || acTemp.Type == DeviceType.ACPanel || acTemp.Type == DeviceType.LongXiAC) if ((acTemp as AC).Power == 1) { acOponeCount++; } } } UserDeviceView.UpdataDeviceCountNumber (acOponeCount, R.MyInternationalizationString.AC); #endregion }); } /// /// 更新工作模式-针对面板单一状态更新 /// public static void UpdateSetMode (string updateFalg, byte setMode) { if (curView == null) { return; } if (curView.ac.CommonLoopID != updateFalg) { return; } if (controlTime.AddSeconds (0.8) > DateTime.Now) { return; } Application.RunOnMainThread (() => { curView.acM.UpdataACHostModeIcon (setMode, curView.btnModeIcon, curView.btnModeText); }); } /// /// 更新工作模式-针对面板单一状态更新 /// public static void UpdateSetFanSpeed (string updateFalg, byte setFanSpeed) { if (curView == null) { return; } if (curView.ac.CommonLoopID != updateFalg) { return; } if (controlTime.AddSeconds (0.8) > DateTime.Now) { return; } Application.RunOnMainThread (() => { try { curView.acM.UpdataACHostWindIcon (setFanSpeed, curView.btnWindIcon, curView.btnWindModeText); } catch { } }); } /// /// 更新空调 /// public static void UpdateStatus (AC ac , bool selfUpdate = false) { Application.RunOnMainThread (() => { if (curView == null) { return; } if (curView.ac != ac) { return; } if (controlTime.AddSeconds (0.8) > DateTime.Now && !selfUpdate) { return; } try { if (ac.Power == 1) { curView.btnACSwitch.IsSelected = true; curView.btnInterior.Text = ac.IndoorTemperature.ToString () + TempTypeString; if (ac.TemperatureMode == 1) { var f = ac.IndoorTemperature * 9 / 5 + 32; curView.btnInterior.Text = f + TempTypeString; } curView.acM.UpdataACHostModeIcon (ac.SetMode, curView.btnModeIcon, curView.btnModeText); curView.acM.UpdataACHostWindIcon (ac.SetFanSpeed, curView.btnWindIcon, curView.btnWindModeText); curView.acM.UpdataACModeTemperature (ac, ac.SetMode, curView.btnSetTemperature); //考虑到其他人控制的情况下,得使当前界面更新的数据和别人控制的一样 curView.btnReduceTemperature.Enable = true; curView.BtnAddTemperature.Enable = true; curView.btnACModeLeft.Enable = true; curView.btnACModeRight.Enable = true; curView.btnACWindRight.Enable = true; curView.btnACWindLeft.Enable = true; } else { curView.btnACSwitch.IsSelected = false; curView.btnReduceTemperature.Enable = false; curView.BtnAddTemperature.Enable = false; curView.btnACModeLeft.Enable = false; curView.btnACModeRight.Enable = false; curView.btnACWindRight.Enable = false; curView.btnACWindLeft.Enable = false; } } catch (Exception ex) { Console.WriteLine (ex.ToString ()); } }); } public void UpdateACTempType () { System.Threading.Tasks.Task.Factory.StartNew (() => { var readRecBytes = Control.ControlBytesSendHasReturn (Command.ReadPanelTempType, ac.SubnetID, ac.DeviceID, new byte [] { }); if(readRecBytes!= null) { try { if (readRecBytes.Length > 0) { if (readRecBytes [0] == 0) { Application.RunOnMainThread (() => { btnInterior.Text = ac.IndoorTemperature.ToString () + "°C"; btnSetTemperature.Text = ac.SetTemperature.ToString () + "°C"; TempTypeString = "°C"; }); } else { var f = ac.IndoorTemperature * 9 / 5 + 32; Application.RunOnMainThread (() => { btnInterior.Text = f.ToString () + "°F"; btnSetTemperature.Text = ac.SetTemperature.ToString () + "°F"; TempTypeString = "°F"; }); } ac.TemperatureMode = readRecBytes [0]; IO.FileUtils.SaveEquipmentMessage (ac, ac.LoopID.ToString ()); } } catch (Exception ex) { Console.WriteLine (ex.Message); } } }); } /// /// 显示出当前房间所有的空调 /// public void showRoomAC () { #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (640), }; AddChidren (topView); var title = new Button () { TextAlignment = TextAlignment.Center, Text = ac.Name, TextColor = SkinStyle.Current.TextColor1, TextSize = 19, }; topView.AddChidren (title); var logo = new Button () { Width = Application.GetRealWidth (154), Height = Application.GetRealHeight (90), X = Application.GetRealWidth (486), UnSelectedImagePath = MainPage.LogoString, }; topView.AddChidren (logo); var back = new Button () { Height = Application.GetRealHeight (100), Width = Application.GetRealWidth (85), UnSelectedImagePath = "Item/Back.png", SelectedImagePath = "Item/BackSelected.png", }; topView.AddChidren (back); back.MouseUpEventHandler += (sender, e) => { (Parent as PageLayout).PageIndex -= 1; curView = null; }; #endregion acBodyView = new FrameLayout { Height = Application.GetRealHeight (Application.DesignHeight - 126), Y = Application.GetRealHeight (126) }; AddChidren (acBodyView); #region roomBackgroundImage var roomBackgroundImageView = new FrameLayout () { Height = MainPage.GetDesignHeight (360), }; acBodyView.AddChidren (roomBackgroundImageView); roomBackgroundImageView.BackgroundImagePath = room.BackGroundImage; FrameLayout setACTemp = new FrameLayout () { Height = Application.GetMinRealAverage (106), Width = Application.GetRealWidth (640), BackgroundColor = SkinStyle.Current.MainColor, Y = Application.GetMinRealAverage (360), }; acBodyView.AddChidren (setACTemp); btnACSwitch = new Button () { Width = Application.GetMinRealAverage (115), Height = Application.GetMinRealAverage (115), X = Application.GetRealWidth (640 - 152), UnSelectedImagePath = "FH/FH_Switch.png", SelectedImagePath = "FH/FH_Switch_on.png", }; btnACSwitch.IsSelected = ac.Power == 1; btnACSwitch.MouseUpEventHandler += (sender, e) => { btnACSwitch.IsSelected = !btnACSwitch.IsSelected; ac.Power = btnACSwitch.IsSelected ? (byte)1 : (byte)0; UpdateStatus (ac,true); if (controlTime.AddSeconds (0.8) > DateTime.Now) { controlTime = DateTime.Now; return; } controlTime = DateTime.Now; Console.WriteLine ("controlTime reset"); System.Threading.Tasks.Task.Run (() => { while (controlTime.AddSeconds (0.8) > DateTime.Now) { System.Threading.Thread.Sleep (800); Console.WriteLine ("sleep 800"); } Console.WriteLine ("Control ac switch"); 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.ACInfrared || ac.Type == DeviceType.HVAC) { 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 }); } else if (ac.Type == DeviceType.CustomAC) { var acCommon = ac as CustomAC; var controlCommand = acCommon.customACControlLists.Find ((obj) => obj.UniversalModeType == ac.Power); if (controlCommand != null) { Control.ControlBytesSend (Command.SetCommonSwitch, acCommon.SubnetID, acCommon.DeviceID, new byte [] { controlCommand.UniversalID, 255 }, SendCount.Zero); IO.FileUtils.SaveEquipmentMessage (acCommon, acCommon.LoopID.ToString ()); } } }); }; setACTemp.AddChidren (btnACSwitch); var btnText = new Button () { Width = Application.GetRealWidth (150), Height = Application.GetRealHeight (40), X = Application.GetRealWidth (15), Y = Application.GetRealHeight (22), TextID = R.MyInternationalizationString.ACInterior, TextAlignment = TextAlignment.BottomCenter, TextColor = SkinStyle.Current.TextColor1 }; setACTemp.AddChidren (btnText); btnInterior = new Button () { Width = Application.GetRealWidth (150), Height = Application.GetRealHeight (40), X = Application.GetRealWidth (10), Y = btnText.Bottom, TextSize = 14, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1 }; setACTemp.AddChidren (btnInterior); if(ac.TemperatureMode == 1) { var f = ac.IndoorTemperature * 9 / 5 + 32; btnInterior.Text = f.ToString () + "°F"; } else { btnInterior.Text = ac.IndoorTemperature.ToString () + "°C"; } UpdateACTempType (); //长按更换背景 #if wallon #else roomBackgroundImageView.MouseLongEventHandler += (sender, e) => { Camera.SelectPicture ((obj) => { if (obj != null) { room.BackGroundImage = obj; roomBackgroundImageView.BackgroundImagePath = obj; room.Save (typeof (Room).Name + "_" + room.Name); } }, room.Name, false); }; #endif #endregion #region acTemperature FrameLayout acTemperatureView = new FrameLayout () { Height = (acBodyView.Height - setACTemp.Height - roomBackgroundImageView.Height)/3, BackgroundColor = SkinStyle.Current.ViewColor, Y = setACTemp.Bottom, }; acBodyView.AddChidren (acTemperatureView); var btnACTemp = new Button () { Width = Application.GetRealWidth (200), Height = Application.GetRealHeight (30), Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight (19), TextID = R.MyInternationalizationString.Temperature, TextColor = SkinStyle.Current.ButtonColor, }; acTemperatureView.AddChidren (btnACTemp); btnSetTemperature = new Button () { Width = Application.GetMinRealAverage (120), Y = Application.GetRealHeight(10), Gravity = Gravity.CenterHorizontal, Text = ac.SetTemperature.ToString () + TempTypeString, TextSize = 20, TextAlignment = TextAlignment.Center, Enable = false, TextColor = SkinStyle.Current.TextColor1 }; acTemperatureView.AddChidren (btnSetTemperature); if (ac.TemperatureMode == 1) { btnSetTemperature.Text = ac.SetTemperature.ToString () + "°F"; } else { btnSetTemperature.Text = ac.SetTemperature.ToString () + "°C"; } btnReduceTemperature = new Button () { Width = Application.GetMinRealAverage (129), Height = Application.GetMinRealAverage (129), X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "AC/ac-1.png", SelectedImagePath = "AC/ac_on-.png", }; acTemperatureView.AddChidren (btnReduceTemperature); btnReduceTemperature.MouseDownEventHandler += (sender, e) => { btnReduceTemperature.IsSelected = true; }; btnReduceTemperature.MouseUpEventHandler += (sender, e) => { btnReduceTemperature.IsSelected = false; if (ac.SetMode == 2) { return; } if (ac.SetTemperature < 17) { return; } ac.SetTemperature--; byte modeKey = 4; switch (ac.SetMode) { //cooling case 0: ac.CoolTemperature = ac.SetTemperature; modeKey = 4; break; //Heating case 1: ac.HeatTemperature = ac.SetTemperature; modeKey = 7; break; //Fan case 2: ac.IndoorTemperature = ac.SetTemperature; modeKey = 2; break; // Auto case 3: ac.AutoTemperature = ac.SetTemperature; modeKey = 8; break; //Dry case 4: ac.ChuShiTemperature = ac.SetTemperature; modeKey = 19; break; } UpdateStatus (ac,true); if (controlTime.AddSeconds (0.8) > DateTime.Now) { controlTime = DateTime.Now; return; } controlTime = DateTime.Now; Console.WriteLine ("controlTime reset"); System.Threading.Tasks.Task.Run (() => { while (controlTime.AddSeconds (0.8) > DateTime.Now) { System.Threading.Thread.Sleep (800); Console.WriteLine ("sleep 800"); } if (ac.Type == DeviceType.ACPanel) { Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { modeKey, ac.SetTemperature, ac.LoopID }); } else if (ac.Type == DeviceType.ACDevice || ac.Type == DeviceType.ACInfrared || ac.Type == DeviceType.HVAC) { 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, btnACSwitch.IsSelected ? (byte)1 : (byte)0, ac.SetMode, ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode }); } else if (ac.Type == DeviceType.CustomAC) { var acCommon = ac as CustomAC; var controlCommand = acCommon.customACControlLists.Find ((obj) => obj.UniversalModeType == ac.Power && obj.UniversalFanSpeed == ac.SetFanSpeed && obj.UniversalTemp == ac.SetTemperature); if (controlCommand != null) { Control.ControlBytesSend (Command.SetCommonSwitch, acCommon.SubnetID, acCommon.DeviceID, new byte [] { controlCommand.UniversalID, 255 }, SendCount.Zero); IO.FileUtils.SaveEquipmentMessage (acCommon, acCommon.LoopID.ToString ()); } } }); }; BtnAddTemperature = new Button () { Width = Application.GetMinRealAverage (129), Height = Application.GetMinRealAverage (129), X = Application.GetRealWidth (640 - 129 - 30), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "AC/ac+1.png", SelectedImagePath = "AC/ac_on+.png", }; acTemperatureView.AddChidren (BtnAddTemperature); BtnAddTemperature.MouseDownEventHandler += (sender, e) => { BtnAddTemperature.IsSelected = true; }; BtnAddTemperature.MouseUpEventHandler += (sender, e) => { BtnAddTemperature.IsSelected = false; if (ac.SetMode == 2) { return; } if (ac.TemperatureMode == 0) { if (++ac.SetTemperature > 38) { ac.SetTemperature = 38; return; } } else { if (++ac.SetTemperature > 120) { ac.SetTemperature = 120; return; } } byte modeKey = 4; switch (ac.SetMode) { //cooling case 0: ac.CoolTemperature = ac.SetTemperature; modeKey = 4; break; //Heating case 1: ac.HeatTemperature = ac.SetTemperature; modeKey = 7; break; //Fan case 2: ac.IndoorTemperature = ac.SetTemperature; break; // Auto case 3: ac.AutoTemperature = ac.SetTemperature; modeKey = 8; break; //Dry case 4: ac.ChuShiTemperature = ac.SetTemperature; modeKey = 19; break; } UpdateStatus (ac,true); if (controlTime.AddSeconds (0.8) > DateTime.Now) { controlTime = DateTime.Now; return; } controlTime = DateTime.Now; Console.WriteLine ("controlTime reset"); System.Threading.Tasks.Task.Run (() => { while (controlTime.AddSeconds (0.8) > DateTime.Now) { System.Threading.Thread.Sleep (800); Console.WriteLine ("sleep 800"); } if (ac.Type == DeviceType.ACPanel) { Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { modeKey, ac.SetTemperature, ac.LoopID }); } else if (ac.Type == DeviceType.ACDevice || ac.Type == DeviceType.ACInfrared || ac.Type == DeviceType.HVAC) { 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, btnACSwitch.IsSelected ? (byte)1 : (byte)0, ac.SetMode, ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode }); } else if (ac.Type == DeviceType.CustomAC) { var acCommon = ac as CustomAC; var controlCommand = acCommon.customACControlLists.Find ((obj) => obj.UniversalModeType == ac.Power && obj.UniversalFanSpeed == ac.SetFanSpeed && obj.UniversalTemp == ac.SetTemperature); if (controlCommand != null) { Control.ControlBytesSend (Command.SetCommonSwitch, acCommon.SubnetID, acCommon.DeviceID, new byte [] { controlCommand.UniversalID, 255 }, SendCount.Zero); IO.FileUtils.SaveEquipmentMessage (acCommon, acCommon.LoopID.ToString ()); } } }); }; #endregion Button btnTNull = new Button () { Height = 1, BackgroundColor = SkinStyle.Current.MainColor, Y = acTemperatureView.Bottom, }; acBodyView.AddChidren (btnTNull); #region 模式 var acModeView = new FrameLayout () { Height = (acBodyView.Height - setACTemp.Height - roomBackgroundImageView.Height) / 3, Width = Application.GetRealWidth(640), BackgroundColor = SkinStyle.Current.ViewColor, Y = btnTNull.Bottom, }; acBodyView.AddChidren (acModeView); btnACModeLeft = new Button () { Width = Application.GetMinRealAverage (129), Height = Application.GetMinRealAverage (129), X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "AC/ac_left.png", SelectedImagePath = "AC/ACLeftSelected.png", }; acModeView.AddChidren (btnACModeLeft); var btnModeName = new Button () { Width = Application.GetRealWidth (200), Height = Application.GetRealHeight (30), Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight (25), TextID = R.MyInternationalizationString.UserACMode, TextColor = SkinStyle.Current.ButtonColor, }; acModeView.AddChidren (btnModeName); btnModeIcon = new Button () { Width = Application.GetMinRealAverage (110), Height = Application.GetMinRealAverage (112), Gravity = Gravity.Center, Y = btnModeName.Bottom + Application.GetRealHeight (10), UnSelectedImagePath = "AC/ACRefrigeration.png", }; acModeView.AddChidren (btnModeIcon); btnModeText = new Button () { Width = Application.GetRealWidth (200), Height = Application.GetRealHeight (50), TextID = R.MyInternationalizationString.Cool, Gravity = Gravity.CenterHorizontal, Y = btnModeIcon.Bottom - Application.GetRealHeight (20), TextColor = SkinStyle.Current.TextColor1 }; acModeView.AddChidren (btnModeText); btnACModeRight = new Button () { Width = Application.GetMinRealAverage (129), Height = Application.GetMinRealAverage (129), X = Application.GetRealWidth (640 - 129 - 30), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "AC/ac_right.png", SelectedImagePath = "AC/ACRightSelected.png", }; acModeView.AddChidren (btnACModeRight); btnACModeRight.MouseDownEventHandler += (sender, e) => { btnACModeRight.IsSelected = true; }; btnACModeRight.MouseUpEventHandler += (sender, e) => { btnACModeRight.IsSelected = false; try { if (ac.SetMode > 4) { ac.SetMode = 4; } if (++ac.SetMode > 4) { ac.SetMode = 0; } UpdateStatus (ac, true); if (controlTime.AddSeconds (0.8) > DateTime.Now) { controlTime = DateTime.Now; return; } controlTime = DateTime.Now; Console.WriteLine ("controlTime reset"); System.Threading.Tasks.Task.Run (() => { while (controlTime.AddSeconds (0.8) > DateTime.Now) { System.Threading.Thread.Sleep (800); Console.WriteLine ("sleep 800"); } if (ac.Type == DeviceType.ACPanel) { Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 6, ac.SetMode, ac.LoopID }); } else if (ac.Type == DeviceType.ACDevice || ac.Type == DeviceType.ACInfrared || ac.Type == DeviceType.HVAC) { 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, btnACSwitch.IsSelected ? (byte)1 : (byte)0, ac.SetMode, ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode }); } else if (ac.Type == DeviceType.CustomAC) { var acCommon = ac as CustomAC; var controlCommand = acCommon.customACControlLists.Find ((obj) => obj.UniversalModeType == ac.Power && obj.UniversalFanSpeed == ac.SetFanSpeed && obj.UniversalTemp == ac.SetTemperature); if (controlCommand != null) { Control.ControlBytesSend (Command.SetCommonSwitch, acCommon.SubnetID, acCommon.DeviceID, new byte [] { controlCommand.UniversalID, 255 }, SendCount.Zero); IO.FileUtils.SaveEquipmentMessage (acCommon, acCommon.LoopID.ToString ()); } } }); } catch { } }; btnACModeLeft.MouseDownEventHandler += (sender, e) => { btnACModeLeft.IsSelected = true; }; btnACModeLeft.MouseUpEventHandler += (sender, e) => { btnACModeLeft.IsSelected = false; try { if (ac.SetMode == 0 ) ac.SetMode = 4; else{ ac.SetMode--; } } catch { ac.SetMode = 4; } UpdateStatus (ac,true); if (controlTime.AddSeconds (0.8) > DateTime.Now) { controlTime = DateTime.Now; return; } controlTime = DateTime.Now; Console.WriteLine ("controlTime reset"); System.Threading.Tasks.Task.Run (() => { while (controlTime.AddSeconds (0.8) > DateTime.Now) { System.Threading.Thread.Sleep (800); Console.WriteLine ("sleep 800"); } acM.UpdataACHostModeIcon (ac.SetMode, btnModeIcon); if (ac.Type == DeviceType.ACPanel) { Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 6, ac.SetMode, ac.LoopID }); } else if (ac.Type == DeviceType.ACDevice || ac.Type == DeviceType.ACInfrared || ac.Type == DeviceType.HVAC) { 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, btnACSwitch.IsSelected ? (byte)1 : (byte)0, ac.SetMode, ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode }); } else if (ac.Type == DeviceType.CustomAC) { var acCommon = ac as CustomAC; var controlCommand = acCommon.customACControlLists.Find ((obj) => obj.UniversalModeType == ac.Power && obj.UniversalFanSpeed == ac.SetFanSpeed && obj.UniversalTemp == ac.SetTemperature); if (controlCommand != null) { Control.ControlBytesSend (Command.SetCommonSwitch, acCommon.SubnetID, acCommon.DeviceID, new byte [] { controlCommand.UniversalID, 255 }, SendCount.Zero); IO.FileUtils.SaveEquipmentMessage (acCommon, acCommon.LoopID.ToString ()); } } }); }; #endregion var btnLine1 = new Button () { Height = 1, BackgroundColor = SkinStyle.Current.MainColor, Y = acModeView.Bottom, }; acBodyView.AddChidren (btnLine1); #region 风速 var acWindView = new FrameLayout () { Height = (acBodyView.Height - setACTemp.Height - roomBackgroundImageView.Height) / 3, Y = btnLine1.Bottom, BackgroundColor = SkinStyle.Current.ViewColor, }; acBodyView.AddChidren (acWindView); btnACWindLeft = new Button () { Width = Application.GetMinRealAverage (129), Height = Application.GetMinRealAverage (129), X = Application.GetRealWidth (30), Y = Application.GetMinRealAverage (44), UnSelectedImagePath = "AC/ac_left.png", SelectedImagePath = "AC/ACLeftSelected.png", }; acWindView.AddChidren (btnACWindLeft); var btnWindName = new Button () { Width = Application.GetRealWidth (200), Height = Application.GetRealHeight (30), Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight (21), TextID = R.MyInternationalizationString.Speed, TextColor = SkinStyle.Current.ButtonColor, }; acWindView.AddChidren (btnWindName); btnWindIcon = new Button () { Width = Application.GetMinRealAverage (110), Height = Application.GetMinRealAverage (112), X = Application.GetRealWidth (262), Y = Application.GetMinRealAverage (44), UnSelectedImagePath = "AC/ACAuto.png", }; acWindView.AddChidren (btnWindIcon); btnWindModeText = new Button () { Width = Application.GetRealWidth (200), Height = Application.GetRealHeight (50), TextID = R.MyInternationalizationString.High, Gravity = Gravity.CenterHorizontal, TextColor = SkinStyle.Current.TextColor1, Y = btnWindIcon.Bottom - Application.GetRealHeight (16), }; acWindView.AddChidren (btnWindModeText); btnACWindRight = new Button () { Width = Application.GetMinRealAverage (129), Height = Application.GetMinRealAverage (129), X = btnACModeRight.X, Y = Application.GetMinRealAverage (44), UnSelectedImagePath = "AC/ac_right.png", SelectedImagePath = "AC/ACRightSelected.png", }; btnACWindLeft.MouseDownEventHandler += (sender, e) => { btnACWindLeft.IsSelected = true; }; btnACWindLeft.MouseUpEventHandler += (sender, e) => { btnACWindLeft.IsSelected = false; if (ac.SetFanSpeed > 3) { ac.SetFanSpeed = 3; } if (++ac.SetFanSpeed > 3) ac.SetFanSpeed = 0; //acM.UpdataACHostWindIcon (ac.SetFanSpeed, btnWindIcon); UpdateStatus (ac,true); if (controlTime.AddSeconds (0.8) > DateTime.Now) { controlTime = DateTime.Now; return; } controlTime = DateTime.Now; Console.WriteLine ("controlTime reset"); System.Threading.Tasks.Task.Run (() => { while (controlTime.AddSeconds (0.8) > DateTime.Now) { System.Threading.Thread.Sleep (800); Console.WriteLine ("sleep 800"); } if (ac.Type == DeviceType.ACPanel) { Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 5, ac.SetFanSpeed, ac.LoopID }); } else if (ac.Type == DeviceType.ACDevice || ac.Type == DeviceType.ACInfrared || ac.Type == DeviceType.HVAC) { 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, btnACSwitch.IsSelected ? (byte)1 : (byte)0, ac.SetMode, ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode }); } else if (ac.Type == DeviceType.CustomAC) { var acCommon = ac as CustomAC; var controlCommand = acCommon.customACControlLists.Find ((obj) => obj.UniversalModeType == ac.Power && obj.UniversalFanSpeed == ac.SetFanSpeed && obj.UniversalTemp == ac.SetTemperature); if (controlCommand != null) { Control.ControlBytesSend (Command.SetCommonSwitch, acCommon.SubnetID, acCommon.DeviceID, new byte [] { controlCommand.UniversalID, 255 }, SendCount.Zero); IO.FileUtils.SaveEquipmentMessage (acCommon, acCommon.LoopID.ToString ()); } } }); }; acWindView.AddChidren (btnACWindRight); btnACWindRight.MouseDownEventHandler += (sender, e) => { btnACWindRight.IsSelected = true; }; btnACWindRight.MouseUpEventHandler += (sender, e) => { btnACWindRight.IsSelected = false; try { ac.SetFanSpeed--; if (ac.SetFanSpeed < 0 || ac.SetFanSpeed > 3) ac.SetFanSpeed = 3; } catch { ac.SetFanSpeed = 3; } UpdateStatus (ac,true); if (controlTime.AddSeconds (0.8) > DateTime.Now) { controlTime = DateTime.Now; return; } controlTime = DateTime.Now; Console.WriteLine ("controlTime reset"); System.Threading.Tasks.Task.Run (() => { while (controlTime.AddSeconds (0.8) > DateTime.Now) { System.Threading.Thread.Sleep (800); Console.WriteLine ("sleep 800"); } Console.WriteLine ("control ac wind"); if (ac.Type == DeviceType.ACPanel) { Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 5, ac.SetFanSpeed, ac.LoopID }); } else if (ac.Type == DeviceType.ACDevice || ac.Type == DeviceType.ACInfrared || ac.Type == DeviceType.HVAC) { 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, btnACSwitch.IsSelected ? (byte)1 : (byte)0, ac.SetMode, ac.SetFanSpeed, ac.SetTemperature, ac.ShaoFanMode }); } else if (ac.Type == DeviceType.CustomAC) { var acCommon = ac as CustomAC; var controlCommand = acCommon.customACControlLists.Find ((obj) => obj.UniversalModeType == ac.Power && obj.UniversalFanSpeed == ac.SetFanSpeed && obj.UniversalTemp == ac.SetTemperature); if (controlCommand != null) { Control.ControlBytesSend (Command.SetCommonSwitch, acCommon.SubnetID, acCommon.DeviceID, new byte [] { controlCommand.UniversalID, 255 }, SendCount.Zero); IO.FileUtils.SaveEquipmentMessage (acCommon, acCommon.LoopID.ToString ()); } } }); }; #endregion UpdateStatus (ac,true); } /// /// 读取设备状态 /// static void readStatus (AC ac) { System.Threading.Tasks.Task.Run (() => { #if DEBUG #else if (ac.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now) { #endif if (ac.Type == DeviceType.ACPanel) { Control.ControlBytesSend (Command.ReadInstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 3, ac.LoopID, ac.LoopID }, SendCount.Zero); Control.ControlBytesSend (Command.ReadInstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 4, ac.LoopID, ac.LoopID }, SendCount.Zero); Control.ControlBytesSend (Command.ReadInstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 5, ac.LoopID, ac.LoopID }, SendCount.Zero); Control.ControlBytesSend (Command.ReadInstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 6, ac.LoopID, ac.LoopID }, SendCount.Zero); Control.ControlBytesSend (Command.ReadInstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 7, ac.LoopID, ac.LoopID }, SendCount.Zero); Control.ControlBytesSend (Command.ReadInstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 8, ac.LoopID, ac.LoopID }, SendCount.Zero); Control.ControlBytesSend (Command.ReadInstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 19, ac.LoopID, ac.LoopID }, SendCount.Zero); Control.ControlBytesSend (Command.ReadPanelTempTypeACK, ac.SubnetID, ac.DeviceID, new byte [] { }, SendCount.Zero); Control.ControlBytesSend (Command.ReadPanleTemp, ac.SubnetID, ac.DeviceID, new byte [] { ac.LoopID }, SendCount.Zero); } else if (ac.Type == DeviceType.HVAC || ac.Type == DeviceType.ACInfrared) { Control.ControlBytesSendHasReturn (Command.ReadACMode, ac.SubnetID, ac.DeviceID, new byte [] { ac.LoopID }); } #if DEBUG #else } #endif }); } } }