| | |
| | | rowTemperature.AddBottomLine();
|
| | | rowTemperature.ButtonClickEvent += (sender, e) =>
|
| | | {
|
| | | //显示温度传感器列表
|
| | | this.ShowTemperatrueDevice(btnTemper);
|
| | | };
|
| | |
|
| | | //【湿度】
|
| | |
| | | rowHumidity.AddBottomLine();
|
| | | rowHumidity.ButtonClickEvent += (sender, e) =>
|
| | | {
|
| | | //显示湿度传感器列表
|
| | | this.ShowHumidityDevice(btnHumi);
|
| | | };
|
| | |
|
| | | //初始化桌布完成
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 温度传感器相关_____________________
|
| | |
|
| | | /// <summary>
|
| | | /// 显示温度传感器列表
|
| | | /// </summary>
|
| | | /// <param name="btnTemper"></param>
|
| | | private void ShowTemperatrueDevice(NormalViewControl btnTemper)
|
| | | {
|
| | | var listDevice = new List<ZigBee.Device.CommonDevice>();
|
| | | foreach (var device in Common.LocalDevice.Current.listAllDevice)
|
| | | {
|
| | | //获取温度传感器
|
| | | if (device is ZigBee.Device.TemperatureSensor && ((ZigBee.Device.TemperatureSensor)device).SensorDiv == 1)
|
| | | {
|
| | | listDevice.Add(device);
|
| | | }
|
| | | }
|
| | | var listSelect = new List<string>() { newRoom.TemperatrueDevice };
|
| | | var form = new SelectDeviceForm();
|
| | | form.AddForm(listDevice, listSelect, true, true);
|
| | | form.ActionSelectDevice += (list) =>
|
| | | {
|
| | | if (list.Count == 0)
|
| | | {
|
| | | newRoom.TemperatrueDevice = string.Empty;
|
| | | btnTemper.Text = Language.StringByID(R.MyInternationalizationString.uNothing);
|
| | | return;
|
| | | }
|
| | | newRoom.TemperatrueDevice = Common.LocalDevice.Current.GetDeviceMainKeys(list[0]);
|
| | | //获取温度值
|
| | | this.GetTemperatrueValue(btnTemper, newRoom.TemperatrueDevice);
|
| | | };
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取温度值
|
| | | /// </summary>
|
| | | /// <param name="btnHumi"></param>
|
| | | /// <param name="deviceKey"></param>
|
| | | private void GetTemperatrueValue(NormalViewControl btnTemper, string deviceKey)
|
| | | {
|
| | | var device = Common.LocalDevice.Current.GetDevice(deviceKey);
|
| | | if (device == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //获取中...
|
| | | btnTemper.Text = Language.StringByID(R.MyInternationalizationString.uGetting);
|
| | |
|
| | | HdlDeviceAttributeLogic.Current.RemoveEvent("TemperatrueDevice");
|
| | | HdlDeviceAttributeLogic.Current.AddAttributeEvent("TemperatrueDevice", "DeviceStatusReport", (Action<ZigBee.Device.CommonDevice>)((report) =>
|
| | | {
|
| | | string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(report);
|
| | | if (newRoom.TemperatrueDevice != mainKeys || btnTemper == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //移除掉事件
|
| | | HdlDeviceAttributeLogic.Current.RemoveEvent("TemperatrueDevice");
|
| | |
|
| | | foreach (var data in report.DeviceStatusReport.AttriBute)
|
| | | {
|
| | | if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue)
|
| | | {
|
| | | if (data.AttriButeData == 0)
|
| | | {
|
| | | //0℃
|
| | | btnTemper.Text = "0.0℃";
|
| | | }
|
| | | else if (data.AttriButeData > 32767)
|
| | | {
|
| | | //负数(特殊处理)
|
| | | string strValue = (data.AttriButeData - 65536).ToString();
|
| | | //小数点需要一位
|
| | | strValue = strValue.Substring(0, strValue.Length - 1);
|
| | | btnTemper.Text = strValue.Insert(strValue.Length - 1, ".") + "℃";
|
| | | }
|
| | | else
|
| | | {
|
| | | //小数点需要一位
|
| | | string strValue = data.AttriButeData.ToString();
|
| | | strValue = strValue.Substring(0, strValue.Length - 1);
|
| | | btnTemper.Text = strValue.Insert(strValue.Length - 1, ".") + "℃";
|
| | | }
|
| | | }
|
| | | }
|
| | | }));
|
| | | //发送获取温度的命令
|
| | | ((ZigBee.Device.TemperatureSensor)device).ReadTemperatureOrHumidity();
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 湿度传感器相关_____________________
|
| | |
|
| | | /// <summary>
|
| | | /// 显示湿度传感器列表
|
| | | /// </summary>
|
| | | /// <param name="btnHumi"></param>
|
| | | private void ShowHumidityDevice(NormalViewControl btnHumi)
|
| | | {
|
| | | var listDevice = new List<ZigBee.Device.CommonDevice>();
|
| | | foreach (var device in Common.LocalDevice.Current.listAllDevice)
|
| | | {
|
| | | //获取湿度传感器
|
| | | if (device is ZigBee.Device.TemperatureSensor && ((ZigBee.Device.TemperatureSensor)device).SensorDiv == 2)
|
| | | {
|
| | | listDevice.Add(device);
|
| | | }
|
| | | }
|
| | | var listSelect = new List<string>() { newRoom.HumidityDevice };
|
| | | var form = new SelectDeviceForm();
|
| | | form.AddForm(listDevice, listSelect, true, true);
|
| | | form.ActionSelectDevice += (list) =>
|
| | | {
|
| | | if (list.Count == 0)
|
| | | {
|
| | | newRoom.HumidityDevice = string.Empty;
|
| | | btnHumi.Text = Language.StringByID(R.MyInternationalizationString.uNothing);
|
| | | return;
|
| | | }
|
| | | newRoom.HumidityDevice = Common.LocalDevice.Current.GetDeviceMainKeys(list[0]);
|
| | | //获取湿度值
|
| | | this.GetHumidityValue(btnHumi, newRoom.HumidityDevice);
|
| | | };
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取湿度值
|
| | | /// </summary>
|
| | | /// <param name="btnHumi"></param>
|
| | | /// <param name="deviceKey"></param>
|
| | | private void GetHumidityValue(NormalViewControl btnHumi, string deviceKey)
|
| | | {
|
| | | var device = Common.LocalDevice.Current.GetDevice(deviceKey);
|
| | | if (device == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //获取中...
|
| | | btnHumi.Text = Language.StringByID(R.MyInternationalizationString.uGetting);
|
| | |
|
| | | HdlDeviceAttributeLogic.Current.RemoveEvent("HumidityDevice");
|
| | | HdlDeviceAttributeLogic.Current.AddAttributeEvent("HumidityDevice", "DeviceStatusReport", (report) =>
|
| | | {
|
| | | string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(report);
|
| | | if (newRoom.HumidityDevice != mainKeys || btnHumi == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //移除掉事件
|
| | | HdlDeviceAttributeLogic.Current.RemoveEvent("HumidityDevice");
|
| | | foreach (var data in report.DeviceStatusReport.AttriBute)
|
| | | {
|
| | | if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue)
|
| | | {
|
| | | if (data.AttriButeData == 0)
|
| | | {
|
| | | //0
|
| | | btnHumi.Text = "0.0%";
|
| | | }
|
| | | else
|
| | | {
|
| | | //小数点需要一位(湿度没有负数)
|
| | | string strValue = data.AttriButeData.ToString();
|
| | | strValue = strValue.Substring(0, strValue.Length - 1);
|
| | | btnHumi.Text = strValue.Insert(strValue.Length - 1, ".") + "%";
|
| | | }
|
| | | }
|
| | | }
|
| | | });
|
| | | //发送获取湿度的命令
|
| | | ((ZigBee.Device.TemperatureSensor)device).ReadTemperatureOrHumidity();
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 界面关闭___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 界面关闭
|
| | | /// </summary>
|
| | | public override void CloseForm()
|
| | | {
|
| | | HdlDeviceAttributeLogic.Current.RemoveEvent("TemperatrueDevice");
|
| | | HdlDeviceAttributeLogic.Current.RemoveEvent("HumidityDevice");
|
| | |
|
| | | base.CloseForm();
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 一般方法___________________________
|
| | |
|
| | | /// <summary>
|