| | |
| | | using System; |
| | | using Shared.Common; |
| | | using Shared.Phone.Device.DeviceLogic; |
| | | using Shared.Phone.UserCenter; |
| | | using Shared.Phone.UserView; |
| | | using ZigBee.Device; |
| | | |
| | | namespace Shared.Phone.Device.CommonForm |
| | | { |
| | | public class RoomView:FrameLayout |
| | | public class RoomView:FrameLayout, ZigBee.Common.IStatus |
| | | { |
| | | /// <summary> |
| | | /// Room |
| | |
| | | /// </summary> |
| | | public Action action; |
| | | |
| | | FrameLayout roomNameBackground; |
| | | |
| | | FrameLayout roomTemperatureBackground; |
| | | |
| | | Button roomListBtn; |
| | | |
| | | Button temperatureText; |
| | | |
| | | Button humidityText; |
| | | |
| | | CommonDevice temperDevice; |
| | | |
| | | CommonDevice humidDevice; |
| | | |
| | | #region ◆ 接口__________________________ |
| | | /// <summary> |
| | | /// 处理变化事件 --将弃用 改用DeviceInfoChange() |
| | | /// </summary> |
| | | /// <returns>The changed.</returns> |
| | | /// <param name="common">Common.</param> |
| | | public void Changed(CommonDevice common) |
| | | { |
| | | |
| | | } |
| | | /// <summary> |
| | | /// Changeds the IL ogic status. |
| | | /// </summary> |
| | | /// <param name="logic">Logic.</param> |
| | | public void ChangedILogicStatus(ZigBee.Device.Logic logic) |
| | | { |
| | | //throw new NotImplementedException(); |
| | | } |
| | | /// <summary> |
| | | /// Changeds the IS cene status. |
| | | /// </summary> |
| | | /// <param name="scene">Scene.</param> |
| | | public void ChangedISceneStatus(Scene scene) |
| | | { |
| | | //throw new NotImplementedException(); |
| | | } |
| | | /// <summary> |
| | | /// 设备状态更新接口 |
| | | /// <para>type:如果为 DeviceInComingRespon:设备新上报</para> |
| | | /// <para>type:如果为 IASInfoReport:RemoveDeviceRespon</para> |
| | | /// <para>type:如果为 DeviceStatusReport:设备上报</para> |
| | | /// <para>type:如果为 IASInfoReport:IAS安防信息上报</para> |
| | | /// <para>type:如果为 OnlineStatusChange: 设备在线状态更新</para> |
| | | /// </summary> |
| | | /// <param name="common">Common.</param> |
| | | /// <param name="typeTag">Type tag.</param> |
| | | public void DeviceInfoChange(CommonDevice common, string typeTag) |
| | | { |
| | | if (typeTag == "DeviceStatusReport") |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | try |
| | | { |
| | | if (common.DeviceStatusReport.AttriBute == null || common.DeviceStatusReport.AttriBute.Count == 0) |
| | | { |
| | | return; |
| | | } |
| | | //是否为当前设备 |
| | | if ((temperDevice?.DeviceEpoint != common.DeviceEpoint || temperDevice?.DeviceAddr != common.DeviceAddr) && (humidDevice?.DeviceEpoint != common.DeviceEpoint || humidDevice?.DeviceAddr != common.DeviceAddr) ) |
| | | { |
| | | //return; |
| | | } |
| | | |
| | | //if (common.Type == DeviceType.TemperatureSensor) |
| | | //{ |
| | | if (common.DeviceStatusReport.CluterID == 1026) |
| | | { |
| | | foreach (var data in common.DeviceStatusReport.AttriBute) |
| | | { |
| | | if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue) |
| | | { |
| | | if (data.AttriButeData == 0) |
| | | { |
| | | //0 |
| | | humidityText.Text = "--%"; |
| | | room.Humidity = 0; |
| | | } |
| | | else |
| | | { |
| | | //小数点需要一位(湿度没有负数) |
| | | string strValue = data.AttriButeData.ToString(); |
| | | strValue = strValue.Substring(0, strValue.Length - 1); |
| | | humidityText.Text = strValue.Insert(strValue.Length - 1, ".") + "%"; |
| | | room.Humidity = int.Parse(strValue) * 0.1; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else if (common.DeviceStatusReport.CluterID == 1029) |
| | | { |
| | | foreach (var data in common.DeviceStatusReport.AttriBute) |
| | | { |
| | | if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue) |
| | | { |
| | | if (data.AttriButeData == 0) |
| | | { |
| | | //0 |
| | | humidityText.Text = "--%"; |
| | | room.Humidity = 0; |
| | | } |
| | | else |
| | | { |
| | | //小数点需要一位(湿度没有负数) |
| | | string strValue = data.AttriButeData.ToString(); |
| | | strValue = strValue.Substring(0, strValue.Length - 1); |
| | | humidityText.Text = strValue.Insert(strValue.Length - 1, ".") + "%"; |
| | | room.Humidity = int.Parse(strValue) * 0.1; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //} |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Console.WriteLine($"Error:{ex.Message}"); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | public override void RemoveFromParent()
|
| | | {
|
| | | HdlGatewayReceiveLogic.Current.RemoveEvent("TemperatrueDevice");
|
| | | HdlGatewayReceiveLogic.Current.RemoveEvent("HumidityDevice");
|
| | | ZbGateway.StatusList.Remove(this);
|
| | | base.RemoveFromParent();
|
| | | } |
| | | |
| | |
| | | Y = Application.GetRealHeight(y); |
| | | Width = Application.GetRealWidth(717); |
| | | Height = Application.GetRealHeight(478); |
| | | ZbGateway.StatusList.Add(this); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | public void Init(Common.Room r) |
| | | { |
| | | this.room = r; |
| | | |
| | | this.temperDevice= Common.LocalDevice.Current.GetDevice(room.TemperatrueDevice); |
| | | |
| | | this.humidDevice= Common.LocalDevice.Current.GetDevice(room.HumidityDevice); |
| | | |
| | | var roomBackView = new FrameLayout() |
| | | { |
| | |
| | | }; |
| | | roomBackView.AddChidren(roomImg); |
| | | |
| | | var roomNameBackground = new FrameLayout |
| | | roomNameBackground = new FrameLayout |
| | | { |
| | | X = Application.GetRealWidth(29), |
| | | Y = Application.GetRealHeight(282), |
| | |
| | | Width = Application.GetRealWidth(190), |
| | | Text = room.Name, |
| | | TextColor = ZigbeeColor.Current.GXCTextWhiteColor, |
| | | TextSize=10, |
| | | IsBold=true |
| | | }; |
| | | roomNameBackground.AddChidren(roomName); |
| | | |
| | | |
| | | var roomTemperatureBackground = new FrameLayout |
| | | roomTemperatureBackground = new FrameLayout |
| | | { |
| | | X = Application.GetRealWidth(29), |
| | | Y = Application.GetRealHeight(374), |
| | |
| | | }; |
| | | roomTemperatureBackground.AddChidren(temperatureIcon); |
| | | |
| | | var temperatureText = new Button |
| | | temperatureText = new Button |
| | | { |
| | | X = Application.GetRealWidth(69), |
| | | Width = Application.GetRealWidth(120), |
| | | Height = Application.GetRealHeight(58), |
| | | Gravity = Gravity.CenterVertical, |
| | | Text = $"{room.Temperatrue}℃" |
| | | Text = Math.Abs(room.Temperatrue) <= 0 ? "--℃" : $"{room.Temperatrue}℃", |
| | | TextSize=14 |
| | | }; |
| | | roomTemperatureBackground.AddChidren(temperatureText); |
| | | |
| | |
| | | }; |
| | | roomTemperatureBackground.AddChidren(humidityIcon); |
| | | |
| | | var humidityText = new Button |
| | | humidityText = new Button |
| | | { |
| | | X = Application.GetRealWidth(260), |
| | | Width = Application.GetRealWidth(120), |
| | | Height = Application.GetRealHeight(58), |
| | | Gravity = Gravity.CenterVertical, |
| | | Text = $"{room.Humidity}%" |
| | | Text = Math.Abs(room.Temperatrue) <= 0 ? "--%" : $"{room.Humidity}%", |
| | | TextSize=14 |
| | | }; |
| | | roomTemperatureBackground.AddChidren(humidityText); |
| | | |
| | | |
| | | if (string.IsNullOrEmpty(room.TemperatrueDevice) == false) |
| | | { |
| | | HdlGatewayReceiveLogic.Current.RemoveEvent("TemperatrueDevice"); |
| | | HdlGatewayReceiveLogic.Current.AddAttributeEvent("TemperatrueDevice", ReceiveComandDiv.A设备属性上报, (Action<ZigBee.Device.CommonDevice>)((report) => |
| | | { |
| | | string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(report); |
| | | if (room.TemperatrueDevice != mainKeys) |
| | | { |
| | | return; |
| | | } |
| | | //移除掉事件 |
| | | HdlGatewayReceiveLogic.Current.RemoveEvent("TemperatrueDevice"); |
| | | |
| | | foreach (var data in report.DeviceStatusReport.AttriBute) |
| | | { |
| | | if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue) |
| | | { |
| | | if (data.AttriButeData == 0) |
| | | { |
| | | //0℃ |
| | | temperatureText.Text = "0.0℃"; |
| | | room.Temperatrue = 0; |
| | | } |
| | | else if (data.AttriButeData > 32767) |
| | | { |
| | | //负数(特殊处理) |
| | | string strValue = (data.AttriButeData - 65536).ToString(); |
| | | //小数点需要一位 |
| | | strValue = strValue.Substring(0, strValue.Length - 1); |
| | | temperatureText.Text = strValue.Insert(strValue.Length - 1, ".") + "℃"; |
| | | room.Temperatrue = int.Parse(strValue) * 0.1; |
| | | } |
| | | else |
| | | { |
| | | //小数点需要一位 |
| | | string strValue = data.AttriButeData.ToString(); |
| | | strValue = strValue.Substring(0, strValue.Length - 1); |
| | | temperatureText.Text = strValue.Insert(strValue.Length - 1, ".") + "℃"; |
| | | room.Temperatrue = int.Parse(strValue) * 0.1; |
| | | } |
| | | } |
| | | } |
| | | })); |
| | | //发送获取温度的命令 |
| | | var dev = Common.LocalDevice.Current.GetDevice(room.TemperatrueDevice); |
| | | if (dev != null) |
| | | { |
| | | (dev as ZigBee.Device.TemperatureSensor).ReadTemperatureOrHumidity(); |
| | | } |
| | | ReadDeviceAttributeLogic.Instance.SendTemperatureStatuComand(dev); |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(room.HumidityDevice) == false) |
| | | { |
| | | HdlGatewayReceiveLogic.Current.RemoveEvent("HumidityDevice"); |
| | | HdlGatewayReceiveLogic.Current.AddAttributeEvent("HumidityDevice", ReceiveComandDiv.A设备属性上报, (report) => |
| | | { |
| | | string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(report); |
| | | if (room.HumidityDevice != mainKeys) |
| | | { |
| | | return; |
| | | } |
| | | //移除掉事件 |
| | | HdlGatewayReceiveLogic.Current.RemoveEvent("HumidityDevice"); |
| | | foreach (var data in report.DeviceStatusReport.AttriBute) |
| | | { |
| | | if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue) |
| | | { |
| | | if (data.AttriButeData == 0) |
| | | { |
| | | //0 |
| | | humidityText.Text = "0.0%"; |
| | | room.Humidity = 0; |
| | | } |
| | | else |
| | | { |
| | | //小数点需要一位(湿度没有负数) |
| | | string strValue = data.AttriButeData.ToString(); |
| | | strValue = strValue.Substring(0, strValue.Length - 1); |
| | | humidityText.Text = strValue.Insert(strValue.Length - 1, ".") + "%"; |
| | | room.Humidity = int.Parse(strValue) * 0.1; |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | //发送获取湿度的命令 |
| | | var dev = Common.LocalDevice.Current.GetDevice(room.HumidityDevice); |
| | | if (dev != null) |
| | | { |
| | | (dev as ZigBee.Device.TemperatureSensor).ReadTemperatureOrHumidity(); |
| | | } |
| | | ReadDeviceAttributeLogic.Instance.SendHumidityStatuComand(dev); |
| | | } |
| | | |
| | | |
| | | var roomListBtn = new Button() |
| | | roomListBtn = new Button() |
| | | { |
| | | X = roomBackView.Width - Application.GetRealWidth(100 + 20), |
| | | Y = Application.GetRealHeight(20), |
| | |
| | | }; |
| | | }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// HideName |
| | | /// </summary> |
| | | public void HideName(bool statu) |
| | | { |
| | | roomNameBackground.Visible = roomTemperatureBackground.Visible = roomListBtn.Visible = !statu; |
| | | } |
| | | } |
| | | } |