using Shared.Common;
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Threading.Tasks;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.UserCenter.DeviceCurtain
|
{
|
/// <summary>
|
/// 开合帘的方向与限位的配置界面
|
/// </summary>
|
public class AutoOpenDirectionAndLimitSettionForm : EditorCommonForm
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
///窗帘的回路
|
/// </summary>
|
private Rollershade curtainDevice = null;
|
/// <summary>
|
/// 窗帘数据
|
/// </summary>
|
private CurtainData curtainData = null;
|
/// <summary>
|
/// 接收开限位 false:没有接收到 true:已经接收到
|
/// </summary>
|
private bool receiveOpenlimit = false;
|
/// <summary>
|
/// 接收合限位 false:没有接收到 true:已经接收到
|
/// </summary>
|
private bool receiveCloseLimit = false;
|
/// <summary>
|
/// 发送区分 1:开限位 2:合限位
|
/// </summary>
|
private int sendDiv = 0;
|
/// <summary>
|
/// 是否备份窗帘数据
|
/// </summary>
|
private bool backupCurtainData = false;
|
/// <summary>
|
/// 列表控件
|
/// </summary>
|
private VerticalListControl listView = null;
|
/// <summary>
|
/// 开限位的进度条
|
/// </summary>
|
private SeekBarControl openSeekBar = null;
|
/// <summary>
|
/// 合限位的进度条
|
/// </summary>
|
private SeekBarControl closeSeekBar = null;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
/// <param name="i_listdevice">窗帘的回路</param>
|
public void ShowForm(Rollershade i_CurtainDevice)
|
{
|
this.ScrollEnabled = false;
|
|
this.curtainDevice = i_CurtainDevice;
|
|
//设置标题信息
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDirectionAndLimit));
|
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//初始化中部控件
|
this.InitMiddleFrame();
|
});
|
}
|
|
/// <summary>
|
/// 初始化中部信息
|
/// </summary>
|
private void InitMiddleFrame()
|
{
|
//获取设备初始数据
|
var result = this.InitCurtainDefultData();
|
if (result == false)
|
{
|
//显示重新加载的界面
|
this.ShowReLoadView();
|
return;
|
}
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
//清空bodyFrame
|
bodyFrameLayout.BackgroundColor = UserCenterColor.Current.White;
|
this.ClearBodyFrame();
|
|
this.listView = new VerticalListControl(29);
|
listView.Y = Application.GetRealHeight(-6);
|
listView.Height = bodyFrameLayout.Height;
|
bodyFrameLayout.AddChidren(listView);
|
|
//导轨长度为0时
|
if (curtainData.CurtainLength <= 0)
|
{
|
//电机数据异常,确认已经安装导轨后,请重置电机
|
this.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uCurtainDataIsErrorPleaseResetCurtain));
|
try
|
{
|
//设备异常补救 -> 添加重置电机行
|
this.AddElectricalMachineryRow();
|
return;
|
}
|
catch (Exception ex2)
|
{
|
HdlLogLogic.Current.WriteLog(ex2, "开合帘补救异常1");
|
return;
|
}
|
}
|
|
try
|
{
|
//添加方向行
|
this.AddDirectionRow();
|
//添加限位行
|
this.AddLimitRow();
|
//添加重置电机行
|
this.AddElectricalMachineryRow();
|
|
//限位数据接收
|
this.ReceiveLimitData();
|
}
|
catch (Exception ex)
|
{
|
//Log出力
|
string msg = "当前激活的界面[" + HdlFormLogic.Current.NowActionFormID + "]";
|
HdlLogLogic.Current.WriteLog(ex, msg);
|
//电机数据异常,确认已经安装导轨后,请重置电机
|
this.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uCurtainDataIsErrorPleaseResetCurtain));
|
try
|
{
|
this.listView.RemoveAll();
|
//设备异常补救 -> 添加重置电机行
|
this.AddElectricalMachineryRow();
|
}
|
catch (Exception ex2) { HdlLogLogic.Current.WriteLog(ex2, "开合帘补救异常2"); }
|
}
|
});
|
}
|
|
#endregion
|
|
#region ■ 方向行_____________________________
|
|
/// <summary>
|
/// 添加方向行
|
/// </summary>
|
private void AddDirectionRow()
|
{
|
var rowDirection = new FrameRowControl(listView.rowSpace / 2);
|
listView.AddChidren(rowDirection);
|
//方向
|
rowDirection.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uDirection), 600);
|
//右箭头
|
rowDirection.AddRightArrow();
|
//状态
|
var btnStatu = rowDirection.AddMostRightView("", 300);
|
btnStatu.TextID = curtainData.Direction == false ? R.MyInternationalizationString.uForwardDirection : R.MyInternationalizationString.uReverseDirection;
|
//底线
|
rowDirection.AddBottomLine();
|
|
int nowSelectNo = curtainData.Direction == false ? 0 : 1;
|
rowDirection.ButtonClickEvent += (sender, e) =>
|
{
|
var listText = new List<string>();
|
listText.Add(Language.StringByID(R.MyInternationalizationString.uForwardDirection));//正向
|
listText.Add(Language.StringByID(R.MyInternationalizationString.uReverseDirection));//反向
|
|
var form = new BottomItemSelectForm();
|
form.AddForm(Language.StringByID(R.MyInternationalizationString.uDirectionSelect), listText, null, nowSelectNo);
|
form.FinishSelectEvent += (index) =>
|
{
|
//变更方向
|
var result = HdlDeviceCurtainLogic.Current.SetCurtainDirection(curtainDevice, index == 0 ? false : true);
|
if (result == false)
|
{
|
return;
|
}
|
nowSelectNo = index;
|
btnStatu.Text = listText[index];
|
curtainData.Direction = index == 0 ? false : true;
|
};
|
};
|
//如果当前是展示模板,则不能编辑
|
if (Common.Config.Instance.Home.IsShowTemplate == true)
|
{
|
rowDirection.CanClick = false;
|
}
|
}
|
|
#endregion
|
|
#region ■ 限位行_____________________________
|
|
/// <summary>
|
/// 添加限位行
|
/// </summary>
|
private void AddLimitRow()
|
{
|
var frameBack = new FrameLayout();
|
frameBack.Height = Application.GetRealHeight(956);
|
|
var rowLimit = new FrameRowControl(listView.rowSpace / 2);
|
rowLimit.UseClickStatu = false;
|
listView.AddChidren(rowLimit);
|
//限位
|
rowLimit.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uLimit), 600);
|
//右箭头
|
var btnRinght = rowLimit.AddMostRightEmptyIcon(58, 58);
|
rowLimit.ChangedChidrenBindMode(btnRinght, ChidrenBindMode.NotBind);
|
btnRinght.UseClickStatu = false;
|
btnRinght.UnSelectedImagePath = "Item/RightNext.png";
|
btnRinght.SelectedImagePath = "Item/Down.png";
|
btnRinght.IsSelected = true;
|
btnRinght.ButtonClickEvent += (sender, e) =>
|
{
|
btnRinght.IsSelected = !btnRinght.IsSelected;
|
//展开折叠
|
frameBack.Height = frameBack.Height > 10 ? 0 : Application.GetRealHeight(956);
|
};
|
//底线
|
rowLimit.AddBottomLine();
|
|
listView.AddChidren(frameBack);
|
//添加开限位进度条
|
this.AddOpenLimitProgress(frameBack);
|
//添加合限位进度条
|
this.AddCloseLimitProgress(frameBack);
|
}
|
|
#endregion
|
|
#region ■ 开限位行___________________________
|
|
/// <summary>
|
/// 添加开限位进度条
|
/// </summary>
|
/// <param name="frameBack"></param>
|
private void AddOpenLimitProgress(FrameLayout frameBack)
|
{
|
//开限位
|
var btnProgressView = new NormalViewControl(200, 50, true);
|
btnProgressView.X = HdlControlResourse.XXLeft;
|
btnProgressView.Y = Application.GetRealHeight(78);
|
btnProgressView.TextSize = 12;
|
btnProgressView.TextColor = UserCenterColor.Current.TextGrayColor1;
|
btnProgressView.TextID = R.MyInternationalizationString.uOpenLimit;
|
frameBack.AddChidren(btnProgressView);
|
|
int progressValue = (int)(curtainData.OpenLimitValue / (curtainData.CurtainLength * 1.0) * 100);
|
//设置百分比的初始值
|
curtainData.OpenLimitPersent = progressValue;
|
var btnProgress1 = new NormalViewControl(200, 50, true);
|
btnProgress1.X = Application.GetRealWidth(200);
|
btnProgress1.Y = btnProgressView.Y;
|
btnProgress1.TextSize = 12;
|
btnProgress1.TextColor = UserCenterColor.Current.TextGrayColor1;
|
btnProgress1.Text = progressValue + "%";
|
frameBack.AddChidren(btnProgress1);
|
//进度条
|
this.openSeekBar = new SeekBarControl(965);
|
openSeekBar.Y = btnProgressView.Bottom + Application.GetRealHeight(46);
|
openSeekBar.ProgressBarColor = 0xff288bfd;
|
openSeekBar.Progress = progressValue;
|
frameBack.AddChidren(openSeekBar);
|
|
var btnTemp1 = new NormalViewControl(200, 50, true);
|
btnTemp1.X = HdlControlResourse.XXLeft;
|
btnTemp1.Y = btnProgressView.Bottom + Application.GetRealHeight(115);
|
btnTemp1.TextSize = 12;
|
btnTemp1.TextColor = UserCenterColor.Current.TextGrayColor3;
|
btnTemp1.Text = "0%";
|
frameBack.AddChidren(btnTemp1);
|
var btnTemp2 = new NormalViewControl(200, 50, true);
|
btnTemp2.X = frameBack.Width - Application.GetRealWidth(200 + 50);
|
btnTemp2.Y = btnTemp1.Y;
|
btnTemp2.TextAlignment = TextAlignment.CenterRight;
|
btnTemp2.TextSize = 12;
|
btnTemp2.TextColor = UserCenterColor.Current.TextGrayColor3;
|
btnTemp2.Text = "100%";
|
frameBack.AddChidren(btnTemp2);
|
//线
|
var btnLine = new NormalViewControl(frameBack.Width - HdlControlResourse.XXLeft * 2, HdlControlResourse.BottomLineHeight, false);
|
btnLine.X = HdlControlResourse.XXLeft;
|
btnLine.Y = btnTemp2.Bottom + Application.GetRealHeight(156);
|
btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
|
frameBack.AddChidren(btnLine);
|
|
//减号
|
var btnMinus = new IconViewControl(104);
|
btnMinus.UseClickStatu = true;
|
btnMinus.X = Application.GetRealWidth(847);
|
btnMinus.Y = Application.GetRealHeight(46);
|
btnMinus.UnSelectedImagePath = "Item/MinusSign2.png";
|
btnMinus.SelectedImagePath = "Item/MinusSign2Selected.png";
|
frameBack.AddChidren(btnMinus);
|
btnMinus.ButtonClickEvent += (sender, e) =>
|
{
|
if (openSeekBar.Progress <= 0)
|
{
|
return;
|
}
|
openSeekBar.Progress -= 5;
|
openSeekBar.ProgressChangedEvent(1, openSeekBar.Progress);
|
};
|
|
//加号
|
var btnPlus = new IconViewControl(104);
|
btnPlus.UseClickStatu = true;
|
btnPlus.X = btnMinus.Right;
|
btnPlus.Y = btnMinus.Y;
|
btnPlus.UnSelectedImagePath = "Item/PlusSign2.png";
|
btnPlus.SelectedImagePath = "Item/PlusSign2Selected.png";
|
frameBack.AddChidren(btnPlus);
|
btnPlus.ButtonClickEvent += (sender, e) =>
|
{
|
if (openSeekBar.Progress >= 100)
|
{
|
return;
|
}
|
openSeekBar.Progress += 5;
|
openSeekBar.ProgressChangedEvent(1, openSeekBar.Progress);
|
};
|
|
//保存
|
var btnSave = new NormalViewControl(150, 60, true);
|
btnSave.X = Application.GetRealWidth(906);
|
btnSave.Y = btnTemp1.Bottom + Application.GetRealHeight(68);
|
btnSave.TextAlignment = TextAlignment.Center;
|
btnSave.TextID = R.MyInternationalizationString.uSave;
|
btnSave.TextColor = UserCenterColor.Current.TextOrangeColor;
|
frameBack.AddChidren(btnSave);
|
btnSave.ButtonClickEvent += (sender, e) =>
|
{
|
//2020.05.17:追加虚拟住宅可以直接点击
|
if (this.receiveOpenlimit == true || Common.Config.Instance.Home.IsVirtually == true)
|
{
|
//确认开限位点
|
this.SaveOpenLimit();
|
}
|
};
|
|
int oldProValue = curtainData.OpenLimitPersent;
|
openSeekBar.ProgressChangedEvent += (div, value) =>
|
{
|
//开限位不能大于合限位
|
if (value > closeSeekBar.Progress)
|
{
|
openSeekBar.Progress = closeSeekBar.Progress;
|
return;
|
}
|
btnProgress1.Text = value + "%";
|
//数据变更,百分比
|
curtainData.OpenLimitPersent = value;
|
};
|
//如果当前是展示模板,则不能编辑
|
if (Common.Config.Instance.Home.IsShowTemplate == true)
|
{
|
openSeekBar.Enable = false;
|
btnMinus.CanClick = false;
|
btnPlus.CanClick = false;
|
btnSave.CanClick = false;
|
}
|
|
//虚拟住宅不需要监听
|
if (Common.Config.Instance.Home.IsVirtually == true)
|
{
|
return;
|
}
|
|
HdlThreadLogic.Current.RunThread(async () =>
|
{
|
while (openSeekBar.Parent != null)
|
{
|
int nowValue = curtainData.OpenLimitPersent;
|
if (oldProValue == nowValue)
|
{
|
//值不等才处理
|
await Task.Delay(500);
|
continue;
|
}
|
oldProValue = nowValue;
|
|
//将窗帘调整到指定百分比
|
this.sendDiv = 1;
|
curtainDevice.WcdGoToTiltValue(nowValue);
|
}
|
});
|
}
|
|
/// <summary>
|
/// 确认开限位点
|
/// </summary>
|
private void SaveOpenLimit()
|
{
|
//确认当前位置为开限位?
|
string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainOpenLimitMsg);
|
this.ShowMassage(ShowMsgType.Confirm, msg, () =>
|
{
|
decimal openValue = ((decimal)curtainData.OpenLimitPersent / 100) * curtainData.CurtainLength;
|
decimal closeValue = ((decimal)curtainData.CloseLimitPersent / 100) * curtainData.CurtainLength;
|
if (openValue < 0) { openValue = 0; }
|
if (closeValue < 0) { closeValue = curtainData.CurtainLength; }
|
//执行确认及覆盖上限位点
|
var result = HdlDeviceCurtainLogic.Current.SetAutoOpenCurtainLimitPoint(curtainDevice, (int)openValue, (int)closeValue, curtainData.CurtainLength);
|
if (result == true)
|
{
|
this.receiveOpenlimit = false;
|
}
|
});
|
}
|
|
#endregion
|
|
#region ■ 合限位行___________________________
|
|
/// <summary>
|
/// 添加合限位进度条
|
/// </summary>
|
/// <param name="frameBack"></param>
|
private void AddCloseLimitProgress(FrameLayout frameBack)
|
{
|
//合限位
|
var btnProgressView = new NormalViewControl(200, 50, true);
|
btnProgressView.X = HdlControlResourse.XXLeft;
|
btnProgressView.Y = Application.GetRealHeight(536);
|
btnProgressView.TextSize = 12;
|
btnProgressView.TextColor = UserCenterColor.Current.TextGrayColor1;
|
btnProgressView.TextID = R.MyInternationalizationString.uCloseLimit;
|
frameBack.AddChidren(btnProgressView);
|
|
int progressValue = (int)(curtainData.CloseLimitValue / (curtainData.CurtainLength * 1.0) * 100);
|
//设置百分比的初始值
|
curtainData.CloseLimitPersent = progressValue;
|
var btnProgress1 = new NormalViewControl(200, 50, true);
|
btnProgress1.X = Application.GetRealWidth(200);
|
btnProgress1.Y = btnProgressView.Y;
|
btnProgress1.TextSize = 12;
|
btnProgress1.TextColor = UserCenterColor.Current.TextGrayColor1;
|
btnProgress1.Text = progressValue + "%";
|
frameBack.AddChidren(btnProgress1);
|
//进度条
|
this.closeSeekBar = new SeekBarControl(965);
|
closeSeekBar.Y = btnProgressView.Bottom + Application.GetRealHeight(46);
|
closeSeekBar.ProgressBarColor = 0xff288bfd;
|
closeSeekBar.Progress = progressValue;
|
frameBack.AddChidren(closeSeekBar);
|
|
var btnTemp1 = new NormalViewControl(200, 50, true);
|
btnTemp1.X = HdlControlResourse.XXLeft;
|
btnTemp1.Y = btnProgressView.Bottom + Application.GetRealHeight(115);
|
btnTemp1.TextSize = 12;
|
btnTemp1.TextColor = UserCenterColor.Current.TextGrayColor3;
|
btnTemp1.Text = "0%";
|
frameBack.AddChidren(btnTemp1);
|
var btnTemp2 = new NormalViewControl(200, 50, true);
|
btnTemp2.X = frameBack.Width - Application.GetRealWidth(200 + 50);
|
btnTemp2.Y = btnTemp1.Y;
|
btnTemp2.TextAlignment = TextAlignment.CenterRight;
|
btnTemp2.TextSize = 12;
|
btnTemp2.TextColor = UserCenterColor.Current.TextGrayColor3;
|
btnTemp2.Text = "100%";
|
frameBack.AddChidren(btnTemp2);
|
//线
|
var btnLine = new NormalViewControl(frameBack.Width - HdlControlResourse.XXLeft * 2, HdlControlResourse.BottomLineHeight, false);
|
btnLine.X = HdlControlResourse.XXLeft;
|
btnLine.Y = btnTemp2.Bottom + Application.GetRealHeight(156);
|
btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
|
frameBack.AddChidren(btnLine);
|
|
//减号
|
var btnMinus = new IconViewControl(104);
|
btnMinus.UseClickStatu = true;
|
btnMinus.X = Application.GetRealWidth(847);
|
btnMinus.Y = Application.GetRealHeight(504);
|
btnMinus.UnSelectedImagePath = "Item/MinusSign2.png";
|
btnMinus.SelectedImagePath = "Item/MinusSign2Selected.png";
|
frameBack.AddChidren(btnMinus);
|
btnMinus.ButtonClickEvent += (sender, e) =>
|
{
|
if (closeSeekBar.Progress <= 0)
|
{
|
return;
|
}
|
closeSeekBar.Progress -= 5;
|
closeSeekBar.ProgressChangedEvent(1, closeSeekBar.Progress);
|
};
|
|
//加号
|
var btnPlus = new IconViewControl(104);
|
btnPlus.UseClickStatu = true;
|
btnPlus.X = btnMinus.Right;
|
btnPlus.Y = btnMinus.Y;
|
btnPlus.UnSelectedImagePath = "Item/PlusSign2.png";
|
btnPlus.SelectedImagePath = "Item/PlusSign2Selected.png";
|
frameBack.AddChidren(btnPlus);
|
btnPlus.ButtonClickEvent += (sender, e) =>
|
{
|
if (closeSeekBar.Progress >= 100)
|
{
|
return;
|
}
|
closeSeekBar.Progress += 5;
|
closeSeekBar.ProgressChangedEvent(1, closeSeekBar.Progress);
|
};
|
|
//保存
|
var btnSave = new NormalViewControl(150, 60, true);
|
btnSave.X = Application.GetRealWidth(906);
|
btnSave.Y = btnTemp1.Bottom + Application.GetRealHeight(68);
|
btnSave.TextAlignment = TextAlignment.Center;
|
btnSave.TextID = R.MyInternationalizationString.uSave;
|
btnSave.TextColor = UserCenterColor.Current.TextOrangeColor;
|
frameBack.AddChidren(btnSave);
|
btnSave.ButtonClickEvent += (sender, e) =>
|
{
|
//2020.05.17:追加虚拟住宅可以直接点击
|
if (this.receiveCloseLimit == true || Common.Config.Instance.Home.IsVirtually == true)
|
{
|
//保存合限位点
|
this.SaveCloseLimit();
|
}
|
};
|
|
int oldProValue = curtainData.CloseLimitPersent;
|
closeSeekBar.ProgressChangedEvent += (div, value) =>
|
{
|
if (value < curtainData.OpenLimitPersent)
|
{
|
//合限位不能小于合限位
|
closeSeekBar.Progress = openSeekBar.Progress;
|
return;
|
}
|
btnProgress1.Text = value + "%";
|
//数据变更,百分比
|
curtainData.CloseLimitPersent = value;
|
};
|
//如果当前是展示模板,则不能编辑
|
if (Common.Config.Instance.Home.IsShowTemplate == true)
|
{
|
closeSeekBar.Enable = false;
|
btnMinus.CanClick = false;
|
btnPlus.CanClick = false;
|
btnSave.CanClick = false;
|
}
|
//虚拟住宅不需要监听
|
if (Common.Config.Instance.Home.IsVirtually == true)
|
{
|
return;
|
}
|
|
HdlThreadLogic.Current.RunThread(async () =>
|
{
|
while (closeSeekBar.Parent != null)
|
{
|
int nowValue = curtainData.CloseLimitPersent;
|
if (oldProValue == nowValue)
|
{
|
//值不等才处理
|
await Task.Delay(500);
|
continue;
|
}
|
oldProValue = nowValue;
|
|
//将窗帘调整到指定百分比
|
this.sendDiv = 2;
|
curtainDevice.WcdGoToTiltValue(nowValue);
|
}
|
});
|
}
|
|
/// <summary>
|
/// 保存合限位点
|
/// </summary>
|
private void SaveCloseLimit()
|
{
|
//确认当前位置为合限位?
|
string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainCloseLimitMsg);
|
this.ShowMassage(ShowMsgType.Confirm, msg, () =>
|
{
|
decimal openValue = ((decimal)curtainData.OpenLimitPersent / 100) * curtainData.CurtainLength;
|
decimal closeValue = ((decimal)curtainData.CloseLimitPersent / 100) * curtainData.CurtainLength;
|
if (openValue < 0) { openValue = 0; }
|
if (closeValue < 0) { closeValue = curtainData.CurtainLength; }
|
//执行确认及覆盖上限位点
|
var result = HdlDeviceCurtainLogic.Current.SetAutoOpenCurtainLimitPoint(curtainDevice, (int)openValue, (int)closeValue, curtainData.CurtainLength);
|
|
if (result == true)
|
{
|
this.receiveCloseLimit = false;
|
}
|
});
|
}
|
|
#endregion
|
|
#region ■ 重置电机___________________________
|
|
/// <summary>
|
/// 添加重置电机行
|
/// </summary>
|
private void AddElectricalMachineryRow()
|
{
|
var rowReset = new FrameRowControl(listView.rowSpace / 2);
|
listView.AddChidren(rowReset);
|
//重置电机
|
rowReset.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uResetElectricalMachinery), 600);
|
//底线
|
rowReset.AddBottomLine();
|
rowReset.ButtonClickEvent += (sender, e) =>
|
{
|
//如果当前是虚拟住宅
|
if (Common.Config.Instance.Home.IsVirtually == true)
|
{
|
return;
|
}
|
//重置电机将初始化{0}方向与限位设置,确认继续?
|
string msg = Language.StringByID(R.MyInternationalizationString.uResetElectricalMachineryMsg);
|
msg = msg.Replace("{0}", "\r\n");
|
this.ShowMassage(ShowMsgType.Confirm, msg, () =>
|
{
|
//开启进度条
|
ProgressFormBar.Current.Start();
|
//正在重置电机
|
ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uElectricalMachineryResetting));
|
//重置窗帘
|
HdlThreadLogic.Current.RunThread(async () =>
|
{
|
var result = await HdlDeviceCurtainLogic.Current.RestoreCurtain(curtainDevice);
|
if (result == false)
|
{
|
//关闭进度条
|
ProgressFormBar.Current.Close();
|
return;
|
}
|
|
//每10的长度大概是2秒,多预留1次出来
|
int waitCount = ((curtainData.CurtainLength / 10) + 1) * 3;
|
if (waitCount < 12)
|
{
|
waitCount = 12;
|
}
|
|
int timeCount = 0;
|
while (timeCount <= waitCount)
|
{
|
//进度条值
|
ProgressFormBar.Current.SetValue(timeCount, waitCount);
|
timeCount++;
|
System.Threading.Thread.Sleep(1000);
|
}
|
//关闭进度条
|
ProgressFormBar.Current.Close();
|
|
//获取数据后,备份窗帘数据
|
this.backupCurtainData = true;
|
//重新初始化界面
|
this.InitMiddleFrame();
|
});
|
});
|
};
|
}
|
|
#endregion
|
|
#region ■ 初始化窗帘数据_____________________
|
|
/// <summary>
|
/// 初始化窗帘数据
|
/// </summary>
|
/// <returns></returns>
|
private bool InitCurtainDefultData()
|
{
|
this.curtainData = new CurtainData();
|
this.receiveOpenlimit = false;
|
this.receiveCloseLimit = false;
|
this.sendDiv = 0;
|
|
//如果当前是虚拟住宅
|
if (Common.Config.Instance.Home.IsVirtually == true)
|
{
|
var data = HdlTemplateDeviceDataLogic.Current.GetCurtainLimitPoint(curtainDevice);
|
curtainData.Direction = data.Direction;
|
curtainData.CurtainLength = data.curtainLength;
|
curtainData.OpenLimitValue = data.upLimit;
|
curtainData.CloseLimitValue = data.downLimit;
|
return true;
|
}
|
|
//开启进度条
|
this.ShowProgressBar();
|
|
int receiptDataCount = 0;
|
string mainkeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(curtainDevice);
|
HdlGatewayReceiveLogic.Current.AddAttributeEvent("CurtainDeviceAttribute", ReceiveComandDiv.A设备属性上报, (device) =>
|
{
|
string checkKey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
|
if (mainkeys != checkKey || device.DeviceStatusReport.CluterID != 258)
|
{
|
return;
|
}
|
foreach (var attriBute in device.DeviceStatusReport.AttriBute)
|
{
|
if (attriBute.AttributeId == 23)
|
{
|
//开合帘方向
|
if (0 < (attriBute.AttriButeData & 0x01))
|
{
|
//反向
|
curtainData.Direction = true;
|
}
|
else
|
{
|
//正向
|
curtainData.Direction = false;
|
}
|
receiptDataCount++;
|
}
|
else if (attriBute.AttributeId == 1)
|
{
|
//窗帘总长
|
curtainData.CurtainLength = attriBute.AttriButeData;
|
receiptDataCount++;
|
}
|
else if (attriBute.AttributeId == 16)
|
{
|
//开限位
|
curtainData.OpenLimitValue = attriBute.AttriButeData;
|
receiptDataCount++;
|
}
|
else if (attriBute.AttributeId == 17)
|
{
|
//合限位
|
curtainData.CloseLimitValue = attriBute.AttriButeData;
|
receiptDataCount++;
|
}
|
}
|
});
|
//发送获取窗帘限位配置的命令
|
HdlDeviceCurtainLogic.Current.SetGetCurtainLimitSettionComand(curtainDevice);
|
|
int timeCount = 30;
|
while (receiptDataCount != 4 && timeCount >= 0)
|
{
|
System.Threading.Thread.Sleep(100);
|
timeCount--;
|
}
|
//关闭进度条
|
this.CloseProgressBar();
|
|
if (timeCount <= 0)
|
{
|
//获取窗帘方向与限位设置失败
|
string msg = Language.StringByID(R.MyInternationalizationString.uGetCurtainDirectionAndLimitSettionFail);
|
//拼接上【网关回复超时】的Msg
|
msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
this.ShowMassage(ShowMsgType.Tip, msg);
|
return false;
|
}
|
//移除监听
|
HdlGatewayReceiveLogic.Current.RemoveEvent("CurtainDeviceAttribute");
|
|
return true;
|
}
|
|
#endregion
|
|
#region ■ 限位数据接收_______________________
|
|
/// <summary>
|
/// 限位数据接收
|
/// </summary>
|
private void ReceiveLimitData()
|
{
|
//如果当前是展示模板,则需要处理
|
if (Common.Config.Instance.Home.IsShowTemplate == true)
|
{
|
return;
|
}
|
if (HdlGatewayReceiveLogic.Current.IsEsixt("ReceiveLimitData") == true)
|
{
|
HdlGatewayReceiveLogic.Current.RemoveEvent("ReceiveLimitData");
|
}
|
string mainkeys = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(curtainDevice);
|
HdlGatewayReceiveLogic.Current.AddAttributeEvent("ReceiveLimitData", ReceiveComandDiv.A设备属性上报, (device) =>
|
{
|
string checkKey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
|
if (mainkeys != checkKey || device.DeviceStatusReport.CluterID != 258)
|
{
|
return;
|
}
|
foreach (var attriBute in device.DeviceStatusReport.AttriBute)
|
{
|
//窗帘百分比推送
|
if (attriBute.AttributeId == 8)
|
{
|
//开限位
|
if (sendDiv == 1)
|
{
|
receiveOpenlimit = true;
|
}
|
//合限位
|
else if (sendDiv == 2)
|
{
|
receiveCloseLimit = true;
|
}
|
}
|
}
|
});
|
}
|
|
#endregion
|
|
#region ■ 界面关闭___________________________
|
|
/// <summary>
|
/// 界面关闭
|
/// </summary>
|
public override void CloseFormBefore()
|
{
|
HdlGatewayReceiveLogic.Current.RemoveEvent("CurtainDeviceAttribute");
|
HdlGatewayReceiveLogic.Current.RemoveEvent("ReceiveLimitData");
|
|
base.CloseFormBefore();
|
}
|
|
#endregion
|
|
#region ■ 结构体_____________________________
|
|
/// <summary>
|
/// 窗帘数据
|
/// </summary>
|
private class CurtainData
|
{
|
/// <summary>
|
/// false:电机方向正向;true:电机方向反向
|
/// </summary>
|
public bool Direction = false;
|
/// <summary>
|
/// 开限位的值
|
/// </summary>
|
public int OpenLimitValue = -1;
|
/// <summary>
|
/// 开限位的百分比
|
/// </summary>
|
public int OpenLimitPersent = -1;
|
/// <summary>
|
/// 合限位的值
|
/// </summary>
|
public int CloseLimitValue = -1;
|
/// <summary>
|
/// 合限位的百分比
|
/// </summary>
|
public int CloseLimitPersent = -1;
|
/// <summary>
|
/// 窗帘总长
|
/// </summary>
|
public int CurtainLength = -1;
|
}
|
|
#endregion
|
}
|
}
|