using Shared;
|
using HDL_ON.Stan;
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using HDL_ON.UI.CSS;
|
using HDL_ON.Entity;
|
using HDL_ON.DriverLayer;
|
|
namespace HDL_ON.UI
|
{
|
/// <summary>
|
/// 涂鸦风扇的控制界面
|
/// </summary>
|
public class TuyaFanPage : DeviceFunctionCardCommonForm
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 当前档位控件
|
/// </summary>
|
private NormalViewControl btnNowGear = null;
|
/// <summary>
|
/// 滑动条控件
|
/// </summary>
|
private SeekBarImageControl seekBarContr = null;
|
/// <summary>
|
/// 开关控件
|
/// </summary>
|
private IconViewControl btnSwitch = null;
|
/// <summary>
|
/// 风扇数据
|
/// </summary>
|
private FanData fanData = new FanData();
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 初始化白色区域的内容
|
/// </summary>
|
public override void InitFrameWhiteContent()
|
{
|
base.SetTitleText(Language.StringByID(StringId.Fan));
|
|
//刷新当前设备的状态缓存
|
this.RefreshNowDeviceStatuMemory(this.device);
|
//初始化第一个索引页的内容
|
this.InitFrameWhiteContent1();
|
}
|
|
/// <summary>
|
/// 初始化第一个索引页的内容
|
/// </summary>
|
private void InitFrameWhiteContent1()
|
{
|
//当前风速
|
var btnNowSpeed = new NormalViewControl(FrameWhiteCentet1.Width, Application.GetRealHeight(21), false);
|
btnNowSpeed.Y = Application.GetRealHeight(164);
|
btnNowSpeed.TextAlignment = TextAlignment.Center;
|
btnNowSpeed.TextID = StringId.CurrentWindSpeed;
|
FrameWhiteCentet1.AddChidren(btnNowSpeed);
|
|
//当前档位值
|
this.btnNowGear = new NormalViewControl(200, 38, true);
|
btnNowGear.TextAlignment = TextAlignment.Center;
|
btnNowGear.TextSize = CSS_FontSize.EmphasisFontSize_ExLevel;
|
btnNowGear.Gravity = Gravity.CenterHorizontal;
|
btnNowGear.Y = btnNowSpeed.Bottom + Application.GetRealHeight(8);
|
FrameWhiteCentet1.AddChidren(btnNowGear);
|
|
//滑动条
|
this.seekBarContr = new SeekBarImageControl(215);
|
seekBarContr.Enable = false;
|
seekBarContr.Gravity = Gravity.CenterHorizontal;
|
seekBarContr.Y = btnNowGear.Bottom + Application.GetRealHeight(30);
|
seekBarContr.MinValue = 1;
|
seekBarContr.MaxValue = 15;
|
FrameWhiteCentet1.AddChidren(seekBarContr);
|
|
//开关图标
|
this.btnSwitch = new IconViewControl(40);
|
btnSwitch.Gravity = Gravity.CenterHorizontal;
|
btnSwitch.Y = Application.GetRealHeight(468);
|
btnSwitch.UnSelectedImagePath = "Public/PowerClose.png";
|
btnSwitch.SelectedImagePath = "Public/PowerOpen.png";
|
FrameWhiteCentet1.AddChidren(btnSwitch);
|
btnSwitch.ButtonClickEvent += (sender, e) =>
|
{
|
//发送开关命令
|
this.SendSwitchComand();
|
};
|
|
//刷新界面状态
|
this.RefreshFormStatu(false);
|
|
int oldProgressValue = fanData.SpeedLevel;
|
int nowProgressValue = fanData.SpeedLevel;
|
//档
|
var strView = Language.StringByID(StringId.Gear);
|
seekBarContr.ProgressChangedEvent += (div, value) =>
|
{
|
nowProgressValue = value;
|
this.btnNowGear.Text = value + strView;
|
//滑动中
|
if (div == 0) { this.fanData.IsProgressing = true; }
|
//滑动结束
|
else
|
{
|
this.fanData.IsProgressing = false;
|
this.fanData.ProgressEndTime = DateTime.Now;
|
}
|
};
|
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
while (this.Parent != null)
|
{
|
if (nowProgressValue != oldProgressValue)
|
{
|
//发送风速命令
|
this.SendSpeedComand(nowProgressValue);
|
oldProgressValue = nowProgressValue;
|
}
|
System.Threading.Thread.Sleep(1000);
|
}
|
//界面关闭时
|
if (nowProgressValue != oldProgressValue)
|
{
|
//发送风速命令
|
this.SendSpeedComand(nowProgressValue);
|
}
|
});
|
}
|
|
#endregion
|
|
#region ■ 设备状态反馈_______________________
|
|
/// <summary>
|
/// 设备状态反馈
|
/// </summary>
|
/// <param name="i_LocalDevice"></param>
|
public override void DeviceStatuPush(Function i_LocalDevice)
|
{
|
//不是同一个东西
|
if (this.device.sid != i_LocalDevice.sid) { return; }
|
|
//刷新当前设备的状态缓存
|
this.RefreshNowDeviceStatuMemory(i_LocalDevice);
|
//刷新界面状态
|
this.RefreshFormStatu(true);
|
}
|
|
#endregion
|
|
#region ■ 刷新界面状态_______________________
|
|
/// <summary>
|
/// 刷新界面状态
|
/// </summary>
|
private void RefreshFormStatu(bool checkTime)
|
{
|
//开关
|
if (this.btnSwitch.IsSelected != this.fanData.Open)
|
{
|
//相同不变更
|
this.btnSwitch.IsSelected = this.fanData.Open;
|
this.seekBarContr.Enable = this.fanData.Open;
|
}
|
//如果是停止滑动的情况
|
if (this.fanData.IsProgressing == false)
|
{
|
if (checkTime == true && (DateTime.Now - this.fanData.ProgressEndTime).TotalSeconds <= 2)
|
{
|
//2秒之内不变更滑动条的值(为了不让它来回跳动)
|
return;
|
}
|
if (this.seekBarContr.Progress != this.fanData.SpeedLevel)
|
{
|
//变更进度条的值
|
this.seekBarContr.Progress = this.fanData.SpeedLevel;
|
this.btnNowGear.Text = this.fanData.SpeedLevel + Language.StringByID(StringId.Gear);
|
}
|
}
|
}
|
|
#endregion
|
|
#region ■ 发送各种命令_______________________
|
|
/// <summary>
|
/// 发送开关命令
|
/// </summary>
|
private void SendSwitchComand()
|
{
|
this.btnSwitch.CanClick = false;
|
|
string statu = this.btnSwitch.IsSelected == true ? "off" : "on";
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
var dic = new Dictionary<string, string>();
|
dic.Add(FunctionAttributeKey.OnOff, statu);
|
Control.Ins.SendWriteCommand(this.device, dic, true);
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
this.btnSwitch.CanClick = true;
|
});
|
});
|
}
|
|
/// <summary>
|
/// 发送风速命令
|
/// </summary>
|
private void SendSpeedComand(int value)
|
{
|
var dic = new Dictionary<string, string>();
|
dic.Add("fan_speed_percent", value.ToString());
|
Control.Ins.SendWriteCommand(this.device, dic, true);
|
}
|
|
#endregion
|
|
#region ■ 一般方法___________________________
|
|
/// <summary>
|
/// 刷新当前设备的状态缓存
|
/// </summary>
|
private void RefreshNowDeviceStatuMemory(Function i_LocalDevice)
|
{
|
foreach (var data in i_LocalDevice.attributes)
|
{
|
//开关
|
if (data.key == "on_off") { this.fanData.Open = data.realValue == "on"; }
|
//风速档位
|
else if (data.key == "fan_speed_percent")
|
{
|
var value = data.realValue;
|
if (value != string.Empty)
|
{
|
this.fanData.SpeedLevel = Convert.ToInt32(value);
|
}
|
}
|
}
|
}
|
|
#endregion
|
|
#region ■ 结构体_____________________________
|
|
/// <summary>
|
/// 风扇的数据
|
/// </summary>
|
private class FanData
|
{
|
/// <summary>
|
/// 是否打开
|
/// </summary>
|
public bool Open = true;
|
/// <summary>
|
/// 风速档位(1-15)
|
/// </summary>
|
public int SpeedLevel = 1;
|
/// <summary>
|
/// 是否正在滑动中
|
/// </summary>
|
public bool IsProgressing = false;
|
/// <summary>
|
/// 滑动结束的时间
|
/// </summary>
|
public DateTime ProgressEndTime = DateTime.Now;
|
}
|
|
#endregion
|
}
|
}
|