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; /// /// 构造函数 /// /// Room. public UserACPage (AC ac, Room room) { this.ac = ac; this.room = room; curView = this; acM = new ACMethod (); BackgroundColor = SkinStyle.Current.MainColor; readStatus (ac); } /// /// 更新空调 /// /// Subnet identifier. /// Device identifier. /// Ac host bytes for updata. public static void UpdateStatus (AC ac) { Application.RunOnMainThread (() => { if (curView == null) { return; } if (curView.ac != ac) { return; } for (int i = 0; i < curView.acBodyView.ChildrenCount; i++) { try { if (ac.Power == 1) { curView.btnACSwitch.IsSelected = true; curView.btnInterior.Text = ac.IndoorTemperature.ToString () + "°C"; 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 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 = room.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 { Width = Application.GetRealWidth(640), Height = Application.GetRealHeight (1136 - 126), Y = Application.GetRealHeight (126) }; AddChidren (acBodyView); #region roomBackgroundImage var roomBackgroundImageView = new FrameLayout () { Height = Application.GetRealHeight (360), Width = Application.GetRealWidth(640), }; acBodyView.AddChidren (roomBackgroundImageView); roomBackgroundImageView.BackgroundImagePath = room.BackGroundImage; if (ac.Type == DeviceType.ACInfrared) { Button btnDownIRCode = new Button () { X = Application.GetRealWidth (500), Y = Application.GetRealHeight (20), Width = Application.GetMinRealAverage (131), Height = Application.GetMinRealAverage (131), UnSelectedImagePath = "TV/DownIRCodeIcon.png", SelectedImagePath = "TV/DownIRCodeIcon.png", }; roomBackgroundImageView.AddChidren (btnDownIRCode); btnDownIRCode.MouseUpEventHandler += (sender, e) => { var downIRCodeDialog = new ConfigIRCode (); downIRCodeDialog.Show (); downIRCodeDialog.ShowSystemInfrared (ac,true); }; } 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); 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, Text = ac.IndoorTemperature.ToString () + "°C", TextSize = 14, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1 }; setACTemp.AddChidren (btnInterior); //长按更换背景 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); }; #endregion #region acTemperature FrameLayout acTemperatureView = new FrameLayout () { Height = Application.GetRealHeight (550 / 3 - 40), Width = Application.GetRealWidth(640), 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 () + "°C", TextSize = 20, TextAlignment = TextAlignment.Center, Enable = false, TextColor = SkinStyle.Current.TextColor1 }; acTemperatureView.AddChidren (btnSetTemperature); 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 <= 0) { ac.SetTemperature = 16; } if (--ac.SetTemperature <= 16) { ac.SetTemperature = 16; } 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); 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.SetTemperature > 30) { ac.SetTemperature = 30; } 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); 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 = Application.GetRealHeight (550 / 3 + 20), 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; if (++ac.SetMode > 4) { ac.SetMode = 0; } UpdateStatus (ac); 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 ()); } } }; 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); 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 = Application.GetRealHeight (230), Width = Application.GetRealWidth(640), 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), Gravity = Gravity.CenterVertical, 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, Gravity = Gravity.CenterVertical, 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 = 0; //acM.UpdataACHostWindIcon (ac.SetFanSpeed, btnWindIcon); UpdateStatus (ac); 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); 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); } /// /// 读取设备状态 /// static void readStatus (AC ac) { System.Threading.Tasks.Task.Run (() => { if (ac.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now) { 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.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 }); } } }); } } }