using System;
|
using System.Collections.Generic;
|
using System.Threading;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
/// <summary>
|
/// 通过灯光设备类型,显示出所有房间的灯光
|
/// </summary>
|
public class UserDeviceToLight : FrameLayout
|
{
|
/// <summary>
|
/// 当前设备界面
|
/// </summary>
|
static UserDeviceToLight curView;
|
VerticalScrolViewLayout equipmentListScrolView;
|
VerticalScrolViewLayout bodyScrolView;
|
Thread readEnergyThead;
|
bool readEnergy = false;
|
List<Common> EnergtLightList = new List<Common> ();
|
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
public UserDeviceToLight ()
|
{
|
curView = this;
|
readAllStatus ();
|
}
|
|
public override void RemoveFromParent ()
|
{
|
curView = null;
|
readEnergy = false;
|
if (readEnergyThead != null)
|
readEnergyThead.Abort ();
|
base.RemoveFromParent ();
|
}
|
/// <summary>
|
/// 更新能源设备数据
|
/// </summary>
|
/// <param name="updataType">更新类型(bit0-bit5) 2: 电压 3: 电流 10:功率 11:电能 (BIT 6-7 0:2bytes 1:1bytes 2:4bytes)</param>
|
/// <param name="updataFlag">更新的设备标记</param>
|
/// <param name="energy">更新的值</param>
|
public static void UpdataEnergy (int updataType, string updataFlag, int energy)
|
{
|
Application.RunOnMainThread (() => {
|
if (curView == null) {
|
return;
|
}
|
if (curView.equipmentListScrolView.Decelerating) {
|
return;
|
}
|
for (int i = 0; i < curView.equipmentListScrolView.ChildrenCount; i++) {
|
if (curView.equipmentListScrolView.GetChildren (i).GetType () == typeof (FrameLayout)) {
|
var lightRow = (FrameLayout)curView.equipmentListScrolView.GetChildren (i);
|
var o = lightRow.GetTagByKey ("UpdataKey");
|
if (o != null && o.ToString () == updataFlag) {
|
for (int j = 0; j < lightRow.ChildrenCount; j++) {
|
if (lightRow.GetChildren (j).GetType () == typeof (Button)) {
|
var btn = (Button)lightRow.GetChildren (j);
|
if (btn.Tag != null) {
|
if (updataType == 10) {
|
if (btn.Tag.ToString () == DeviceType.LightEnergySocket.ToString () + "_Voltage" || btn.Tag.ToString () == DeviceType.LightEnergySwitch.ToString () + "_Voltage") {
|
btn.Text = energy.ToString () + " W";
|
}
|
} else if (updataType == 11) {
|
if (btn.Tag.ToString () == DeviceType.LightEnergySocket.ToString () + "_Electric" || btn.Tag.ToString () == DeviceType.LightEnergySwitch.ToString () + "_Electric") {
|
btn.Text = ((double)(Convert.ToDouble (energy) / 10)).ToString () + " kw.h";
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
});
|
}
|
|
|
public static void UpdateBrighingCount (string updataFlag)
|
{
|
#region 更新用户主界面灯光点亮总数
|
int brighingCount = 0;
|
foreach (var room in Room.Lists) {
|
if (string.IsNullOrEmpty (room.Name)) {
|
continue;
|
}
|
foreach (var light in room.DeviceList) {
|
if (light.Type == DeviceType.LightDimming || light.Type == DeviceType.LightMixDimming || light.Type == DeviceType.LightDALI) {
|
if ((light as LightDimming).CurrentBrightness > 0)
|
brighingCount++;
|
} else if (light.Type == DeviceType.LightSwitch || light.Type == DeviceType.LightMixSwitch)
|
if ((light as LightSwitch).CurrentBrightness == 100)
|
brighingCount++;
|
if (light.Type == DeviceType.LightRGB)
|
if ((light as LightLogic).CurrentBrightness > 0)
|
brighingCount++;
|
}
|
}
|
UserDeviceView.UpdataDeviceCountNumber (brighingCount, Language.StringByID (R.MyInternationalizationString.Lights));
|
if (curView != null)
|
curView.updateLigthOnCount (updataFlag);
|
#endregion
|
}
|
|
/// <summary>
|
/// 更新当前灯光
|
/// </summary>
|
public static void UpdateStatus (string updataFlag, byte brightness)
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
Application.RunOnMainThread (() => {
|
if (curView == null) {
|
return;
|
}
|
if (UserConfig.Instance.ShowRoomLightList) {
|
for (int i = 0; i < curView.equipmentListScrolView.ChildrenCount; i++) {
|
if (curView.equipmentListScrolView.GetChildren (i).GetType () == typeof (FrameLayout)) {
|
var lightRow = (FrameLayout)curView.equipmentListScrolView.GetChildren (i);
|
var o = lightRow.GetTagByKey ("UpdataKey");
|
if (o != null && o.ToString () == updataFlag) {
|
for (int j = 0; j < lightRow.ChildrenCount; j++) {
|
if (lightRow.GetChildren (j).GetType () == typeof (Button)) {
|
var btn = (Button)lightRow.GetChildren (j);
|
if (brightness == 0) {
|
btn.IsSelected = false;
|
} else {
|
btn.IsSelected = true;
|
}
|
} else if (lightRow.GetChildren (j).GetType () == typeof (HorizontalSeekBar) && 3 < (DateTime.Now - (DateTime)lightRow.GetChildren (j).Tag).TotalSeconds) {
|
(lightRow.GetChildren (j) as HorizontalSeekBar).Progress = brightness;
|
if (brightness > 0) {
|
(lightRow.GetChildren (j) as HorizontalSeekBar).ThumbColor = SkinStyle.Current.SelectedColor;
|
} else {
|
(lightRow.GetChildren (j) as HorizontalSeekBar).ThumbColor = SkinStyle.Current.ThumbColor;
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
curView.updateLigthOnCount (updataFlag);
|
});
|
});
|
}
|
/// <summary>
|
/// 显示当前多少个灯是亮的
|
/// 灯光模块如果很多的话,这么会频繁更新
|
/// </summary>
|
void updateLigthOnCount (string updataFlag)
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
int oCount = 0;
|
Room updateRoom = null;
|
foreach (var room in Room.Lists) {
|
if (string.IsNullOrEmpty (room.Name)) {
|
continue;
|
}
|
var findLight = room.DeviceList.Find ((obj) => obj.CommonLoopID == updataFlag);
|
if (findLight == null)
|
continue;
|
|
oCount = 0;
|
updateRoom = room;
|
foreach (var light in room.DeviceList) {
|
if (light.Type == DeviceType.LightDimming || light.Type == DeviceType.LightMixDimming) {
|
if ((light as LightDimming).CurrentBrightness > 0)
|
oCount++;
|
} else if (light.Type == DeviceType.LightRGB) {
|
if ((light as LightLogic).CurrentBrightness > 0)
|
oCount++;
|
} else if (light.Type == DeviceType.LightSwitch || light.Type == DeviceType.LightMixSwitch) {
|
if ((light as LightSwitch).CurrentBrightness == 100)
|
oCount++;
|
}
|
}
|
}
|
//if (!update) {
|
// Console.WriteLine ("退出更新灯光");
|
// return;
|
//}
|
Application.RunOnMainThread (() => {
|
try {
|
for (int i = 0; i < curView.bodyScrolView.ChildrenCount; i++) {
|
if (curView.bodyScrolView == null) {
|
return;
|
}
|
if (curView.bodyScrolView.GetChildren (i).GetType () == typeof (FrameLayout)) {
|
var roomRow = (FrameLayout)curView.bodyScrolView.GetChildren (i);
|
if (roomRow.Tag == null) {
|
continue;
|
}
|
if (roomRow.Tag.ToString () == updateRoom.Name) {
|
for (int j = 0; j < roomRow.ChildrenCount; j++) {
|
if (roomRow.GetChildren (j).GetType () == typeof (EditText)) {
|
var et = (EditText)roomRow.GetChildren (j);
|
et.Text = oCount.ToString ();
|
if (oCount > 0) {
|
et.TextColor = SkinStyle.Current.SelectedColor;
|
} else {
|
et.TextColor = SkinStyle.Current.TextColor1;
|
et.Text = updateRoom.DeviceList.FindAll ((obj) => {
|
return obj.Type == DeviceType.LightRGB || obj.Type == DeviceType.LightDimming
|
|| obj.Type == DeviceType.LightMixSwitch || obj.Type == DeviceType.LightMixDimming
|
|| obj.Type == DeviceType.LightSwitch;
|
}).Count.ToString ();
|
}
|
}
|
if (roomRow.GetChildren (j).GetType () == typeof (Button)) {
|
var btn = (Button)roomRow.GetChildren (j);
|
if (oCount > 0) {
|
btn.IsSelected = true;
|
} else {
|
btn.IsSelected = false;
|
}
|
}
|
}
|
}
|
|
}
|
}
|
} catch {
|
return;
|
}
|
});
|
});
|
Console.WriteLine ("U1");
|
}
|
bool showTip = true;
|
/// <summary>
|
/// 控制所有的灯
|
/// </summary>
|
/// <param name="b">The blue component.</param>
|
void controlAllLight (byte b)
|
{
|
showTip = true;
|
MainPage.Loading.Start ("Sending...");
|
|
System.Threading.Tasks.Task.Run (() => {
|
foreach (var room in Room.Lists) {
|
if (room == null)
|
continue;
|
if (string.IsNullOrEmpty (room.Name)) {
|
continue;
|
}
|
foreach (var common in room.DeviceList) {
|
byte [] returnBytes = null;
|
if (common.Type == DeviceType.LightDimming || common.Type == DeviceType.LightSwitch || common.Type == DeviceType.LightRGB || common.Type == DeviceType.LightEnergySwitch
|
|| common.Type == DeviceType.LightMixDimming || common.Type == DeviceType.LightMixSwitch || common.Type == DeviceType.LightDALI) {
|
if (common.Type == DeviceType.LightDimming || common.Type == DeviceType.LightDALI) {
|
var light = (LightDimming)common;
|
if (b == 100) {
|
if (light.LastOpenBrightness == 0) {
|
returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { light.LoopID, b, light.DelayTimeHeight, light.DelayTimeLow });
|
} else
|
returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { light.LoopID, light.LastOpenBrightness, light.DelayTimeHeight, light.DelayTimeLow });
|
} else
|
returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { light.LoopID, b, light.DelayTimeHeight, light.DelayTimeLow });
|
} else if (common.Type == DeviceType.LightSwitch || common.Type == DeviceType.LightEnergySwitch) {
|
returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { common.LoopID, b, ((LightSwitch)common).DelayTimeHeight, ((LightSwitch)common).DelayTimeLow });
|
} else if (common.Type == DeviceType.LightRGB) {
|
var light = (LightLogic)common;
|
byte b2 = b;
|
if (b2 == 100) {
|
if (light.LastOpenBrightness != 0) {
|
b2 = light.LastOpenBrightness;
|
}
|
}
|
returnBytes = Control.ControlBytesSendHasReturn (Command.SetLogicLoopColor, common.SubnetID, common.DeviceID, new byte [] {
|
common.LoopID, b2, 254, light.CustomDelayTimeOpen,light.CustomDelayTimeClose,
|
3,light.RStatus,light.GStatus,light.BStatus,0,0});
|
} else if (common.Type == DeviceType.LightMixDimming) {
|
var light = (LightMixDimming)common;
|
if (b == 100) {
|
if (light.LastOpenBrightness == 0) {
|
returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { light.PhysicsLoopID, b, light.DelayTimeHeight, light.DelayTimeLow });
|
} else
|
returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { light.PhysicsLoopID, light.LastOpenBrightness, light.DelayTimeHeight, light.DelayTimeLow });
|
} else
|
returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { light.PhysicsLoopID, b, light.DelayTimeHeight, light.DelayTimeLow });
|
} else if (common.Type == DeviceType.LightMixSwitch) {
|
var light = (LightMixSwitch)common;
|
returnBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { light.PhysicsLoopID, b, light.DelayTimeHeight, light.DelayTimeLow });
|
}
|
if (showTip) {
|
Application.RunOnMainThread (() => {
|
if (returnBytes == null) {
|
string tipString = Language.StringByID (R.MyInternationalizationString.ControlFailure);
|
var btnTip = new Button () {
|
Height = Application.GetRealHeight (140),
|
Text = common.Name + tipString,// + "..." + controlDeviceIndex.ToString () + @"/" + sceneDeviceCount.ToString (),
|
BackgroundColor = 0xFFD7D7D7,
|
};
|
MainPage.MainFrameLayout.AddChidren (btnTip);
|
btnTip.MouseUpEventHandler += (sender, e) => {
|
btnTip.RemoveFromParent ();
|
//MainPage.MainFrameLayout.Remove (btnTip);
|
showTip = false;
|
};
|
|
System.Threading.Tasks.Task.Run (() => {
|
System.Threading.Thread.Sleep (3000);
|
Application.RunOnMainThread (() => {
|
btnTip.RemoveFromParent ();
|
//MainPage.MainFrameLayout.Remove (btnTip);
|
});
|
});
|
}
|
});
|
}
|
}
|
}
|
}
|
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
});
|
}
|
/// <summary>
|
/// 通过设备类型方式选择设备
|
/// </summary>
|
public void showAllRoomLights ()
|
{
|
#region 标题
|
var topView = new FrameLayout () {
|
Y = Application.GetRealHeight (36),
|
Height = Application.GetRealHeight (90),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
AddChidren (topView);
|
|
var title = new Button () {
|
TextAlignment = TextAlignment.Center,
|
Text = Language.StringByID (R.MyInternationalizationString.Lights),
|
TextColor = SkinStyle.Current.TextColor1,
|
TextSize = 19,
|
};
|
topView.AddChidren (title);
|
|
var logo = new Button () {
|
Width = Application.GetRealWidth (154),
|
Height = Application.GetRealHeight (90),
|
X = Application.GetRealWidth (486),
|
UnSelectedImagePath = MainPage.LogoString,
|
};
|
topView.AddChidren (logo);
|
var back = new Button () {
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (85),
|
UnSelectedImagePath = "Item/Back.png",
|
SelectedImagePath = "Item/BackSelected.png",
|
};
|
topView.AddChidren (back);
|
back.MouseUpEventHandler += (sender, e) => {
|
(Parent as PageLayout).PageIndex -= 1;
|
curView = null;
|
};
|
#endregion
|
|
#region 全开-全关
|
var powerView = new FrameLayout () {
|
Height = Application.GetRealHeight (110),
|
BackgroundColor = SkinStyle.Current.TitileView,
|
Y = topView.Bottom
|
};
|
AddChidren (powerView);
|
var btnAllON = new Button () {
|
Width = Application.GetRealWidth (320),
|
TextSize = 16,
|
TextID = R.MyInternationalizationString.ALLON,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
powerView.AddChidren (btnAllON);
|
var btnAllOff = new Button () {
|
Width = Application.GetRealWidth (320),
|
X = btnAllON.Right,
|
TextSize = 16,
|
TextID = R.MyInternationalizationString.ALLOFF,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
powerView.AddChidren (btnAllOff);
|
var btnLine = new Button () {
|
Width = 1,
|
BackgroundColor = SkinStyle.Current.White20Transparent,
|
X = btnAllON.Right,
|
};
|
powerView.AddChidren (btnLine);
|
#endregion
|
|
bodyScrolView = new VerticalScrolViewLayout () {
|
Height = Application.GetRealHeight (1136 - 126 - 110),
|
Y = powerView.Bottom,
|
};
|
AddChidren (bodyScrolView);
|
|
//显示有多少个房间,每个房间有多少个灯开
|
foreach (var room in Room.Lists) {
|
if (string.IsNullOrEmpty (room.Name)) {
|
continue;
|
}
|
var lightListForRoom = room.DeviceList.FindAll ((obj) => {
|
return obj.Type == DeviceType.LightDimming || obj.Type == DeviceType.LightSwitch || obj.Type == DeviceType.LightRGB
|
|| obj.Type == DeviceType.LightMixSwitch || obj.Type == DeviceType.LightMixDimming || obj.Type == DeviceType.LightDALI;
|
});
|
if (lightListForRoom == null) {
|
continue;
|
}
|
FrameLayout roomView = new FrameLayout () {
|
Height = Application.GetRealHeight (110),
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
Tag = room.Name
|
};
|
bodyScrolView.AddChidren (roomView);
|
Button btnRoomNull = new Button () {
|
Height = 1,
|
SelectedBackgroundColor = SkinStyle.Current.MainColor,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
bodyScrolView.AddChidren (btnRoomNull);
|
Button btnPoint = new Button () {
|
Width = Application.GetRealWidth (10),
|
Height = Application.GetRealHeight (10),
|
X = Application.GetRealWidth (30),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Item/Point.png",
|
SelectedImagePath = "Item/Point.png",
|
};
|
roomView.AddChidren (btnPoint);
|
Button btnRoomName = new Button () {
|
Text = room.Name,
|
X = btnPoint.Right + Application.GetRealWidth (20),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.TextColor1,
|
SelectedTextColor = SkinStyle.Current.TextColor1,
|
};
|
roomView.AddChidren (btnRoomName);
|
|
EditText btnNumber = new EditText () {
|
Width = Application.GetMinRealAverage (50),
|
Height = Application.GetMinRealAverage (35),
|
X = Application.GetRealWidth (640 - 100 - 50 - 20),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Item/LightingCount.png",
|
SelectedImagePath = "Item/LightingCount.png",
|
Enable = false,
|
Text = lightListForRoom.Count.ToString (),
|
TextColor = SkinStyle.Current.TextColor1,
|
TextAlignment = TextAlignment.Center,
|
Tag = room.Name
|
};
|
roomView.AddChidren (btnNumber);
|
|
Button btnLightIcon = new Button () {
|
Width = Application.GetRealWidth (100),
|
Height = Application.GetRealHeight (80),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Item/RH_Lights.png",
|
SelectedImagePath = "Item/RH_LightsSelected.png",
|
X = btnNumber.Right
|
};
|
roomView.AddChidren (btnLightIcon);
|
|
btnRoomName.MouseUpEventHandler += (sender, e) => {
|
var userLightView = new UserLightPage (room);
|
UserMiddle.DevicePageView.AddChidren (userLightView);
|
userLightView.showLightsRoom ();
|
UserMiddle.DevicePageView.PageIndex = 2;
|
};
|
|
|
System.Threading.Tasks.Task.Run (() => {
|
int num = 0;
|
foreach (var light in room.DeviceList) {
|
if (light.Type == DeviceType.LightDimming || light.Type == DeviceType.LightMixDimming) {
|
if ((light as LightDimming).CurrentBrightness > 0)
|
num++;
|
} else if (light.Type == DeviceType.LightRGB) {
|
if ((light as LightLogic).CurrentBrightness > 0)
|
num++;
|
} else if (light.Type == DeviceType.LightSwitch || light.Type == DeviceType.LightMixSwitch) {
|
if ((light as LightSwitch).CurrentBrightness == 100)
|
num++;
|
}
|
}
|
|
if (num > 0) {
|
Application.RunOnMainThread (() => {
|
btnNumber.TextColor = SkinStyle.Current.SelectedColor;
|
btnNumber.Text = num.ToString ();
|
btnLightIcon.IsSelected = true;
|
});
|
}
|
});
|
}
|
|
|
#region 显示全部的灯光
|
FrameLayout ShowAllView = new FrameLayout () {
|
Height = Application.GetRealHeight (85),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
bodyScrolView.AddChidren (ShowAllView);
|
|
Button btnShowAll = new Button () {
|
X = Application.GetRealWidth (20),
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = Language.StringByID (R.MyInternationalizationString.AllLight),
|
TextColor = SkinStyle.Current.TextColor1,
|
SelectedTextColor = SkinStyle.Current.TextColor1
|
};
|
ShowAllView.AddChidren (btnShowAll);
|
|
Button downSelectedButton = new Button () {
|
X = Application.GetRealWidth (550),
|
Height = Application.GetRealHeight (50),
|
Width = Application.GetRealWidth (55),
|
UnSelectedImagePath = "Item/Down.png",
|
SelectedImagePath = "Item/DownSelected.png",
|
Gravity = Gravity.CenterVertical,
|
IsSelected = true,
|
};
|
ShowAllView.AddChidren (downSelectedButton);
|
|
//显示出所有的灯
|
equipmentListScrolView = new VerticalScrolViewLayout () {
|
Height = bodyScrolView.Height - ShowAllView.Height,
|
};
|
bodyScrolView.AddChidren (equipmentListScrolView);
|
|
int LightCount = 0;
|
var lightList = new List<Common> ();
|
foreach (var room in Room.Lists) {
|
if (room == null) {
|
Console.WriteLine ("Null is Room");
|
continue;
|
}
|
Console.WriteLine ("RoomCount" + Room.Lists.Count);
|
|
Console.WriteLine (room.Name);
|
if (string.IsNullOrEmpty (room.Name)) {
|
Console.WriteLine ("Null is Room Name");
|
continue;
|
}
|
foreach (var common in room.DeviceList) {
|
if (common.Type == DeviceType.LightSwitch || common.Type == DeviceType.LightMixSwitch) {
|
LightCount++;
|
lightList.Add (common);
|
} else if (common.Type == DeviceType.LightDimming || common.Type == DeviceType.LightDALI || common.Type == DeviceType.LightMixDimming) {
|
LightCount++;
|
lightList.Add (common);
|
} else if (common.Type == DeviceType.LightRGB) {
|
LightCount++;
|
lightList.Add (common);
|
}
|
}
|
}
|
|
EventHandler<MouseEventArgs> eHandler = (sender, e) => {
|
//return;
|
MainPage.Loading.Start ("Please wait...");
|
btnShowAll.IsSelected = !btnShowAll.IsSelected;
|
downSelectedButton.IsSelected = btnShowAll.IsSelected;
|
UserConfig.Instance.ShowRoomLightList = btnShowAll.IsSelected;
|
UserConfig.Instance.SaveUserConfig ();
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
Application.RunOnMainThread (() => {
|
if (btnShowAll.IsSelected) {
|
equipmentListScrolView.RemoveAll ();
|
foreach (var room in Room.Lists) {
|
if (room == null) {
|
continue;
|
}
|
if (string.IsNullOrEmpty (room.Name)) {
|
continue;
|
}
|
foreach (var common in room.DeviceList) {
|
if (common.Type == DeviceType.LightSwitch || common.Type == DeviceType.LightMixSwitch ||
|
common.Type == DeviceType.LightEnergySwitch) {
|
LightCount++;
|
byte sendLoopID = 0;
|
if (common.Type == DeviceType.LightMixSwitch) {
|
sendLoopID = (common as LightMixSwitch).PhysicsLoopID;
|
} else {
|
sendLoopID = (common as LightSwitch).LoopID;
|
}
|
var light = common as LightSwitch;
|
FrameLayout lightView = new FrameLayout () {
|
Height = Application.GetRealHeight (130),
|
};
|
lightView.AddTag ("UpdataKey", common.CommonLoopID);
|
equipmentListScrolView.AddChidren (lightView);
|
Button btnLightViewBottomNull = new Button () {
|
Y = Application.GetRealHeight (127),
|
Height = Application.GetRealHeight (3),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
SelectedBackgroundColor = SkinStyle.Current.MainColor,
|
};
|
lightView.AddChidren (btnLightViewBottomNull);
|
|
//灯名
|
var tempDeviceName = new Button () {
|
X = Application.GetRealWidth (20),
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = room.Name + "-" + light.Name,
|
TextColor = SkinStyle.Current.TextColor1,
|
SelectedTextColor = SkinStyle.Current.TextColor1,
|
Enable = false,
|
};
|
lightView.AddChidren (tempDeviceName);
|
|
|
var tempSwitch = new Button () {
|
Width = Application.GetMinRealAverage (90),
|
Height = Application.GetMinRealAverage (53),
|
X = Application.GetRealWidth (640 - 90 - 20),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Item/SwitchClose.png",
|
SelectedImagePath = "Item/SwitchOpen.png",
|
};
|
lightView.AddChidren (tempSwitch);
|
|
if (common.Type == DeviceType.LightEnergySwitch || common.Type == DeviceType.LightEnergySocket) {
|
Button btnEnergy = new Button () {
|
Width = Application.GetRealWidth (90),
|
Height = Application.GetRealHeight (30),
|
X = tempSwitch.X,
|
Y = tempSwitch.Bottom,
|
TextColor = SkinStyle.Current.TextColor1,
|
SelectedTextColor = SkinStyle.Current.TextColor1,
|
Tag = common.Type.ToString () + "_Voltage",
|
Text = "0 W"
|
};
|
lightView.AddChidren (btnEnergy);
|
EnergtLightList.Add (common);
|
|
if (common.Type == DeviceType.LightEnergySwitch) {
|
Button btnElectric = new Button () {
|
Width = Application.GetRealWidth (200),
|
Height = Application.GetRealHeight (35),
|
X = Application.GetRealWidth (320),
|
Y = tempSwitch.Bottom,
|
TextAlignment = TextAlignment.CenterRight,
|
TextColor = SkinStyle.Current.TextColor1,
|
SelectedTextColor = SkinStyle.Current.TextColor1,
|
Tag = common.Type.ToString () + "_Electric",
|
Text = "0 kw.h"
|
};
|
lightView.AddChidren (btnElectric);
|
}
|
}
|
|
tempSwitch.MouseUpEventHandler += (sender3, e3) => {
|
tempSwitch.IsSelected = !tempSwitch.IsSelected;
|
if (tempSwitch.IsSelected) {
|
light.CurrentBrightness = 100;
|
} else {
|
light.CurrentBrightness = 0;
|
}
|
Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { sendLoopID, (byte)light.CurrentBrightness, light.DelayTimeHeight, light.DelayTimeLow });
|
|
new System.Threading.Thread (() => {
|
Control.ControlBytesSend (Command.ReadAnalogValue, light.SubnetID, light.DeviceID, new byte [] { 10, light.LoopID }, SendCount.Zero);
|
Control.ControlBytesSend (Command.ReadAnalogValue, light.SubnetID, light.DeviceID, new byte [] { 11, light.LoopID }, SendCount.Zero);
|
}) { IsBackground = true }.Start ();
|
|
};
|
|
if (light.CurrentBrightness == 100) {
|
tempSwitch.IsSelected = true;
|
}
|
}
|
else if (common.Type == DeviceType.LightDimming || common.Type == DeviceType.LightDALI || common.Type == DeviceType.LightMixDimming) {
|
LightCount++;
|
byte sendLoopID = 0;
|
if (common.Type == DeviceType.LightMixDimming) {
|
sendLoopID = (common as LightMixDimming).PhysicsLoopID;
|
} else {
|
sendLoopID = (common as LightDimming).LoopID;
|
}
|
var light = common as LightDimming;
|
|
var lightView = new FrameLayout () {
|
Height = Application.GetRealHeight (130),
|
};
|
lightView.AddTag ("UpdataKey", light.CommonLoopID);
|
equipmentListScrolView.AddChidren (lightView);
|
Button btnLightViewBottomNull = new Button () {
|
Y = Application.GetRealHeight (127),
|
Height = Application.GetRealHeight (3),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
SelectedBackgroundColor = SkinStyle.Current.MainColor,
|
};
|
lightView.AddChidren (btnLightViewBottomNull);
|
|
// 灯光名称
|
var tempLightName = new Button () {
|
X = Application.GetRealWidth (20),
|
Y = Application.GetRealHeight (10),
|
TextAlignment = light.DimmingFunction ? TextAlignment.TopLeft : TextAlignment.CenterLeft,
|
Text = room.Name + "-" + light.Name,
|
TextColor = SkinStyle.Current.TextColor1,
|
SelectedTextColor = SkinStyle.Current.TextColor1,
|
Enable = false,
|
};
|
|
if (!light.DimmingFunction) {
|
tempLightName.Y = 0;
|
}
|
lightView.AddChidren (tempLightName);
|
|
//var btnValues = new Button () {
|
// X = Application.GetRealHeight (30),
|
// Y = Application.GetRealHeight (40),
|
// Width = Application.GetRealWidth (55),
|
// Height = Application.GetRealHeight (130 - 20),
|
// TextColor = SkinStyle.Current.TextColor1,
|
// Text = light.CurrentBrightness + "%",
|
// TextSize = 10,
|
// Tag = "Values",
|
// SelectedTextColor = SkinStyle.Current.TextColor1,
|
// TextAlignment = TextAlignment.Center
|
//};
|
//lightView.AddChidren (btnValues);
|
|
//进度条
|
var tempLightSeekBar = new HorizontalSeekBar () {
|
Width = Application.GetRealWidth (440 - 20),
|
Height = Application.GetRealHeight (130 - 20),
|
X = Application.GetRealWidth (20),
|
Y = Application.GetRealHeight (20),
|
Visible = light.DimmingFunction,
|
Tag = DateTime.MinValue,
|
Progress = light.CurrentBrightness,
|
ThumbColor = light.CurrentBrightness > 0 ? SkinStyle.Current.SelectedColor : SkinStyle.Current.ThumbColor
|
};
|
lightView.AddChidren (tempLightSeekBar);
|
|
//开关按键
|
var tempSwitch = new Button () {
|
Width = Application.GetMinRealAverage (90),
|
Height = Application.GetMinRealAverage (53),
|
X = Application.GetRealWidth (640 - 90 - 20),
|
Y = Application.GetRealHeight (50),
|
UnSelectedImagePath = "Item/SwitchClose.png",
|
SelectedImagePath = "Item/SwitchOpen.png",
|
};
|
lightView.AddChidren (tempSwitch);
|
tempLightSeekBar.AddTag ("UpdataKey", light.CommonLoopID);
|
|
tempLightSeekBar.ProgressChanged += (senderp, ep) => {
|
if (light.CurrentBrightness > 0) {
|
tempLightSeekBar.ThumbColor = SkinStyle.Current.SelectedColor;
|
} else {
|
tempLightSeekBar.ThumbColor = SkinStyle.Current.ThumbColor;
|
}
|
if (tempLightSeekBar.Progress > 0) {
|
tempSwitch.IsSelected = true;
|
} else {
|
tempSwitch.IsSelected = false;
|
}
|
light.CurrentBrightness = (byte)ep;
|
|
if (light.CurrentBrightness == 0 || light.CurrentBrightness == 100) {
|
Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { sendLoopID, (byte)ep, 0, 0 }, SendCount.Zero);
|
tempLightSeekBar.Tag = DateTime.Now;
|
return;
|
}
|
|
if ((System.DateTime.Now - (DateTime)(tempLightSeekBar.Tag)).TotalMilliseconds < 500) {
|
return;
|
}
|
tempLightSeekBar.Tag = DateTime.Now;
|
|
Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { sendLoopID, (byte)ep, 0, 0 }, SendCount.Zero);
|
};
|
tempLightSeekBar.MouseUpEventHandler += (sender1, e1) => {
|
//弹起的时候发最后的数据
|
tempLightSeekBar.Tag = DateTime.Now;
|
light.LastOpenBrightness = Convert.ToByte (tempLightSeekBar.Progress);
|
Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { sendLoopID, (byte)tempLightSeekBar.Progress, 0, 0 });
|
if (tempLightSeekBar.Progress > 0) {
|
tempSwitch.IsSelected = true;
|
} else {
|
tempSwitch.IsSelected = false;
|
}
|
light.CurrentBrightness = (byte)tempLightSeekBar.Progress;
|
};
|
|
tempSwitch.MouseUpEventHandler += (sender3, e3) => {
|
tempSwitch.IsSelected = !tempSwitch.IsSelected;
|
if (light.LastOpenBrightness == 0) {
|
light.LastOpenBrightness = 100;
|
}
|
if (tempSwitch.IsSelected) {
|
tempLightSeekBar.Progress = light.LastOpenBrightness;
|
} else {
|
tempLightSeekBar.Progress = 0;
|
}
|
light.CurrentBrightness = (byte)tempLightSeekBar.Progress;
|
Control.ControlBytesSend (Command.SetSingleLight, light.SubnetID, light.DeviceID, new byte [] { sendLoopID, light.CurrentBrightness, light.DelayTimeHeight, light.DelayTimeLow });
|
};
|
if (light.CurrentBrightness > 0) {
|
tempSwitch.IsSelected = true;
|
}
|
}
|
else if (common.Type == DeviceType.LightRGB) {
|
LightCount++;
|
var light = common as LightLogic;
|
var lightView = new FrameLayout () {
|
Height = Application.GetRealHeight (130),
|
};
|
lightView.AddTag ("UpdataKey", light.CommonLoopID + "RGB");
|
equipmentListScrolView.AddChidren (lightView);
|
Button btnLightViewBottomNull = new Button () {
|
Y = Application.GetRealHeight (127),
|
Height = Application.GetRealHeight (3),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
SelectedBackgroundColor = SkinStyle.Current.MainColor,
|
};
|
lightView.AddChidren (btnLightViewBottomNull);
|
|
// 灯光名称
|
var tempLightName = new Button () {
|
X = Application.GetRealWidth (20),
|
Y = Application.GetRealHeight (10),
|
TextAlignment = light.DimmingFunction ? TextAlignment.TopLeft : TextAlignment.CenterLeft,
|
Text = room.Name + "-" + light.Name,
|
TextColor = SkinStyle.Current.TextColor1,
|
Enable = false,
|
};
|
|
if (!light.DimmingFunction) {
|
tempLightName.Y = 0;
|
}
|
lightView.AddChidren (tempLightName);
|
//进度条
|
var tempLightSeekBar = new HorizontalSeekBar () {
|
Width = Application.GetRealWidth (440 - 20),
|
Height = Application.GetRealHeight (130 - 20),
|
X = Application.GetRealWidth (20),
|
Y = Application.GetRealHeight (20),
|
Visible = light.DimmingFunction,
|
Tag = DateTime.MinValue,
|
Progress = light.CurrentBrightness,
|
ThumbColor = SkinStyle.Current.ThumbColor,
|
};
|
lightView.AddChidren (tempLightSeekBar);
|
|
//开关按键
|
var tempSwitch = new Button () {
|
Width = Application.GetMinRealAverage (90),
|
Height = Application.GetMinRealAverage (53),
|
X = Application.GetRealWidth (640 - 90 - 20),
|
Y = Application.GetRealHeight (50),
|
//Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Item/SwitchClose.png",
|
SelectedImagePath = "Item/SwitchOpen.png",
|
};
|
lightView.AddChidren (tempSwitch);
|
tempLightSeekBar.AddTag ("UpdataKey", light.CommonLoopID);
|
|
tempLightSeekBar.ProgressChanged += (senderp, ep) => {
|
if ((System.DateTime.Now - (DateTime)(tempLightSeekBar.Tag)).TotalMilliseconds < 500) {
|
return;
|
}
|
tempLightSeekBar.Tag = DateTime.Now;
|
light.CurrentBrightness = (byte)ep;
|
Control.ControlBytesSend (Command.SetLogicLoopColor, light.SubnetID,
|
light.DeviceID, new byte [] { light.LoopID, light.CurrentBrightness, 254, 0,0,
|
3,light.RStatus,light.GStatus,light.BStatus,0,0}, SendCount.Zero);
|
if (light.CurrentBrightness > 0) {
|
tempSwitch.IsSelected = true;
|
} else {
|
tempSwitch.IsSelected = false;
|
}
|
light.CurrentBrightness = (byte)ep;
|
};
|
tempLightSeekBar.MouseUpEventHandler += (sender1, e1) => {
|
//弹起的时候发最后的数据
|
tempLightSeekBar.Tag = DateTime.Now;
|
light.CurrentBrightness = light.LastOpenBrightness = Convert.ToByte (tempLightSeekBar.Progress);
|
Control.ControlBytesSend (Command.SetLogicLoopColor, light.SubnetID,
|
light.DeviceID, new byte [] { light.LoopID, light.CurrentBrightness, 254, 0,0,
|
3,light.RStatus,light.GStatus,light.BStatus,0,0}, SendCount.Zero);
|
if (light.CurrentBrightness > 0) {
|
tempSwitch.IsSelected = true;
|
IO.FileUtils.WriteFileByBytes ("Equipment_LightRGB_" + light.SubnetID.ToString () + "_" + light.DeviceID.ToString () + "_" + (light.LoopID < 10 ? "0" + light.LoopID.ToString () : light.LoopID.ToString ()),
|
CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (light)));
|
} else {
|
tempSwitch.IsSelected = false;
|
}
|
light.CurrentBrightness = (byte)tempLightSeekBar.Progress;
|
};
|
|
tempSwitch.MouseUpEventHandler += (sender3, e3) => {
|
tempSwitch.IsSelected = !tempSwitch.IsSelected;
|
if (light.LastOpenBrightness == 0) {
|
light.LastOpenBrightness = 100;
|
}
|
if (tempSwitch.IsSelected) {
|
tempLightSeekBar.Progress = light.LastOpenBrightness;
|
Control.ControlBytesSend (Command.SetLogicLoopColor, light.SubnetID, light.DeviceID, new byte [] { light.LoopID, light.CurrentBrightness, 254, light.CustomDelayTimeOpen,light.CustomDelayTimeClose,
|
3,light.RStatus,light.GStatus,light.BStatus,0,0}, SendCount.Zero);
|
} else {
|
tempLightSeekBar.Progress = 0;
|
}
|
light.CurrentBrightness = (byte)tempLightSeekBar.Progress;
|
Control.ControlBytesSendHasReturn (Command.SetLogicLoopColor, light.SubnetID, light.DeviceID, new byte [] { light.LoopID, light.CurrentBrightness, 254, light.CustomDelayTimeOpen,light.CustomDelayTimeClose,
|
3,light.RStatus,light.GStatus,light.BStatus,0,0});
|
};
|
if (light.CurrentBrightness > 0) {
|
tempSwitch.IsSelected = true;
|
}
|
}
|
}
|
equipmentListScrolView.Height = bodyScrolView.Height;
|
}
|
} else {
|
equipmentListScrolView.Height = 0;
|
//LightCount = 0;
|
}
|
});
|
} catch { } finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
readEnergyThead = new Thread ((obj) => {
|
while (readEnergy) {
|
try {
|
for (int i = 0; i < EnergtLightList.Count; i++) {
|
var c = EnergtLightList [i];
|
Control.ControlBytesSend (Command.ReadAnalogValue, c.SubnetID, c.DeviceID, new byte [] { 10, c.LoopID }, SendCount.Zero);
|
if (c.Type == DeviceType.LightEnergySwitch) {
|
Control.ControlBytesSend (Command.ReadAnalogValue, c.SubnetID, c.DeviceID, new byte [] { 11, c.LoopID }, SendCount.Zero);
|
}
|
}
|
System.Threading.Thread.Sleep (10000);
|
} catch {
|
EnergtLightList = new List<Common> ();
|
}
|
}
|
});
|
if (EnergtLightList.Count > 0) {
|
readEnergyThead.Start ();
|
readEnergy = true;
|
}
|
});
|
}
|
});
|
};
|
btnShowAll.MouseUpEventHandler += eHandler;
|
downSelectedButton.MouseUpEventHandler += eHandler;
|
|
//默认是选中状态
|
if (UserConfig.Instance.ShowRoomLightList)
|
eHandler (btnShowAll, new MouseEventArgs ());
|
|
|
if (LightCount > 0) {
|
btnAllON.MouseUpEventHandler += (sender, e) => {
|
btnAllON.TextColor = SkinStyle.Current.TextColor1;
|
Alert alert = new Alert ("",
|
Language.StringByID (R.MyInternationalizationString.SureOpenAllLight),
|
Language.StringByID (R.MyInternationalizationString.Cancel),
|
Language.StringByID (R.MyInternationalizationString.Confrim));
|
alert.Show ();
|
alert.ResultEventHandler += (sender2, e2) => {
|
if (e2) {
|
controlAllLight (100);
|
}
|
};
|
};
|
btnAllON.MouseDownEventHandler += (sender, e) => {
|
btnAllON.TextColor = SkinStyle.Current.SelectedColor;
|
};
|
btnAllOff.MouseDownEventHandler += (sender, e) => {
|
btnAllOff.TextColor = SkinStyle.Current.SelectedColor;
|
};
|
btnAllOff.MouseUpEventHandler += (sender, e) => {
|
btnAllOff.TextColor = SkinStyle.Current.TextColor1;
|
Alert alert = new Alert ("",
|
Language.StringByID (R.MyInternationalizationString.SureCloseAllLight),
|
Language.StringByID (R.MyInternationalizationString.Cancel),
|
Language.StringByID (R.MyInternationalizationString.Confrim));
|
alert.Show ();
|
alert.ResultEventHandler += (sender2, e2) => {
|
if (e2) {
|
controlAllLight (0);
|
}
|
};
|
};
|
}
|
#endregion
|
|
Console.WriteLine ("L6");
|
}
|
|
static System.Threading.Thread thread;
|
/// <summary>
|
/// 读取设备状态
|
/// </summary>
|
public static void readAllStatus (bool isRead = false)
|
{
|
if (isRead) {
|
foreach (Room room in Room.Lists) {
|
if (room == null) {
|
continue;
|
}
|
var list = room.DeviceList.FindAll ((obj) => {
|
return (obj.Type == DeviceType.LightDimming || obj.Type == DeviceType.LightSwitch || obj.Type == DeviceType.LightLogic || obj.Type == DeviceType.LightEnergySocket || obj.Type == DeviceType.LightEnergySwitch
|
|| obj.Type == DeviceType.LightMixDimming || obj.Type == DeviceType.LightMixSwitch || obj.Type == DeviceType.FanModule);
|
});
|
foreach (Common common in list) {
|
common.LastUpdateTime = DateTime.MinValue;
|
}
|
var listGRB = room.DeviceList.FindAll ((obj) => {
|
return (obj.Type == DeviceType.LightRGB);
|
});
|
foreach (Common common in listGRB) {
|
common.LastUpdateTime = DateTime.MinValue;
|
}
|
}
|
}
|
if (thread != null) {
|
thread.Abort ();
|
}
|
thread = new Thread (() => {
|
try {
|
List<string> readList = new List<string> ();
|
foreach (Room room in Room.Lists) {
|
//if (string.IsNullOrEmpty(room.Name)) {
|
// continue;
|
//}
|
var list = room.DeviceList.FindAll ((obj) => {
|
return obj.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now && (obj.Type == DeviceType.LightDimming || obj.Type == DeviceType.LightSwitch || obj.Type == DeviceType.LightLogic
|
|| obj.Type == DeviceType.LightEnergySwitch || obj.Type == DeviceType.LightEnergySocket || obj.Type == DeviceType.LightMixDimming || obj.Type == DeviceType.LightMixSwitch || obj.Type == DeviceType.FanModule);
|
});
|
foreach (Common common in list) {
|
var s = common.Type + "_" + common.SubnetID + "_" + common.DeviceID;
|
//已经读取过当前设备就不再读取
|
if (readList.Contains (s)) {
|
continue;
|
}
|
readList.Add (s);
|
Thread.Sleep (500);
|
Control.ControlBytesSendHasReturn (Command.ReadLightEquipmentAllLoopBrightness, common.SubnetID, common.DeviceID, new byte [] { });
|
}
|
var listGRB = room.DeviceList.FindAll ((obj) => {
|
return obj.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now && (obj.Type == DeviceType.LightRGB);
|
});
|
foreach (Common common in listGRB) {
|
var s = common.Type + "_" + common.SubnetID + "_" + common.DeviceID;
|
//已经读取过当前设备就不再读取
|
if (readList.Contains (s)) {
|
continue;
|
}
|
readList.Add (s);
|
Thread.Sleep (500);
|
Control.ControlBytesSendHasReturn (Command.ReadLogicLoopColor, common.SubnetID, common.DeviceID, new byte [] { common.LoopID });
|
}
|
}
|
} catch { } finally {
|
thread = null;
|
}
|
});
|
thread.Start ();
|
}
|
}
|
}
|