[BF] Versuche Fehler zu finden, welcher verhindert das Anwendung geschlossen werden kann
This commit is contained in:
parent
8e9e49e685
commit
241b0ca00a
@ -10,19 +10,25 @@ using System.Threading;
|
||||
|
||||
namespace Dashboard {
|
||||
public partial class Dashboard : Form {
|
||||
private Dictionary<String, ASensor> sensors = new Dictionary<string, ASensor>();
|
||||
private Dictionary<String, ASensor> sensors = new Dictionary<String, ASensor>();
|
||||
private Thread updateThread;
|
||||
|
||||
public Dashboard() {
|
||||
InitializeComponent();
|
||||
Mqtt.Instance.Connect();
|
||||
|
||||
this.generateSensors();
|
||||
this.generateForms();
|
||||
this.GenerateSensors();
|
||||
this.GenerateForms();
|
||||
|
||||
this.updateThread = new Thread(this.SensorPolling);
|
||||
this.updateThread.Start();
|
||||
|
||||
this.FormClosed += this.Dashboard_FormClosed;
|
||||
|
||||
Mqtt.Instance.MessageIncomming += this.Instance_MessageIncomming;
|
||||
Thread a = new Thread(this.SensorPolling);
|
||||
a.Start();
|
||||
}
|
||||
private void generateSensors() {
|
||||
|
||||
private void GenerateSensors() {
|
||||
InIReader ini = InIReader.GetInstance("sensor.ini");
|
||||
List<String> sensorini = ini.GetSections();
|
||||
foreach(String sensor in sensorini) {
|
||||
@ -35,7 +41,7 @@ namespace Dashboard {
|
||||
this.sensors.Add(sensor.ToLower().Substring(1, sensor.Length - 2), s);
|
||||
}
|
||||
}
|
||||
private void generateForms() {
|
||||
private void GenerateForms() {
|
||||
InIReader ini = InIReader.GetInstance("tracings.ini");
|
||||
List<String> tracingini = ini.GetSections();
|
||||
foreach(String tracing in tracingini) {
|
||||
@ -51,11 +57,24 @@ namespace Dashboard {
|
||||
private void SensorPolling() {
|
||||
while(true) {
|
||||
Thread.Sleep(1000);
|
||||
foreach(KeyValuePair<String, ASensor> sensor in sensors) {
|
||||
foreach(KeyValuePair<String, ASensor> sensor in this.sensors) {
|
||||
sensor.Value.Poll();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Dashboard_FormClosed(Object sender, FormClosedEventArgs e) {
|
||||
this.Dispose();
|
||||
}
|
||||
private new void Dispose() {
|
||||
this.updateThread.Abort();
|
||||
while (this.updateThread.ThreadState != ThreadState.Aborted) { }
|
||||
foreach (String item in this.sensors.Keys) {
|
||||
this.sensors[item] = null;
|
||||
}
|
||||
this.sensors.Clear();
|
||||
Mqtt.Instance.MessageIncomming -= this.Instance_MessageIncomming;
|
||||
this.Dispose(true);
|
||||
}
|
||||
private void Instance_MessageIncomming(Object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e) {
|
||||
System.Diagnostics.Debug.WriteLine("Received = " + Encoding.UTF8.GetString(e.Message) + " on topic " + e.Topic+" at "+DateTime.Now.ToUniversalTime());
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Dashboard.Sensor {
|
||||
public abstract class ASensor {
|
||||
public abstract class ASensor : IDisposable {
|
||||
private String topic;
|
||||
private Int32 pollcount;
|
||||
private Dictionary<String, String> settings;
|
||||
@ -38,12 +38,21 @@ namespace Dashboard.Sensor {
|
||||
public Boolean GetBool { get; protected set; }
|
||||
public Types Datatypes { get; protected set; }
|
||||
public DateTime Timestamp { get; protected set; }
|
||||
public int Polling { get; private set; }
|
||||
public Int32 Polling { get; private set; }
|
||||
public void Poll() {
|
||||
if(this.pollcount++ >= Polling) {
|
||||
if(this.pollcount++ >= this.Polling) {
|
||||
this.pollcount = 1;
|
||||
Mqtt.Instance.Send(this.topic + "/status","");
|
||||
}
|
||||
}
|
||||
protected virtual void Dispose(Boolean disposing) {
|
||||
if (disposing) {
|
||||
Mqtt.Instance.MessageIncomming -= this.IncommingMqttMessage;
|
||||
}
|
||||
}
|
||||
public void Dispose() {
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ namespace Dashboard.Sensor {
|
||||
this.GetInt = 0;
|
||||
this.Datatypes = Types.Float;
|
||||
}
|
||||
|
||||
protected override void UpdateValue(MqttMsgPublishEventArgs e) {
|
||||
this.GetFloat = Single.Parse(Encoding.UTF8.GetString(e.Message), new CultureInfo("en-US"));
|
||||
}
|
||||
|
@ -5,11 +5,18 @@ using System.Windows.Forms.DataVisualization.Charting;
|
||||
using Dashboard.Sensor;
|
||||
|
||||
namespace Dashboard.Tracings {
|
||||
class Graph : ATracings {
|
||||
class Graph : ATracings, IDisposable {
|
||||
private Series series;
|
||||
private Chart chart;
|
||||
|
||||
public Graph(ASensor sensor, Dictionary<String, String> settings) : base(sensor, settings) { }
|
||||
|
||||
public void Dispose() {
|
||||
this.chart.Series.Clear();
|
||||
this.series = null;
|
||||
this.chart.Dispose();
|
||||
}
|
||||
|
||||
public override Panel GetPanel() {
|
||||
Panel panel = new Panel();
|
||||
|
||||
@ -52,17 +59,19 @@ namespace Dashboard.Tracings {
|
||||
return panel;
|
||||
}
|
||||
protected override void SensorUpdate(Object sender, EventArgs e) {
|
||||
this.chart.BeginInvoke((MethodInvoker)delegate {
|
||||
if (this.sensor.Datatypes == ASensor.Types.Bool) {
|
||||
this.series.Points.AddXY(this.sensor.Timestamp, (this.sensor.GetBool) ? 1 : 0);
|
||||
}
|
||||
if (this.sensor.Datatypes == ASensor.Types.Int) {
|
||||
this.series.Points.AddXY(this.sensor.Timestamp, this.sensor.GetInt);
|
||||
}
|
||||
if (this.sensor.Datatypes == ASensor.Types.Float) {
|
||||
this.series.Points.AddXY(this.sensor.Timestamp, this.sensor.GetFloat);
|
||||
}
|
||||
});
|
||||
if (this.series != null) {
|
||||
this.chart.BeginInvoke((MethodInvoker)delegate {
|
||||
if (this.sensor.Datatypes == ASensor.Types.Bool) {
|
||||
this.series.Points.AddXY(this.sensor.Timestamp, (this.sensor.GetBool) ? 1 : 0);
|
||||
}
|
||||
if (this.sensor.Datatypes == ASensor.Types.Int) {
|
||||
this.series.Points.AddXY(this.sensor.Timestamp, this.sensor.GetInt);
|
||||
}
|
||||
if (this.sensor.Datatypes == ASensor.Types.Float) {
|
||||
this.series.Points.AddXY(this.sensor.Timestamp, this.sensor.GetFloat);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,14 @@
|
||||
[Ventilator]
|
||||
topic=zway/power/test/wVentilator
|
||||
[Thinkpad]
|
||||
topic=zway/wohnzimmer/thinkpad/power
|
||||
type=Power
|
||||
polling=10
|
||||
|
||||
;zway/wohnzimmer/thinkpad/power
|
||||
;zway/wohnzimmer/tV/power
|
||||
;zway/küche/kuehlschrank/power
|
||||
;[Tv]
|
||||
;topic=zway/wohnzimmer/tV/power
|
||||
;type=Power
|
||||
;polling=10
|
||||
|
||||
;[Kühlschrank]
|
||||
;topic=zway/küche/kuehlschrank/power
|
||||
;type=Power
|
||||
;polling=10
|
@ -1,3 +1,11 @@
|
||||
[VentilatorGraph]
|
||||
sensor=Ventilator
|
||||
type=Graph
|
||||
;[ThinkpadGraph]
|
||||
;sensor=Thinkpad
|
||||
;type=Graph
|
||||
|
||||
;[TvGraph]
|
||||
;sensor=Tv
|
||||
;type=Graph
|
||||
|
||||
;[KühlschrankGraph]
|
||||
;sensor=Kühlschrank
|
||||
;type=Graph
|
Loading…
Reference in New Issue
Block a user