using Shared.Phone.UserCenter;
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.MainPage.Controls
|
{
|
/// <summary>
|
/// 色温灯卡片控件
|
/// </summary>
|
public class DeviceColorTemperatureCardControl : DeviceCardCommon
|
{
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 初始化控件
|
/// </summary>
|
/// <param name="i_device"></param>
|
public override void InitControl(CommonDevice i_device, Common.Room i_nowSelectRoom)
|
{
|
base.InitControl(i_device, i_nowSelectRoom);
|
|
//添加跳转深度卡片信息事件
|
this.AddDetailInfoEvent(i_device);
|
|
//添加开关控件
|
var btnSwitch = this.AddSwitchControl();
|
btnSwitch.ButtonClickEvent += (sender, e) =>
|
{
|
//获取当前亮度
|
int level = Convert.ToInt32(i_device.GetType().InvokeMember("Level", System.Reflection.BindingFlags.GetField, null, i_device, null));
|
//如果住宅为虚拟住宅
|
if (Common.Config.Instance.Home.IsVirtually == true)
|
{
|
//直接变更缓存
|
((LightBase)i_device).OnOffStatus = btnSwitch.IsSelected == true ? 0 : 1;
|
if (((LightBase)i_device).OnOffStatus == 1 && level == 0)
|
{
|
//如果当前是打开状态,并且亮度为0的话,则需要变成100%亮度
|
i_device.GetType().InvokeMember("Level", System.Reflection.BindingFlags.SetField, null, i_device, new object[] { 100 });
|
}
|
this.RefreshControlInfo(this.device);
|
return;
|
}
|
bool setStatu = !btnSwitch.IsSelected;
|
//变更卡片状态
|
this.SetCardOpenStatu(setStatu);
|
//检测是否获取网关反馈的结果,如果网关没有回复,则会弹出消息
|
this.StartCheckResponeResult(!setStatu);
|
|
if (setStatu == true)
|
{
|
//打开
|
this.SetDeviceStatuText(Language.StringByID(R.MyInternationalizationString.uOpen1));
|
if (level == 0)
|
{
|
//如果当前是打开状态,并且亮度为0的话,则需要变成100%亮度
|
i_device.GetType().InvokeMember("SetLevel", System.Reflection.BindingFlags.InvokeMethod, null, i_device, new object[] { 254 });
|
}
|
else
|
{
|
i_device.SwitchControl(1);
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//获取灯光亮度
|
System.Threading.Thread.Sleep(300);
|
HdlDeviceAttributeLogic.Current.SendLevelStatuComand(i_device);
|
});
|
}
|
}
|
else
|
{
|
//关闭
|
this.SetDeviceStatuText(Language.StringByID(R.MyInternationalizationString.Close));
|
i_device.SwitchControl(0);
|
}
|
};
|
}
|
|
#endregion
|
|
#region ■ 深度卡片信息_______________________
|
|
/// <summary>
|
/// 添加跳转深度卡片信息事件
|
/// </summary>
|
private void AddDetailInfoEvent(CommonDevice i_device)
|
{
|
//深度卡片信息
|
this.ButtonClickEvent += (sender, e) =>
|
{
|
Common.CommonPage.Instance.IsDrawerLockMode = true;
|
|
if (HdlDeviceCommonLogic.Current.IsMiniLight(this.device) == false)
|
{
|
var form = new ControlForm.DeviceColorTemperatureLightDetailCardForm();
|
form.RowOrCardControl = this;
|
form.AddForm(i_device, this.nowSelectRoom, 965, 1466);
|
form.FormCloseEvent += this.CardDetailInfoBackEvent;
|
}
|
else
|
{
|
//mini夜灯
|
var form = new ControlForm.DeviceMiniLightDetailCardForm();
|
form.RowOrCardControl = this;
|
form.AddForm(i_device, this.nowSelectRoom, 965, 1466);
|
form.FormCloseEvent += this.CardDetailInfoBackEvent;
|
}
|
};
|
}
|
|
#endregion
|
|
#region ■ 检测设备打开状态___________________
|
|
/// <summary>
|
/// 检测设备打开状态
|
/// </summary>
|
/// <param name="i_device"></param>
|
/// <returns></returns>
|
public override bool CheckIsOpenStatu(CommonDevice i_device)
|
{
|
return ((LightBase)i_device).OnOffStatus == 1;
|
}
|
|
#endregion
|
|
#region ■ 发送获取状态命令___________________
|
|
/// <summary>
|
/// 发送获取状态命令
|
/// </summary>
|
public override void SendStatuComand()
|
{
|
if (Common.Config.Instance.Home.IsVirtually == true)
|
{
|
//如果住宅为虚拟住宅,则此功能无效
|
return;
|
}
|
//检测能否发送获取状态命令
|
if (this.CheckCanSendStatuComand() == true)
|
{
|
HdlDeviceAttributeLogic.Current.SendColorTemperatureLightStatuComand(this.device);
|
}
|
}
|
|
#endregion
|
}
|
}
|