using System;
using System.Collections.Generic;
using System.Threading;
using System.Net.NetworkInformation;
using System.Net;
using System.Text;
namespace Shared.SimpleControl.Phone
{
///
/// 美林空调系统
/// 1.总控 在家 离家 ==> 通用开关指令(控制:E01C,读状态:E018) 开关号:1,开关状态: 0在家、1离家
/// 2.总控 全关 全开 ==> 通用开关指令(控制:E01C,读状态:E018) 开关号:2,开关状态: 0全关、1全开
/// 3.总控 模式 ==> 通用开关指令(控制:E01C,读状态:E018) 开关号:3,开关状态: 0制冷、1制热、2通风
///
/// 空调室内湿度
/// 1.读1938 回1939,扫风状态位替换位湿度状态位
///
/// 读模拟量 E50A
/// 日功耗 小类:25, 月功耗 小类:26, 功率 小类 24;
///
///
public class ACMerrillHomePage : FrameLayout
{
uint MLTextColor = 0xFFEB5C19;
Button tempSwitch;
Button todayValueBtn;
Button monthValueBtn;
Button kwValueBtn;
Button btnLine3;
Button atHomeBtn;
Button outHomeBtn;
Button strokeBtn;
Button heatingBtn;
Button coolingBtn;
//List mEmqServerList;
VerticalScrolViewLayout bodyScrolView;
VerticalScrolViewLayout mACListScrolView;
//Thread readSpeedThead;
///
/// 当前视图
///
static ACMerrillHomePage curView;
ACMerrill mACMerrill;
public ACMerrillHomePage (ACMerrill mmACMerrill)
{
//BackgroundColor = SkinStyle.Current.MainColor;
this.mACMerrill = mmACMerrill;
curView = this;
}
public override void RemoveFromParent ()
{
SaveMerrilEquipmentMessage ();
MainPage.Loading.Hide ();
base.RemoveFromParent ();
curView = null;
}
public void ShowView ()
{
#region 标题
var topView = new FrameLayout () {
Y = Application.GetRealHeight (36),
Height = Application.GetRealHeight (90),
BackgroundColor = SkinStyle.Current.MainColor,
};
AddChidren (topView);
var title = new Button () {
Width = Application.GetRealWidth (400),
TextAlignment = TextAlignment.Center,
Text = Language.StringByID (R.MyInternationalizationString.ACMerrill),
TextSize = 19,
TextColor = SkinStyle.Current.TextColor1,
Height = Application.GetMinReal (90),
Gravity = Gravity.CenterHorizontal,
};
topView.AddChidren (title);
//var logo = new Button () {
// Width = Application.GetRealWidth (154),
// Height = Application.GetRealHeight (90),
// X = Application.GetRealWidth (486),
// UnSelectedImagePath = MainPage.LogoString,
// Gravity = Gravity.CenterVertical,
//};
//topView.AddChidren (logo);
var back = new Button () {
Height = Application.GetRealHeight (90),
Width = Application.GetRealWidth (85),
UnSelectedImagePath = "Item/Back.png",
Gravity = Gravity.CenterVertical,
};
topView.AddChidren (back);
back.MouseUpEventHandler += (sender, e) => {
(Parent as PageLayout).PageIndex -= 1;
curView = null;
};
#endregion
bodyScrolView = new VerticalScrolViewLayout () {
Height = Application.GetRealHeight (Application.DesignHeight - 126),
Y = topView.Bottom,
//BackgroundColor = SkinStyle.Current.ViewColor,
};
AddChidren (bodyScrolView);
#region HomeView 系统总控View
var HomeView = new FrameLayout () {
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight (298),
BackgroundColor = SkinStyle.Current.ViewColor,
};
bodyScrolView.AddChidren (HomeView);
var homeTitle = new Button () {
Width = Application.GetRealWidth (200),
Height = Application.GetRealHeight (38),
X = Application.GetRealWidth (33),
Y = Application.GetRealHeight (32),
TextAlignment = TextAlignment.CenterLeft,
TextID = R.MyInternationalizationString.MyHome,
TextSize = 20,
TextColor = SkinStyle.Current.TextColor1,
};
HomeView.AddChidren (homeTitle);
//开关按键
tempSwitch = new Button () {
Width = Application.GetMinRealAverage (89),
Height = Application.GetMinRealAverage (54),
X = Application.GetRealWidth (640 - 89 - 32),
Y = Application.GetRealHeight (24),
UnSelectedImagePath = "Item/SwitchClose.png",
SelectedImagePath = "Item/SwitchOpen.png",
};
HomeView.AddChidren (tempSwitch);
tempSwitch.MouseUpEventHandler += (sender3, e3) => {
//弹窗询问
ShowAllAcOpenAlter ();
};
//空调总能耗
var statusTitle = new Button () {
Width = Application.GetRealWidth (400),
Height = Application.GetRealHeight (27),
X = Application.GetRealWidth (34),
Y = Application.GetRealHeight (109),
TextAlignment = TextAlignment.CenterLeft,
//Text = "空调总能耗",
TextID = R.MyInternationalizationString.TotalEnergyConsumption,
TextSize = 14,
TextColor = SkinStyle.Current.TextColor1,
};
HomeView.AddChidren (statusTitle);
//屏幕1/3宽
var MenuWidth = Application.GetRealWidth (640 / 3);
//今日耗电量
todayValueBtn = new Button () {
Width = MenuWidth,
Height = Application.GetRealHeight (27),
//X = Application.GetRealWidth (0),
Y = Application.GetRealHeight (183),
TextAlignment = TextAlignment.Center,
//Text = mACMerrill.DailyPowerConsumption.ToString ("F2") + "KWH",
TextSize = 14,
TextColor = 0xFFEB5C19,
};
HomeView.AddChidren (todayValueBtn);
var todayTitle = new Button () {
Width = MenuWidth,
Height = Application.GetRealHeight (27),
//X = Application.GetRealWidth (0),
Y = Application.GetRealHeight (228),
TextAlignment = TextAlignment.Center,
//Text = "今日耗电量",
TextID = R.MyInternationalizationString.DailyPowerConsumption,
TextSize = 12,
TextColor = 0x90FFFFFF,
};
HomeView.AddChidren (todayTitle);
//本月耗电量
monthValueBtn = new Button () {
Width = MenuWidth,
Height = Application.GetRealHeight (27),
X = todayValueBtn.Right,
Y = Application.GetRealHeight (183),
TextAlignment = TextAlignment.Center,
//Text = mACMerrill.MonthlyPowerConsumption.ToString ("F2") + "KWH",
TextSize = 14,
TextColor = 0xFFEB5C19,
};
HomeView.AddChidren (monthValueBtn);
var monthTitle = new Button () {
Width = MenuWidth,
Height = Application.GetRealHeight (27),
X = todayValueBtn.Right,
Y = Application.GetRealHeight (228),
TextAlignment = TextAlignment.Center,
//Text = "本月耗电量",
TextID = R.MyInternationalizationString.MonthlyPowerConsumption,
TextSize = 12,
TextColor = 0x90FFFFFF,
};
HomeView.AddChidren (monthTitle);
//用电功率
kwValueBtn = new Button () {
Width = MenuWidth,
Height = Application.GetRealHeight (27),
X = monthValueBtn.Right,
Y = Application.GetRealHeight (183),
TextAlignment = TextAlignment.Center,
//Text = mACMerrill.CurrentPower.ToString ("F2") + "KW",
TextSize = 14,
TextColor = 0xFFEB5C19,
};
HomeView.AddChidren (kwValueBtn);
var kwTitle = new Button () {
Width = MenuWidth,
Height = Application.GetRealHeight (27),
X = monthValueBtn.Right,
Y = Application.GetRealHeight (228),
TextAlignment = TextAlignment.Center,
//Text = "用电功率",
TextID = R.MyInternationalizationString.ElectricPower,
TextSize = 12,
TextColor = 0x90FFFFFF,
};
HomeView.AddChidren (kwTitle);
try {
todayValueBtn.Text = mACMerrill.DailyPowerConsumption.ToString ("F2") + "KWH";
monthValueBtn.Text = mACMerrill.MonthlyPowerConsumption.ToString ("F2") + "KWH";
kwValueBtn.Text = mACMerrill.CurrentPower.ToString ("F2") + "KW";
} catch {
}
#endregion
var btnLine1 = new Button () {
Height = 1,
BackgroundColor = SkinStyle.Current.LineColor,
};
bodyScrolView.AddChidren (btnLine1);
#region 离家 在家 View
var ScenesView = new FrameLayout () {
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight (175),
Y = HomeView.Bottom,
//BackgroundColor = SkinStyle.Current.ViewColor,
};
bodyScrolView.AddChidren (ScenesView);
var atHomeTitle = new Button () {
Width = MenuWidth,
Height = Application.GetRealHeight (27),
//X = Application.GetRealWidth (65),
Y = Application.GetRealHeight (117),
TextAlignment = TextAlignment.Center,
//Text = "在家",
TextID = R.MyInternationalizationString.AtHome,
TextSize = 14,
TextColor = SkinStyle.Current.TextColor1,
};
ScenesView.AddChidren (atHomeTitle);
var width94X = (MenuWidth - Application.GetMinRealAverage (94)) / 2;
atHomeBtn = new Button () {
Width = Application.GetMinRealAverage (94),
Height = Application.GetMinRealAverage (94),
X = width94X,
Y = Application.GetRealHeight (16),
UnSelectedImagePath = "ACMerrill/ACAtHome.png",
SelectedImagePath = "ACMerrill/ACAtHomeSelected.png",
};
ScenesView.AddChidren (atHomeBtn);
var outHomeTitle = new Button () {
Width = MenuWidth,
Height = Application.GetRealHeight (27),
X = MenuWidth*2,
Y = Application.GetRealHeight (117),
TextAlignment = TextAlignment.Center,
//Text = "离家",
TextID = R.MyInternationalizationString.OutHome,
TextSize = 14,
TextColor = SkinStyle.Current.TextColor1,
};
ScenesView.AddChidren (outHomeTitle);
outHomeBtn = new Button () {
Width = Application.GetMinRealAverage (94),
Height = Application.GetMinRealAverage (94),
X = width94X + MenuWidth*2,
Y = Application.GetRealHeight (16),
UnSelectedImagePath = "ACMerrill/ACOutHome.png",
SelectedImagePath = "ACMerrill/ACOutHomeSelected.png",
};
ScenesView.AddChidren (outHomeBtn);
EventHandler atHomeEventHandler = (button, mouseEventArgs) => {
Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
Language.StringByID (R.MyInternationalizationString.IfSetToAtHomeMode),
Language.StringByID (R.MyInternationalizationString.Cancel),
Language.StringByID (R.MyInternationalizationString.Confrim));
alert.Show ();
alert.ResultEventHandler += (sender2, e2) => {
if (e2) {
atHomeBtn.IsSelected = true;
outHomeBtn.IsSelected = false;
SetSceneModeIsAtHome (true);
}
};
};
EventHandler outHomeEventHandler = (button, mouseEventArgs) => {
Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
Language.StringByID (R.MyInternationalizationString.IfSetToOutHomeMode),
Language.StringByID (R.MyInternationalizationString.Cancel),
Language.StringByID (R.MyInternationalizationString.Confrim));
alert.Show ();
alert.ResultEventHandler += (sender2, e2) => {
if (e2) {
atHomeBtn.IsSelected = false;
outHomeBtn.IsSelected = true;
SetSceneModeIsAtHome (false);
}
};
};
atHomeBtn.MouseUpEventHandler = atHomeEventHandler;
atHomeTitle.MouseUpEventHandler = atHomeEventHandler;
outHomeTitle.MouseUpEventHandler = outHomeEventHandler;
outHomeBtn.MouseUpEventHandler = outHomeEventHandler;
#endregion
var btnLine2 = new Button () {
Height = 1,
BackgroundColor = SkinStyle.Current.LineColor,
};
bodyScrolView.AddChidren (btnLine2);
#region 模式 View
var ModeView = new FrameLayout () {
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight (181),
Y = HomeView.Bottom,
//BackgroundColor = SkinStyle.Current.ViewColor,
};
bodyScrolView.AddChidren (ModeView);
//通风
var strokeTitle = new Button () {
Width = MenuWidth,
Height = Application.GetRealHeight (27),
//X = Application.GetRealWidth (65),
Y = Application.GetRealHeight (117),
TextAlignment = TextAlignment.Center,
TextID = R.MyInternationalizationString.Ventila,
TextSize = 14,
TextColor = SkinStyle.Current.TextColor1,
};
ModeView.AddChidren (strokeTitle);
strokeBtn = new Button () {
Width = Application.GetMinRealAverage (94),
Height = Application.GetMinRealAverage (94),
X = width94X,
Y = Application.GetRealHeight (16),
UnSelectedImagePath = "ACMerrill/ACStroke.png",
SelectedImagePath = "ACMerrill/ACStrokeSelected.png",
};
ModeView.AddChidren (strokeBtn);
//制热
var heatingTitle = new Button () {
Width = MenuWidth,
Height = Application.GetRealHeight (27),
X = MenuWidth,
Y = Application.GetRealHeight (117),
TextAlignment = TextAlignment.Center,
//Text = "制热",
TextID = R.MyInternationalizationString.Heating,
TextSize = 14,
TextColor = SkinStyle.Current.TextColor1,
};
ModeView.AddChidren (heatingTitle);
heatingBtn = new Button () {
Width = Application.GetMinRealAverage (94),
Height = Application.GetMinRealAverage (94),
X = width94X+MenuWidth,
Y = Application.GetRealHeight (16),
UnSelectedImagePath = "ACMerrill/ACHeating.png",
SelectedImagePath = "ACMerrill/ACHeatingSelected.png",
};
ModeView.AddChidren (heatingBtn);
//制冷
var coolingTitle = new Button () {
Width = MenuWidth,
Height = Application.GetRealHeight (27),
X = MenuWidth * 2,
Y = Application.GetRealHeight (117),
TextAlignment = TextAlignment.Center,
//Text = "制冷",
TextID = R.MyInternationalizationString.Cool,
TextSize = 14,
TextColor = SkinStyle.Current.TextColor1,
};
ModeView.AddChidren (coolingTitle);
coolingBtn = new Button () {
Width = Application.GetMinRealAverage (94),
Height = Application.GetMinRealAverage (94),
X = width94X + MenuWidth*2,
Y = Application.GetRealHeight (16),
UnSelectedImagePath = "ACMerrill/ACCooling.png",
SelectedImagePath = "ACMerrill/ACCoolingSelected.png",
};
ModeView.AddChidren (coolingBtn);
//制冷按钮
EventHandler coolingModeEventHandler = (button, mouseEventArgs) => {
Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
Language.StringByID (R.MyInternationalizationString.IfSetToCoolingMode),
Language.StringByID (R.MyInternationalizationString.Cancel),
Language.StringByID (R.MyInternationalizationString.Confrim));
alert.Show ();
alert.ResultEventHandler += (sender2, e2) => {
if (e2) {
coolingBtn.IsSelected = true;
heatingBtn.IsSelected = false;
strokeBtn.IsSelected = false;
SetWorkMode ((byte)0);
}
};
};
//制热按钮
EventHandler heatingModeEventHandler = (button, mouseEventArgs) => {
Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
Language.StringByID (R.MyInternationalizationString.IfSetToHeatingMode),
Language.StringByID (R.MyInternationalizationString.Cancel),
Language.StringByID (R.MyInternationalizationString.Confrim));
alert.Show ();
alert.ResultEventHandler += (sender2, e2) => {
if (e2) {
coolingBtn.IsSelected = false;
heatingBtn.IsSelected = true;
strokeBtn.IsSelected = false;
SetWorkMode ((byte)1);
}
};
};
//通风按钮
EventHandler strokeModeEventHandler = (button, mouseEventArgs) => {
Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
Language.StringByID (R.MyInternationalizationString.IfSetToVentilationMode),
Language.StringByID (R.MyInternationalizationString.Cancel),
Language.StringByID (R.MyInternationalizationString.Confrim));
alert.Show ();
alert.ResultEventHandler += (sender2, e2) => {
if (e2) {
coolingBtn.IsSelected = false;
heatingBtn.IsSelected = false;
strokeBtn.IsSelected = true;
SetWorkMode ((byte)2);
}
};
};
coolingBtn.MouseUpEventHandler = coolingModeEventHandler;
coolingTitle.MouseUpEventHandler = coolingModeEventHandler;
heatingBtn.MouseUpEventHandler = heatingModeEventHandler;
heatingTitle.MouseUpEventHandler = heatingModeEventHandler;
strokeBtn.MouseUpEventHandler = strokeModeEventHandler;
strokeTitle.MouseUpEventHandler = strokeModeEventHandler;
#endregion
btnLine3 = new Button () {
Height = Application.GetRealHeight (16),
BackgroundColor = SkinStyle.Current.LineColor,
};
bodyScrolView.AddChidren (btnLine3);
//mVerticalScrolViewLayout = new VerticalScrolViewLayout ();
//BodyView.AddChidren (mVerticalScrolViewLayout);
UpdateACHomeView ();
#region 空调列表View
//显示出所有的空调
mACListScrolView = new VerticalScrolViewLayout () {
Height = bodyScrolView.Height - btnLine3.Bottom,
//BackgroundColor = 0xff33ff33
};
bodyScrolView.AddChidren (mACListScrolView);
#endregion
LoadACList ();
ReadAllStatus ();
}
///
/// 刷新View
///
void UpdateACHomeView () {
tempSwitch.IsSelected = mACMerrill.Power > 0;
atHomeBtn.IsSelected = mACMerrill.ScenesMode == 0;
outHomeBtn.IsSelected = mACMerrill.ScenesMode > 0;
curView.coolingBtn.IsSelected = mACMerrill.WorkMode == 0;
curView.heatingBtn.IsSelected = mACMerrill.WorkMode == 1;
curView.strokeBtn.IsSelected = mACMerrill.WorkMode == 2;
}
///
/// 加载所有子空调View
///
void LoadACList ()
{
try {
mACListScrolView.RemoveAll ();
foreach (ACMerrillLoop ac in mACMerrill.mACMerrillLoopList) {
AddAcView (ac, mACListScrolView);
}
var nowHeight = bodyScrolView.Height - btnLine3.Bottom;
var allHeight = Application.GetRealHeight (158) * mACMerrill.mACMerrillLoopList.Count;
if (allHeight > nowHeight) {
mACListScrolView.Height = allHeight;
} else {
mACListScrolView.Height = nowHeight;
}
#if __IOS__
//bodyScrolView.ReLocation ();
#endif
} catch {
}
}
///
/// 添加单个空调回路View
///
///
///
void AddAcView (ACMerrillLoop mACMerrillLoop, VerticalScrolViewLayout VerticalScrolViewMiddle)
{
EventHandler openACMerrillDevicePage = (button, mouseEventArgs) => {
ACMerrillDevicePage mACMerrillDevicePage = new ACMerrillDevicePage (mACMerrillLoop);
(Parent as PageLayout).AddChidren (mACMerrillDevicePage);
mACMerrillDevicePage.ShowView ();
(Parent as PageLayout).PageIndex = (Parent as PageLayout).ChildrenCount - 1;
};
var acRowView = new ACMerrillRowView (mACMerrillLoop, openACMerrillDevicePage) {
Height = Application.GetRealHeight (158),
};
VerticalScrolViewMiddle.AddChidren (acRowView);
}
void ShowAllAcOpenAlter () {
var mes = tempSwitch.IsSelected ? Language.StringByID (R.MyInternationalizationString.AllACOff) : Language.StringByID (R.MyInternationalizationString.AllACOpen);
Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
mes,
Language.StringByID (R.MyInternationalizationString.Cancel),
Language.StringByID (R.MyInternationalizationString.Confrim));
alert.Show ();
alert.ResultEventHandler += (sender2, e2) => {
if (e2) {
//状态取反
tempSwitch.IsSelected = !tempSwitch.IsSelected;
SetAllAcOpen (tempSwitch.IsSelected);
}
};
}
///
/// 全开全关
///
///
void SetAllAcOpen (bool isOn)
{
try {
mACMerrill.Power = isOn ? (byte)1 : (byte)0;
Control.ControlBytesSend (Command.SetCommonSwitch, mACMerrill.SubnetID, mACMerrill.DeviceID, new byte [] { (byte)MerrillMasterMode.AllOnAndOffMode, mACMerrill.Power });
} catch { }
}
///
/// 设置场景模式
///
///
void SetSceneModeIsAtHome (bool isAtHome)
{
try {
mACMerrill.ScenesMode = isAtHome ? (byte)0 : (byte)1;
Control.ControlBytesSend (Command.SetCommonSwitch, mACMerrill.SubnetID, mACMerrill.DeviceID, new byte [] { (byte)MerrillMasterMode.SceneMode, mACMerrill.ScenesMode });
} catch { }
}
///
/// 设置工作模式
/// 0制热、1制冷、2通风
///
/// 0制热、1制冷、2通风
void SetWorkMode (byte mWorkMode)
{
try {
mACMerrill.WorkMode = mWorkMode;
//byte sendByte = isAtHome ? (byte)1 : (byte)0;
Control.ControlBytesSend (Command.SetCommonSwitch, mACMerrill.SubnetID, mACMerrill.DeviceID, new byte [] { (byte)MerrillMasterMode.WorkMode, mWorkMode });
} catch { }
}
///
/// 通用开关模式ID
///
private enum MerrillMasterMode
{
///
/// 离家 在家
///
SceneMode = 1,
///
/// 全开全开
///
AllOnAndOffMode = 2,
///
/// 工作模式
///
WorkMode = 3,
}
///
/// 模拟量ID
///
private enum AnalogID
{
///
/// 功率
///
KW = 24,
///
/// 日功耗
///
DayPowerConsumption = 25,
///
/// 月功耗
///
MonthlyPowerConsumption = 26,
}
///
/// 读功耗
///
///
void ReadMerrillAnalogStatus (AnalogID readId)
{
try {
Control.ControlBytesSend (Command.ReadAnalog, mACMerrill.SubnetID, mACMerrill.DeviceID, new byte [] { 5, (byte)readId, 1 });
} catch { }
}
///
/// 读美林系统状态
///
///
void ReadMerrillStatus (MerrillMasterMode readId)
{
try {
Control.ControlBytesSend (Command.ReadHornLoopAlarm, mACMerrill.SubnetID, mACMerrill.DeviceID, new byte [] { (byte)readId });
} catch { }
}
///
/// 读空调状态
///
///
void ReadACStatus (ACMerrillLoop mAC)
{
Control.ControlBytesSend (Command.ReadACMode, mAC.SubnetID, mAC.DeviceID, new byte [] { mAC.LoopID });
}
System.Threading.Thread thread;
///
/// 读取系统状态
///
void ReadAllStatus ()
{
if (thread != null) {
thread.Abort ();
}
thread = new Thread (() => {
try {
ReadMerrillAnalogStatus (AnalogID.DayPowerConsumption);
Thread.Sleep (200);
ReadMerrillAnalogStatus (AnalogID.MonthlyPowerConsumption);
Thread.Sleep (200);
ReadMerrillAnalogStatus (AnalogID.KW);
Thread.Sleep (200);
ReadMerrillStatus (MerrillMasterMode.AllOnAndOffMode);
Thread.Sleep (200);
ReadMerrillStatus (MerrillMasterMode.SceneMode);
Thread.Sleep (200);
ReadMerrillStatus (MerrillMasterMode.WorkMode);
//读功率
//ReadACStatus (mACMerrill.mACMerrillLoopList[0]);
var list = mACMerrill.mACMerrillLoopList.FindAll ((obj) => {
return obj.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now;
});
//System.Collections.Generic.List readList = new System.Collections.Generic.List ();
foreach (ACMerrillLoop mACMerrillLoop in list) {
if (mACMerrillLoop == null) {
continue;
}
Thread.Sleep (200);
ReadACStatus (mACMerrillLoop);
}
} catch (Exception xe) {
Console.WriteLine (xe.Message);
} finally {
thread = null;
}
});
thread.Start ();
}
/////
///// 接受数据之后更新UI
/////
///// The user lights.
//public static void UpdateStatus (byte subnetID, byte deviceID, byte loopID, byte status)
//{
// Application.RunOnMainThread (() => {
// if (curView == null) return;
// if (curView.mLightDoorLock.ReadStatusSubnetID != subnetID
// || curView.mLightDoorLock.ReadStatusDeviceID != deviceID
// || curView.mLightDoorLock.ReadStatusLoopID != loopID) {
// return;
// }
// curView.mLightDoorLock.CurrentStatus = status;
// curView.RefreshButtonStatus ();
// });
//}
///
/// 更新美林系统状态
///
///
///
///
///
public static void UpdateMerrillModeStatus (byte SwitchID, byte StatusID)
{
Application.RunOnMainThread (() => {
if (curView == null) {
return;
}
if (curView.mACMerrill == null) {
return;
}
//if (curView.mACMerrill.SubnetID != subnetID || curView.mACMerrill.DeviceID != deviceID) {
// return;
//}
if (SwitchID == (byte)MerrillMasterMode.AllOnAndOffMode) {
curView.tempSwitch.IsSelected = StatusID > 0;
curView.mACMerrill.Power = StatusID;
} else if (SwitchID == (byte)MerrillMasterMode.SceneMode) {
curView.mACMerrill.ScenesMode = StatusID;
curView.atHomeBtn.IsSelected = !(StatusID > 0);
curView.outHomeBtn.IsSelected = StatusID > 0;
} else if (SwitchID == (byte)MerrillMasterMode.WorkMode) {
curView.coolingBtn.IsSelected = StatusID == 0;
curView.heatingBtn.IsSelected = StatusID == 1;
curView.strokeBtn.IsSelected = StatusID == 2;
curView.mACMerrill.WorkMode = StatusID;
}
});
}
///
/// 更新美林系统 功耗状态
///
///
///
///
///
public static void UpdateMerrillAnalogStatus (byte [] usefullBytes)
{
Application.RunOnMainThread (() => {
if (curView == null) {
return;
}
if (curView.mACMerrill == null) {
return;
}
if (usefullBytes.Length < 9) {
return;
}
if (usefullBytes [0] != 5) {
return;
}
//var SwitchID = usefullBytes [1];
//var values = usefullBytes [5] * 256 * 256 * 256 + usefullBytes [6] * 256 * 256 + usefullBytes [7] * 256 + usefullBytes [8];
////var SwitchID =
//if (SwitchID == (byte)AnalogID.DayPowerConsumption) {
// curView.mACMerrill.DailyPowerConsumption = values;
// curView.todayValueBtn.Text = values + "KWH";
//} else if (SwitchID == (byte)AnalogID.MonthlyPowerConsumption) {
// curView.mACMerrill.MonthlyPowerConsumption = values;
// curView.monthValueBtn.Text = values + "KWH";
//} else if (SwitchID == (byte)AnalogID.KW) {
// curView.mACMerrill.CurrentPower = values;
// curView.kwValueBtn.Text = values + "KW";
//}
try {
//2020-05-28 修改为float类型
var SwitchID = usefullBytes [1];
var values = floatChange (usefullBytes [8], usefullBytes [7], usefullBytes [6], usefullBytes [5]);
var valuesStr = values.ToString ("F2");
//var SwitchID =
if (SwitchID == (byte)AnalogID.DayPowerConsumption) {
curView.mACMerrill.DailyPowerConsumption = values;
curView.todayValueBtn.Text = valuesStr + "KWH";
} else if (SwitchID == (byte)AnalogID.MonthlyPowerConsumption) {
curView.mACMerrill.MonthlyPowerConsumption = values;
curView.monthValueBtn.Text = valuesStr + "KWH";
} else if (SwitchID == (byte)AnalogID.KW) {
curView.mACMerrill.CurrentPower = values;
curView.kwValueBtn.Text = valuesStr + "KW";
}
} catch { }
});
}
public static float floatChange (byte b1, byte b2, byte b3, byte b4)
{
try {
byte [] byteTemp = new byte [4] { b4, b3, b2, b1 };
return BitConverter.ToSingle (byteTemp, 0);
} catch {
return 0.0f;
}
}
public static void SaveMerrilEquipmentMessage ()
{
if (curView == null) {
return;
}
if (curView.mACMerrill == null) {
return;
}
IO.FileUtils.SaveEquipmentMessage (curView.mACMerrill, curView.mACMerrill.LoopID.ToString ());
//IO.FileUtils.SaveEquipmentMessage (curView.mACMerrill);
}
///
/// 更新空调
///
public static void UpdateACStatus (ACMerrillLoop ac, bool selfUpdate = false)
{
Application.RunOnMainThread (() => {
try {
if (curView == null) {
return;
}
if (curView.bodyScrolView.Decelerating) {
return;
}
for (int i = 0; i < curView.mACListScrolView.ChildrenCount; i++) {
if (curView.mACListScrolView.GetChildren (i).GetType () == typeof (ACMerrillRowView)) {
var acRow = (ACMerrillRowView)curView.mACListScrolView.GetChildren (i);
var o = acRow.Tag;
if (o != null && o.ToString () == ac.CommonLoopID) {
acRow.UpdateButton (ac);
}
}
}
} catch {
}
});
}
///
/// 刷新
///
public static void UpdateACRowView () {
if (curView == null) {
return;
}
curView.LoadACList ();
}
}
}