using System;
|
using System.Collections.Generic;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public class SystemSensor : FrameLayout
|
{
|
void ReadStatus (Sensor sensor, Button btnContent)
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
var bytes = Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, sensor.SubnetID, sensor.DeviceID, new byte [] { sensor.BigClass,sensor.MinClass,sensor.LoopID });
|
Application.RunOnMainThread (() => {
|
switch (sensor.Type) {
|
case DeviceType.SensorLPG:
|
SensorLPG sensorLPG = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorLPG> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorLPG.CurrentLPG.ToString () + " ppm";
|
break;
|
case DeviceType.SensorCH4:
|
SensorCH4 sensorCH4 = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorCH4> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorCH4.CurrentCH4.ToString () + " ppm";
|
break;
|
case DeviceType.SensorCOH2:
|
SensorCOH2 sensorCOH2 = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorCOH2> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorCOH2.CurrentCOH2.ToString () + " ppm";
|
break;
|
case DeviceType.SensorSmoke:
|
SensorSmoke sensorSmoke = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorSmoke> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.TextID = sensorSmoke.CurrentStatus == 0 ? R.MyInternationalizationString.Close : R.MyInternationalizationString.Open;
|
break;
|
case DeviceType.SensorMobileDetection:
|
SensorMobileDetection sensorMobileDetection = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorMobileDetection> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.TextID = sensorMobileDetection.Status == 0 ? R.MyInternationalizationString.Close : R.MyInternationalizationString.Open;
|
break;
|
case DeviceType.SensorTemperature:
|
SensorTemperature sensorTemperature = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorTemperature> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorTemperature.CurrentTemperature.ToString () + " °";
|
break;
|
case DeviceType.SensorHumidity:
|
SensorHumidity sensorHumidity = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorHumidity> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorHumidity.CurrentHumidity.ToString () + " %";
|
break;
|
case DeviceType.SensorIllumination:
|
SensorIllumination sensorIllumination = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorIllumination> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorIllumination.CurrentIllumination.ToString () + " %";
|
break;
|
case DeviceType.SensorTVOC:
|
SensorTVOC SensorTVOC = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorTVOC> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = SensorTVOC.CurrentTVOC.ToString () + " mg/m3";
|
break;
|
case DeviceType.SensorPM25:
|
SensorPM25 sensorPM25 = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorPM25> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorPM25.CurrentPM25.ToString ();
|
break;
|
case DeviceType.SensorCO2:
|
SensorCO2 sensorCO2 = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorCO2> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorCO2.CurrentCO2.ToString () + " ppm";
|
break;
|
case DeviceType.SensorWindSpeed:
|
SensorWindSpeed sensorWindSpeed = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorWindSpeed> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorWindSpeed.CurrentWindSpeed.ToString ();
|
break;
|
case DeviceType.SensorWindPressure:
|
SensorWindPressure sensorWindPressure = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorWindPressure> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorWindPressure.CurrentWindPressure.ToString ();
|
break;
|
case DeviceType.SensorLiquidFlow:
|
SensorLiquidFlow sensorLiquidFlow = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorLiquidFlow> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorLiquidFlow.CurrentLiquidFlow.ToString ();
|
break;
|
case DeviceType.SensorLiquidPressure:
|
SensorLiquidPressure sensorLiquidPressure = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorLiquidPressure> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorLiquidPressure.CurrentLiquidPressure.ToString ();
|
break;
|
case DeviceType.SensorLiquidDepth:
|
SensorLiquidDepth sensorLiquidDepth = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorLiquidDepth> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorLiquidDepth.CurrentLiquidDepth.ToString ();
|
break;
|
case DeviceType.SensorRainfall:
|
SensorRainfall sensorRainfall = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorRainfall> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorRainfall.CurrentRainfall.ToString ();
|
break;
|
case DeviceType.SensorWeight:
|
SensorWeight sensorWeight = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorWeight> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorWeight.CurrentWeight.ToString () + " KG";
|
break;
|
case DeviceType.SensorHeightLength:
|
SensorHeightLength sensorHeightLength = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorHeightLength> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorHeightLength.CurrentHeightLength.ToString () + " mm";
|
break;
|
case DeviceType.SensorVelocity:
|
SensorVelocity sensorVelocity = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorVelocity> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorVelocity.CurrentVelocity.ToString () + " m/s";
|
break;
|
case DeviceType.SensorVibration:
|
SensorVibration sensorVibration = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorVibration> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.TextID = sensorVibration.CurrentVibration == 0 ? R.MyInternationalizationString.Close : R.MyInternationalizationString.Open;
|
break;
|
case DeviceType.SensorVoltage:
|
SensorVoltage sensorVoltage = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorVoltage> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorVoltage.CurrentVoltage.ToString () + " V";
|
break;
|
case DeviceType.SensorCurrent:
|
SensorCurrent sensorCurrent = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorCurrent> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorCurrent.CurrentCurrent.ToString () + " A";
|
break;
|
case DeviceType.SensorPower:
|
SensorPower sensorPower = Newtonsoft.Json.JsonConvert.DeserializeObject<SensorPower> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (sensor.SavePath)));
|
btnContent.Text = sensorPower.CurrentPower.ToString () + " W";
|
break;
|
}
|
});
|
});
|
}
|
|
|
public void SystemSensorShow (Sensor sensor, Common common)
|
{
|
byte [] lightDimmingBytes = new byte [26];
|
#region top
|
RowLayout topTitleView = new RowLayout () {
|
Height = Application.GetRealHeight (100),
|
BackgroundColor = SkinStyle.Current.MainColor
|
};
|
AddChidren (topTitleView);
|
Button backButton = new Button () {
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (85),
|
UnSelectedImagePath = "Item/Back.png",
|
SelectedImagePath = "Item/BackSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
backButton.MouseUpEventHandler += (sender, e) => {
|
(Parent as PageLayout).PageIndex -= 1;
|
//SystemEquipmentBase.RefreshView (common);
|
};
|
topTitleView.AddChidren (backButton);
|
|
EditText textButton = new EditText () {
|
X = Application.GetRealWidth (30) + backButton.Right,
|
Height = Application.GetRealHeight (50),
|
Width = Application.GetRealWidth (400),
|
Text = sensor.Name,
|
TextAlignment = TextAlignment.CenterLeft,
|
Gravity = Gravity.CenterVertical,
|
BackgroundColor = SkinStyle.Current.Transparent,
|
SelectedBackgroundColor = SkinStyle.Current.SubtitleView,
|
Enable = false,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
topTitleView.AddChidren (textButton);
|
|
Button editor = new Button () {
|
X = Application.GetRealWidth (520),
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (70),
|
UnSelectedImagePath = "Item/Editor.png",
|
SelectedImagePath = "Item/EditorSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
topTitleView.AddChidren (editor);
|
EventHandler<MouseEventArgs> eHandler = new EventHandler<MouseEventArgs> ((sender, e) => {
|
if (editor.IsSelected) {
|
MainPage.Loading.Start ();
|
byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (textButton.Text.Trim ());
|
textButton.IsSelected = editor.IsSelected = textButton.Enable = false;
|
System.Threading.Tasks.Task.Run (() => {
|
byte [] updateBytes = Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, sensor.SubnetID, sensor.DeviceID, new byte [] {
|
sensor.BigClass,sensor.MinClass,sensor.LoopID
|
});
|
if (updateBytes == null) {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
return;
|
}
|
byte [] uBytes = new byte [20];
|
Array.Copy (remakeBytes, 0, uBytes, 0, remakeBytes.Length < 20 ? remakeBytes.Length : 20);
|
Array.Copy (uBytes, 0, updateBytes, 3, 20 < uBytes.Length ? 20 : uBytes.Length);
|
var reBytes = Control.ControlBytesSendHasReturn (Command.SetDeviceLoopInfo, sensor.SubnetID, sensor.DeviceID, updateBytes);
|
if (reBytes != null) {
|
Application.RunOnMainThread (() => {
|
sensor.Name = textButton.Text.Trim ();
|
IO.FileUtils.SaveEquipmentMessage (sensor, sensor.LoopID.ToString ());
|
MainPage.Loading.Hide ();
|
});
|
} else {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
} else {
|
textButton.Enable = textButton.IsSelected = editor.IsSelected = true;
|
}
|
});
|
editor.MouseUpEventHandler += eHandler;
|
#endregion
|
|
#region MyRegion
|
FrameLayout frameLayoutBody = new FrameLayout () {
|
Y = Application.GetRealHeight (100),
|
Height = Application.GetRealHeight (700),
|
};
|
AddChidren (frameLayoutBody);
|
|
FrameLayout ContentView = new FrameLayout (){
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight(80),
|
Width = Application.GetMinRealAverage (300),
|
Height = Application.GetMinRealAverage(200),
|
BorderWidth = (uint)Application.GetMinRealAverage(3),
|
BorderColor = SkinStyle.Current.TextColor1,
|
Radius = (uint)Application.GetMinRealAverage(100),
|
};
|
frameLayoutBody.AddChidren (ContentView);
|
|
Button btnTitle = new Button () {
|
Y = Application.GetMinRealAverage (20),
|
Width = Application.GetMinRealAverage(300),
|
Height = Application.GetMinRealAverage(80),
|
TextAlignment = TextAlignment.Center,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
ContentView.AddChidren (btnTitle);
|
|
Button btnContent = new Button () {
|
Y = btnTitle.Bottom,
|
Width = Application.GetMinRealAverage(300),
|
Height = Application.GetMinRealAverage(80),
|
TextAlignment = TextAlignment.Center,
|
TextColor = SkinStyle.Current.TextColor1,
|
Text = "--"
|
};
|
ContentView.AddChidren (btnContent);
|
|
switch (sensor.Type) {
|
case DeviceType.SensorLPG:
|
btnTitle.TextID = R.MyInternationalizationString.SensorLPG;
|
break;
|
case DeviceType.SensorCH4:
|
btnTitle.TextID = R.MyInternationalizationString.SensorCH4;
|
break;
|
case DeviceType.SensorCOH2:
|
btnTitle.TextID = R.MyInternationalizationString.SensorCOH2;
|
break;
|
case DeviceType.SensorSmoke:
|
btnTitle.TextID = R.MyInternationalizationString.SensorSmoke;
|
break;
|
case DeviceType.SensorMobileDetection:
|
btnTitle.TextID = R.MyInternationalizationString.SensorMobileDetection;
|
break;
|
case DeviceType.SensorTemperature:
|
btnTitle.TextID = R.MyInternationalizationString.SensorTemperature;
|
break;
|
case DeviceType.SensorHumidity:
|
btnTitle.TextID = R.MyInternationalizationString.SensorHumidity;
|
break;
|
case DeviceType.SensorIllumination:
|
btnTitle.TextID = R.MyInternationalizationString.SensorIllumination;
|
break;
|
case DeviceType.SensorTVOC:
|
btnTitle.TextID = R.MyInternationalizationString.SensorTVOC;
|
break;
|
case DeviceType.SensorPM25:
|
btnTitle.TextID = R.MyInternationalizationString.SensorPM25;
|
break;
|
case DeviceType.SensorCO2:
|
btnTitle.TextID = R.MyInternationalizationString.SensorCO2;
|
break;
|
case DeviceType.SensorWindSpeed:
|
btnTitle.TextID = R.MyInternationalizationString.SensorWindSpeed;
|
break;
|
case DeviceType.SensorWindPressure:
|
btnTitle.TextID = R.MyInternationalizationString.SensorWindPressure;
|
break;
|
case DeviceType.SensorLiquidFlow:
|
btnTitle.TextID = R.MyInternationalizationString.SensorLiquidFlow;
|
break;
|
case DeviceType.SensorLiquidPressure:
|
btnTitle.TextID = R.MyInternationalizationString.SensorLiquidPressure;
|
break;
|
case DeviceType.SensorLiquidDepth:
|
btnTitle.TextID = R.MyInternationalizationString.SensorLiquidDepth;
|
break;
|
case DeviceType.SensorRainfall:
|
btnTitle.TextID = R.MyInternationalizationString.SensorRainfall;
|
break;
|
case DeviceType.SensorWeight:
|
btnTitle.TextID = R.MyInternationalizationString.SensorWeight;
|
break;
|
case DeviceType.SensorHeightLength:
|
btnTitle.TextID = R.MyInternationalizationString.SensorHeightLength;
|
break;
|
case DeviceType.SensorVelocity:
|
btnTitle.TextID = R.MyInternationalizationString.SensorVelocity;
|
break;
|
case DeviceType.SensorVibration:
|
btnTitle.TextID = R.MyInternationalizationString.SensorVibration;
|
break;
|
case DeviceType.SensorVoltage:
|
btnTitle.TextID = R.MyInternationalizationString.SensorVoltage;
|
break;
|
case DeviceType.SensorCurrent:
|
btnTitle.TextID = R.MyInternationalizationString.SensorCurrent;
|
break;
|
case DeviceType.SensorPower:
|
btnTitle.TextID = R.MyInternationalizationString.SensorPower;
|
break;
|
}
|
|
#endregion
|
|
ReadStatus (sensor, btnContent);
|
|
//SystemMiddle.hideBottom ();
|
}
|
|
}
|
}
|