Mqtt-Dashboard/Mqtt-Dashboard/Tracings/PowerMeter.cs
BlubbFish d21ded9f33 [NF] First Release
[NF] Finish Switcher
2017-08-12 12:04:24 +00:00

45 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Dashboard.Sensor;
namespace Dashboard.Tracings {
class PowerMeter : Meter {
public PowerMeter(ASensor sensor, Dictionary<String, String> settings) : base(sensor, settings) {
}
protected override void SensorUpdate(Object sender, EventArgs e) {
String value = "";
switch (this.sensor.Datatypes) {
case ASensor.Types.Bool:
this.DisplayAverage.Enqueue((this.sensor.GetBool) ? 1 : 0);
value = this.sensor.GetBool.ToString(new CultureInfo("de-DE"));
break;
case ASensor.Types.Int:
this.DisplayAverage.Enqueue(this.sensor.GetInt);
value = this.sensor.GetInt.ToString();
break;
case ASensor.Types.Float:
this.DisplayAverage.Enqueue(this.sensor.GetFloat);
value = this.sensor.GetFloat.ToString(new CultureInfo("de-DE"));
break;
}
if (this.DisplayAverage.Count > this.DisplayItems) {
this.DisplayAverage.Dequeue();
}
Single average = this.DisplayAverage.Sum() / this.DisplayAverage.Count();
try {
this.label1.BeginInvoke((MethodInvoker)delegate {
this.label1.Text = value + " W";
});
this.label2.BeginInvoke((MethodInvoker)delegate {
this.label2.Text = "Durchschnitt: " + Math.Round(average, 2) + " W";
});
} catch (Exception) { }
}
}
}