| | |
| | | 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, ZigBee.Common.IStatus |
| | | public class RoomView : FrameLayout |
| | | { |
| | | /// <summary> |
| | | /// Room |
| | | /// </summary> |
| | | private Common.Room room; |
| | | /// <summary> |
| | | /// action |
| | | /// </summary> |
| | | public Action action; |
| | | |
| | | FrameLayout roomNameBackground; |
| | | |
| | |
| | | Button temperatureText; |
| | | |
| | | Button humidityText; |
| | | |
| | | CommonDevice temperDevice; |
| | | |
| | | CommonDevice humidDevice; |
| | | |
| | | #region ◆ 接口__________________________ |
| | | /// <summary> |
| | | /// 处理变化事件 --将弃用 改用DeviceInfoChange() |
| | | /// <summary>
|
| | | /// 温度设备
|
| | | /// </summary> |
| | | /// <returns>The changed.</returns> |
| | | /// <param name="common">Common.</param> |
| | | public void Changed(CommonDevice common) |
| | | { |
| | | |
| | | } |
| | | /// <summary> |
| | | /// Changeds the IL ogic status. |
| | | private CommonDevice temperDevice = null; |
| | | /// <summary>
|
| | | /// 湿度设备
|
| | | /// </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℃ |
| | | 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 = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, ".")); |
| | | } |
| | | else |
| | | { |
| | | //小数点需要一位 |
| | | string strValue = data.AttriButeData.ToString(); |
| | | strValue = strValue.Substring(0, strValue.Length - 1); |
| | | temperatureText.Text = strValue.Insert(strValue.Length - 1, ".") + "℃"; |
| | | room.Temperatrue = Convert.ToDecimal(strValue.Insert(strValue.Length - 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 = Convert.ToDecimal(strValue.Insert(strValue.Length - 1, ".")); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //} |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Console.WriteLine($"Error:{ex.Message}"); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | public override void RemoveFromParent()
|
| | | {
|
| | | ZbGateway.StatusList.Remove(this);
|
| | | base.RemoveFromParent();
|
| | | } |
| | | private CommonDevice humidDevice = null; |
| | | |
| | | /// <summary> |
| | | /// RoomView |
| | |
| | | Y = Application.GetRealHeight(y); |
| | | Width = Application.GetRealWidth(717); |
| | | Height = Application.GetRealHeight(478); |
| | | ZbGateway.StatusList.Add(this); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <param name="r"></param> |
| | | public void Init(Common.Room r) |
| | | { |
| | | this.RemoveAll(); |
| | | |
| | | this.room = r; |
| | | |
| | | this.temperDevice= Common.LocalDevice.Current.GetDevice(room.TemperatrueDevice); |
| | | this.temperDevice = Common.LocalDevice.Current.GetDevice(room.TemperatrueDevice); |
| | | |
| | | this.humidDevice= Common.LocalDevice.Current.GetDevice(room.HumidityDevice); |
| | | this.humidDevice = Common.LocalDevice.Current.GetDevice(room.HumidityDevice); |
| | | |
| | | var roomBackView = new FrameLayout() |
| | | { |
| | | Width = Application.GetRealWidth(717), |
| | | Height = Application.GetRealHeight(478) |
| | | Height = Application.GetRealHeight(478), |
| | | Radius = (uint)Application.GetRealHeight(17), |
| | | Tag = "R" |
| | | }; |
| | | AddChidren(roomBackView); |
| | | |
| | | var roomImg = new ImageView() |
| | | { |
| | | ImagePath = room.BackgroundImageType == 0 ? room.BackgroundImage : System.IO.Path.Combine(Config.Instance.FullPath, room.BackgroundImage), |
| | | Radius = (uint)Application.GetRealHeight(17) |
| | | Radius = (uint)Application.GetRealHeight(17), |
| | | Tag = "R" |
| | | }; |
| | | roomBackView.AddChidren(roomImg); |
| | | |
| | | //加个特殊的遮罩 |
| | | var frameBackGroudTemp = new FrameLayout(); |
| | | frameBackGroudTemp.Width = roomBackView.Width; |
| | | frameBackGroudTemp.Height = roomBackView.Height; |
| | | frameBackGroudTemp.Radius = (uint)Application.GetRealHeight(17); |
| | | frameBackGroudTemp.BackgroundColor = UserCenterColor.Current.PictrueZhezhaoColor; |
| | | roomBackView.AddChidren(frameBackGroudTemp); |
| | | |
| | | roomNameBackground = new FrameLayout |
| | | { |
| | |
| | | Text = room.Name, |
| | | TextColor = ZigbeeColor.Current.GXCTextWhiteColor, |
| | | TextSize = 10, |
| | | TextAlignment=TextAlignment.CenterLeft, |
| | | TextAlignment = TextAlignment.CenterLeft, |
| | | IsBold = true |
| | | }; |
| | | roomNameBackground.AddChidren(roomName); |
| | |
| | | Width = Application.GetRealWidth(120), |
| | | Text = "--℃", |
| | | TextSize = 14, |
| | | TextAlignment=TextAlignment.CenterLeft |
| | | TextAlignment = TextAlignment.CenterLeft |
| | | }; |
| | | if (string.IsNullOrEmpty(room.TemperatrueDevice) == false) |
| | | if (LocalDevice.Current.GetDevice(room.TemperatrueDevice) != null) |
| | | {
|
| | | //这个设备要存在本地才行
|
| | | temperatureText.Text = room.Temperatrue == 0 ? "0.0℃" : room.Temperatrue.ToString() + "℃"; |
| | | } |
| | | roomTemperatureBackground.AddChidren(temperatureText); |
| | |
| | | TextSize = 14, |
| | | TextAlignment = TextAlignment.CenterLeft |
| | | }; |
| | | if (string.IsNullOrEmpty(room.HumidityDevice) == false) |
| | | if (LocalDevice.Current.GetDevice(room.HumidityDevice) != null) |
| | | {
|
| | | //这个设备要存在本地才行
|
| | | humidityText.Text = room.Humidity == 0 ? "0.0%" : room.Humidity.ToString() + "%"; |
| | | } |
| | | roomTemperatureBackground.AddChidren(humidityText); |
| | |
| | | form.AddForm(room); |
| | | form.FinishEditorEvent += (roomName2) =>
|
| | | {
|
| | | action?.Invoke();
|
| | | //重新刷新控件
|
| | | this.Init(this.room);
|
| | | }; |
| | | }; |
| | | //设备属性上报 |
| | | HdlGatewayReceiveLogic.Current.AddAttributeEvent("RoomView" + this.room.Id, ReceiveComandDiv.A设备属性上报, (report) =>
|
| | | { |
| | | if (this.temperDevice != null)
|
| | | {
|
| | | //温度设备
|
| | | if (report.DeviceAddr == temperDevice.DeviceAddr && report.DeviceEpoint == temperDevice.DeviceEpoint)
|
| | | {
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | if (((TemperatureSensor)temperDevice).Temperatrue == 0)
|
| | | {
|
| | | temperatureText.Text = "0.0℃";
|
| | | }
|
| | | else
|
| | | {
|
| | | temperatureText.Text = ((TemperatureSensor)temperDevice).Temperatrue + "℃";
|
| | | }
|
| | | }, ShowErrorMode.NO);
|
| | | }
|
| | | } |
| | | if (this.humidDevice != null)
|
| | | {
|
| | | //湿度设备
|
| | | if (report.DeviceAddr == humidDevice.DeviceAddr && report.DeviceEpoint == humidDevice.DeviceEpoint)
|
| | | {
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | if (((TemperatureSensor)temperDevice).Humidity == 0)
|
| | | {
|
| | | humidityText.Text = "--%";
|
| | | }
|
| | | else
|
| | | {
|
| | | humidityText.Text = ((TemperatureSensor)temperDevice).Humidity + "%";
|
| | | }
|
| | | }, ShowErrorMode.NO);
|
| | | }
|
| | | } |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | public void HideName(bool statu) |
| | | { |
| | | roomNameBackground.Visible = roomTemperatureBackground.Visible = roomListBtn.Visible = !statu; |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// |
| | | /// </summary>
|
| | | public override void RemoveFromParent()
|
| | | {
|
| | | HdlGatewayReceiveLogic.Current.RemoveEvent("RoomView" + this.room.Id);
|
| | | base.RemoveFromParent();
|
| | | } |
| | | } |
| | | } |