From f71e74b5f0d2716fbf05da016cdaa18d64e09f80 Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期四, 31 十二月 2020 17:01:18 +0800 Subject: [PATCH] 又换完成最新门锁。空气质量传感器完成数据和基本配置功能。开发图表和自动化的同事可下载此代码 --- ZigbeeApp/Shared/Phone/UserCenter/Device/AirConditioner/IndoorUnitListForm.cs | 435 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 435 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/AirConditioner/IndoorUnitListForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/AirConditioner/IndoorUnitListForm.cs new file mode 100755 index 0000000..867258a --- /dev/null +++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/AirConditioner/IndoorUnitListForm.cs @@ -0,0 +1,435 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Text; +using ZigBee.Device; + +namespace Shared.Phone.UserCenter.DeviceAirConditioner +{ + /// <summary> + /// 绌鸿皟鐨勫鍐呮満鍒楄〃鐣岄潰 + /// </summary> + public class IndoorUnitListForm : EditorCommonForm + { + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 璁惧鍒楄〃 + /// </summary> + private List<CommonDevice> listDevice = null; + /// <summary> + /// 鎺т欢淇℃伅 + /// </summary> + private Dictionary<string, RowControlInfo> dicControl = new Dictionary<string, RowControlInfo>(); + /// <summary> + /// 婵�娲荤殑璁惧鍦板潃 + /// </summary> + private string actionDeviceKeys = null; + /// <summary> + /// 鎺ユ敹鍥炲鐨勭鐐� + /// </summary> + private HashSet<int> listReceivePoint = new HashSet<int>(); + + #endregion + + #region 鈻� 鍒濆鍖朹____________________________ + + /// <summary> + /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓) + /// </summary> + /// <param name="i_diviceMac">璁惧Mac鍦板潃</param> + public void ShowForm(string i_diviceMac) + { + this.listDevice = Common.LocalDevice.Current.GetDevicesByMac(i_diviceMac); + //鏀堕泦鍏ㄩ儴绔偣 + foreach (var device in this.listDevice) + { + listReceivePoint.Add(device.DeviceEpoint); + } + //璁剧疆澶撮儴淇℃伅 + base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uIndoorUnitSettion)); + + //鍒濆鍖栦腑閮ㄤ俊鎭� + this.InitMiddleFrame(); + } + + /// <summary> + /// 鍒濆鍖栦腑閮ㄤ俊鎭� + /// </summary> + private void InitMiddleFrame() + { + //娓呯┖bodyFrame + this.ClearBodyFrame(); + + var listView = new VerticalFrameControl(14); + listView.Height = bodyFrameLayout.Height; + bodyFrameLayout.AddChidren(listView); + + var frameTemp = new FrameLayout(); + frameTemp.Height = Application.GetRealHeight(69); + listView.AddChidren(frameTemp); + + HdlThreadLogic.Current.RunMainInThread(() => + { + for (int i = 0; i < listDevice.Count; i++) + { + //娣诲姞绌鸿皟琛� + this.AddAcControlRow(listView, (AC)listDevice[i]); + } + var frameTemp2 = new FrameLayout(); + frameTemp2.Height = Application.GetRealHeight(29); + listView.AddChidren(frameTemp2); + + //鏁版嵁鎺ユ敹 + this.StartReceiveDataEvent(); + //鍙戦�佽鍙栧睘鎬х殑鍛戒护 + this.SetReadAttributeComand(); + }); + } + + /// <summary> + /// 娣诲姞绌鸿皟琛� + /// </summary> + /// <param name="listView"></param> + /// <param name="device"></param> + private void AddAcControlRow(VerticalFrameControl listView, AC device) + { + var rowInfo = new RowControlInfo(); + + var frameTable = new FrameLayoutStatuControl(); + frameTable.UseClickStatu = false; + frameTable.Width = Application.GetRealWidth(994); + frameTable.Height = Application.GetRealHeight(337); + frameTable.BackgroundImagePath = "Item/IndoorUnitGround.png"; + frameTable.Gravity = Gravity.CenterHorizontal; + listView.AddChidren(frameTable); + + //璁惧鍥炬爣 + var btnIconBack = new FrameLayout(); + btnIconBack.X = Application.GetRealWidth(46); + btnIconBack.Y = Application.GetRealHeight(43); + btnIconBack.Height = this.GetPictrueRealSize(112); + btnIconBack.Width = this.GetPictrueRealSize(112); + btnIconBack.Radius = (uint)this.GetPictrueRealSize(112) / 2; + btnIconBack.BackgroundColor = 0xfff5f6fa; + frameTable.AddChidren(btnIconBack, ChidrenBindMode.NotBind); + rowInfo.btnIconBack = btnIconBack; + + var btnIcon = new IconViewControl(78); + btnIcon.Gravity = Gravity.Center; + Common.LocalDevice.Current.SetDeviceIconToControl(btnIcon, device); + btnIconBack.AddChidren(btnIcon); + frameTable.ChangedChidrenBindMode(btnIconBack, ChidrenBindMode.BindEvent); + rowInfo.btnIcon = btnIcon; + + //璁惧鍚嶇О + var btnDeviceName = new NormalViewControl(700, 60, true); + btnDeviceName.Text = Common.LocalDevice.Current.GetDeviceEpointName(device); + btnDeviceName.X = Application.GetRealWidth(193); + btnDeviceName.Y = Application.GetRealHeight(45); + frameTable.AddChidren(btnDeviceName, ChidrenBindMode.BindEvent); + rowInfo.btnDeviceName = btnDeviceName; + //鎴块棿 + var btnRoom = new NormalViewControl(400, 50, true); + btnRoom.X = btnDeviceName.X; + btnRoom.Y = btnDeviceName.Bottom + Application.GetRealHeight(12); + btnRoom.TextSize = 12; + btnRoom.TextColor = UserCenterColor.Current.TextGrayColor1; + btnRoom.Text = HdlRoomLogic.Current.GetRoomNameByDevice(device); + frameTable.AddChidren(btnRoom, ChidrenBindMode.BindEvent); + rowInfo.btnRoom = btnRoom; + //鎽勬皬搴� + var btnValue = new NormalViewControl(300, 60, true); + btnValue.Y = Application.GetRealHeight(58); + btnValue.X = frameTable.Width - Application.GetRealWidth(300 + 58); + btnValue.TextAlignment = TextAlignment.CenterRight; + frameTable.AddChidren(btnValue, ChidrenBindMode.BindEvent); + rowInfo.btnValue = btnValue; + //瀹ゅ唴娓╁害 + if (device.currentLocalTemperature == 0) + { + //0鈩� + btnValue.Text = "0.0鈩�"; + } + else + { + btnValue.Text = device.currentLocalTemperature + ".0鈩�"; + } + + //璀﹀憡鍥炬爣 + var btnWarningIcon = new IconViewControl(69); + btnWarningIcon.X = btnIconBack.X; + btnWarningIcon.Y = btnRoom.Bottom + Application.GetRealHeight(43); + btnWarningIcon.UnSelectedImagePath = "Item/WarningIcon1.png"; + frameTable.AddChidren(btnWarningIcon, ChidrenBindMode.NotBind); + btnWarningIcon.Visible = false; + rowInfo.btnWarningIcon = btnWarningIcon; + //璀﹀憡淇℃伅 + var btnWarningMsg = new NormalViewControl(500, 50, true); + btnWarningMsg.X = btnWarningIcon.Right + Application.GetRealWidth(12); + btnWarningMsg.Y = btnRoom.Bottom + Application.GetRealHeight(55); + btnWarningMsg.TextSize = 12; + btnWarningMsg.TextColor = UserCenterColor.Current.TextGrayColor1; + frameTable.AddChidren(btnWarningMsg, ChidrenBindMode.NotBind); + rowInfo.btnWarningMsg = btnWarningMsg; + //寮�鍏� + var btnSwitch = new IconViewControl(69); + btnSwitch.X = frameTable.Width - Application.GetRealWidth(69 + 46); + btnSwitch.Y = btnRoom.Bottom + Application.GetRealHeight(43); + btnSwitch.UnSelectedImagePath = "Item/Switch.png"; + btnSwitch.SelectedImagePath = "Item/SwitchSelected.png"; + frameTable.AddChidren(btnSwitch, ChidrenBindMode.NotBind); + rowInfo.btnSwitch = btnSwitch; + btnSwitch.ButtonClickEvent += async (sender, e) => + { + if (btnSwitch.IsSelected == false) + { + //濡傛灉涓嶆槸铏氭嫙浣忓畢鐨勮瘽 + if (Common.Config.Instance.Home.IsVirtually == false) + { + //鎵撳紑绌鸿皟 + var result = await HdlDeviceAirConditionerLogic.Current.OpenAirConditioner(device); + if (result == false) + { + return; + } + } + btnIcon.IsSelected = true; + btnIconBack.BackgroundColor = 0xfffef1ed; + } + else + { + //濡傛灉涓嶆槸铏氭嫙浣忓畢鐨勮瘽 + if (Common.Config.Instance.Home.IsVirtually == false) + { + //鍏抽棴绌鸿皟 + var result = await HdlDeviceAirConditionerLogic.Current.CloseAirConditioner(device); + if (result == false) + { + return; + } + } + btnIcon.IsSelected = false; + btnIconBack.BackgroundColor = 0xfff5f6fa; + } + btnSwitch.IsSelected = !btnSwitch.IsSelected; + //濡傛灉鏄櫄鎷熶綇瀹呯殑璇� + if (Common.Config.Instance.Home.IsVirtually == true) + { + device.currentSystemMode = btnSwitch.IsSelected == true ? 3 : 0; + } + }; + //濡傛灉鏄睍绀烘ā鏉跨殑璇� + if (Common.Config.Instance.Home.IsShowTemplate == true) + { + btnSwitch.CanClick = false; + } + + frameTable.ButtonClickEvent += (sender, e) => + { + this.actionDeviceKeys = Common.LocalDevice.Current.GetDeviceMainKeys(device); + + var form = new IndoorUnitSettionForm(); + form.AddForm(device); + }; + + dicControl[Common.LocalDevice.Current.GetDeviceMainKeys(device)] = rowInfo; + } + + #endregion + + #region 鈻� 鍙戦�佸懡浠__________________________ + + /// <summary> + /// 鍙戦�佽鍙栧睘鎬х殑鍛戒护 + /// </summary> + private void SetReadAttributeComand() + { + //濡傛灉鏄櫄鎷熶綇瀹呮垨鑰呭睍绀烘ā鏉跨殑璇� + if (Common.Config.Instance.Home.IsShowTemplate == true || Common.Config.Instance.Home.IsVirtually == true) + { + return; + } + HdlThreadLogic.Current.RunThread(() => + { + while (this.listReceivePoint.Count > 0 && this.Parent != null) + { + for (int i = 0; i < listDevice.Count; i++) + { + if (this.Parent == null) + { + return; + } + //宸茬粡鍙戦�佽繃浜�,灏变笉鐢ㄥ啀鍙戦�� + if (this.listReceivePoint.Contains(listDevice[i].DeviceEpoint) == true) + { + //璇诲彇鐘舵�� + HdlDeviceAttributeLogic.Current.SendThermostatStatuComand(listDevice[i]); + System.Threading.Thread.Sleep(200); + } + } + //3绉掑悗鍐嶆寰幆 + System.Threading.Thread.Sleep(3000); + } + }); + } + + #endregion + + #region 鈻� 鏁版嵁鎺ユ敹___________________________ + + /// <summary> + /// 鏁版嵁鎺ユ敹 + /// </summary> + private void StartReceiveDataEvent() + { + HdlGatewayReceiveLogic.Current.AddAttributeEvent("IndoorUnitListFormEvent", ReceiveComandDiv.A璁惧灞炴�т笂鎶�, (device) => + { + string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device); + if (dicControl.ContainsKey(mainkeys) == false || device.DeviceStatusReport.CluterID != 513) + { + return; + } + var localDevice = Common.LocalDevice.Current.GetDevice(mainkeys); + if (localDevice == null) + { + return; + } + //宸茬粡鎺ユ敹鍒版暟鎹�,鍒欑Щ闄ょ鐐� + this.listReceivePoint.Remove(device.DeviceEpoint); + + var rowInfo = dicControl[mainkeys]; + for (int i = 0; i < device.DeviceStatusReport.AttriBute.Count; i++) + { + var data = device.DeviceStatusReport.AttriBute[i]; + if (data.AttributeId == 0) + { + HdlThreadLogic.Current.RunMain(() => + { + //瀹ゅ唴娓╁害 + if (((AC)localDevice).currentLocalTemperature == 0) + { + //0鈩� + rowInfo.btnValue.Text = "0.0鈩�"; + } + else + { + rowInfo.btnValue.Text = ((AC)localDevice).currentLocalTemperature + ".0鈩�"; + } + }); + } + else if (data.AttributeId == 28) + { + //姝ゅ睘鎬ф弿杩版亽娓╄澶囨澶勪簬鍝妯″紡 + //Off = 0 Auto = 1 Cool = 3 Heat = 4 FanOnly = 7 Dry = 8 + if (data.AttriButeData != 0) + { + HdlThreadLogic.Current.RunMain(() => + { + rowInfo.btnSwitch.IsSelected = true; + rowInfo.btnIcon.IsSelected = true; + rowInfo.btnIconBack.BackgroundColor = 0xfffef1ed; + }); + } + } + else if (data.AttributeId == 4097) + { + //42:闇�瑕佹竻娲楁护缃� + if (data.AttriButeData == 42) + { + HdlThreadLogic.Current.RunMain(() => + { + rowInfo.btnWarningIcon.Visible = true; + //璇锋敞鎰忔竻娲楁护缃戝摝 + rowInfo.btnWarningMsg.TextID = R.MyInternationalizationString.uPleaseClreanACfilter; + }); + } + } + } + }); + } + + #endregion + + #region 鈻� 鐣岄潰鍏抽棴___________________________ + + /// <summary> + /// 鐣岄潰鍏抽棴 + /// </summary> + public override void CloseFormBefore() + { + HdlGatewayReceiveLogic.Current.RemoveEvent("IndoorUnitListFormEvent"); + + base.CloseFormBefore(); + } + + #endregion + + #region 鈻� 鐣岄潰閲嶆柊婵�娲讳簨浠禵__________________ + + /// <summary> + /// 鑷韩鐨勪笂灞傜晫闈㈠叧闂悗,瀹冭嚜韬浜庢渶涓婂眰鏃�,瑙﹀彂鐨勪簨浠� + /// </summary> + public override int FormActionAgainEvent() + { + if (this.actionDeviceKeys != null && dicControl.ContainsKey(this.actionDeviceKeys) == true) + { + //鍒锋柊璁惧淇℃伅 + var device = Common.LocalDevice.Current.GetDevice(this.actionDeviceKeys); + if (device != null) + { + var contr = dicControl[this.actionDeviceKeys]; + contr.btnDeviceName.Text = Common.LocalDevice.Current.GetDeviceEpointName(device); + contr.btnRoom.Text = HdlRoomLogic.Current.GetRoomNameByDevice(device); + } + } + this.actionDeviceKeys = null; + + return 1; + } + + #endregion + + #region 鈻� 缁撴瀯浣揰____________________________ + + /// <summary> + /// 琛屾暟鎹� + /// </summary> + private class RowControlInfo + { + /// <summary> + /// 璁惧鍚嶅瓧 + /// </summary> + public NormalViewControl btnDeviceName = null; + /// <summary> + /// 璁惧鎴块棿 + /// </summary> + public NormalViewControl btnRoom = null; + /// <summary> + /// 璁惧鍥炬爣鑳屾櫙 + /// </summary> + public FrameLayout btnIconBack = null; + /// <summary> + /// 璁惧鍥炬爣 + /// </summary> + public IconViewControl btnIcon = null; + /// <summary> + /// 鎽勬皬搴� + /// </summary> + public NormalViewControl btnValue = null; + /// <summary> + /// 璀﹀憡鍥炬爣 + /// </summary> + public IconViewControl btnWarningIcon = null; + /// <summary> + /// 璀﹀憡淇℃伅 + /// </summary> + public NormalViewControl btnWarningMsg = null; + /// <summary> + /// 寮�鍏� + /// </summary> + public IconViewControl btnSwitch = null; + } + + #endregion + } +} -- Gitblit v1.8.0