[NF] Sensor hinzugefügt

This commit is contained in:
BlubbFish 2017-08-07 22:15:39 +00:00
parent c634625f0e
commit 452db11a92
5 changed files with 84 additions and 18 deletions

View File

@ -23,12 +23,16 @@
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary> /// </summary>
private void InitializeComponent() { private void InitializeComponent() {
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
this.panel1 = new System.Windows.Forms.Panel();
this.flowLayoutPanel2 = new System.Windows.Forms.FlowLayoutPanel();
((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
this.panel1.SuspendLayout();
this.flowLayoutPanel2.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// statusStrip1 // statusStrip1
@ -41,31 +45,49 @@
// //
// chart1 // chart1
// //
chartArea1.Name = "ChartArea1"; chartArea2.Name = "ChartArea1";
this.chart1.ChartAreas.Add(chartArea1); this.chart1.ChartAreas.Add(chartArea2);
legend1.Name = "Legend1"; legend2.Name = "Legend1";
this.chart1.Legends.Add(legend1); this.chart1.Legends.Add(legend2);
this.chart1.Location = new System.Drawing.Point(62, 21); this.chart1.Location = new System.Drawing.Point(3, 3);
this.chart1.Name = "chart1"; this.chart1.Name = "chart1";
series1.ChartArea = "ChartArea1"; series2.ChartArea = "ChartArea1";
series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
series1.Legend = "Legend1"; series2.Legend = "Legend1";
series1.Name = "Series1"; series2.Name = "Series1";
this.chart1.Series.Add(series1); this.chart1.Series.Add(series2);
this.chart1.Size = new System.Drawing.Size(324, 166); this.chart1.Size = new System.Drawing.Size(183, 136);
this.chart1.TabIndex = 1; this.chart1.TabIndex = 1;
this.chart1.Text = "chart1"; this.chart1.Text = "chart1";
// //
// panel1
//
this.panel1.Controls.Add(this.chart1);
this.panel1.Location = new System.Drawing.Point(3, 3);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(201, 155);
this.panel1.TabIndex = 2;
//
// flowLayoutPanel2
//
this.flowLayoutPanel2.Controls.Add(this.panel1);
this.flowLayoutPanel2.Location = new System.Drawing.Point(12, 12);
this.flowLayoutPanel2.Name = "flowLayoutPanel2";
this.flowLayoutPanel2.Size = new System.Drawing.Size(819, 289);
this.flowLayoutPanel2.TabIndex = 3;
//
// Dashboard // Dashboard
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(843, 326); this.ClientSize = new System.Drawing.Size(843, 326);
this.Controls.Add(this.chart1); this.Controls.Add(this.flowLayoutPanel2);
this.Controls.Add(this.statusStrip1); this.Controls.Add(this.statusStrip1);
this.Name = "Dashboard"; this.Name = "Dashboard";
this.Text = "Dashboard"; this.Text = "Dashboard";
((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();
this.panel1.ResumeLayout(false);
this.flowLayoutPanel2.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@ -75,6 +97,8 @@
private System.Windows.Forms.StatusStrip statusStrip1; private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.DataVisualization.Charting.Chart chart1; private System.Windows.Forms.DataVisualization.Charting.Chart chart1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel2;
} }
} }

View File

@ -8,14 +8,21 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Dashboard.Connector; using Dashboard.Connector;
using Dashboard.Sensor;
using Dashboard.Tracings;
namespace Dashboard { namespace Dashboard {
public partial class Dashboard : Form { public partial class Dashboard : Form {
public Dashboard() { public Dashboard() {
InitializeComponent(); InitializeComponent();
Mqtt.Instance.Connect(); Mqtt.Instance.Connect();
ATracings g = new Graph();
ASensor s = new Power();
s.SetMqttTopic("zway/wohnzimmer/thinkpad/power");
Mqtt.Instance.MessageIncomming += s.IncommingMqttMessage;
g.SetSensor(s);
this.flowLayoutPanel2.Controls.Add(g.GetTracing());
this.chart1.ChartAreas[0].AxisX.Maximum = 100; this.chart1.ChartAreas[0].AxisX.Maximum = 100;
Mqtt.Instance.MessageIncomming += this.Instance_MessageIncomming;
} }
private void Instance_MessageIncomming(Object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e) { private void Instance_MessageIncomming(Object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e) {

View File

@ -0,0 +1,18 @@
using System;
using uPLibrary.Networking.M2Mqtt.Messages;
namespace Dashboard.Sensor {
public abstract class ASensor {
private String topic;
public void SetMqttTopic(String topic) {
this.topic = topic;
}
public delegate void UpdatedValue(Object sender, EventArgs e);
public event UpdatedValue Update;
internal abstract void IncommingMqttMessage(Object sender, MqttMsgPublishEventArgs e);
public abstract Int32 GetInt();
public abstract Single GetFloat();
public abstract Boolean GetBool();
}
}

View File

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dashboard.Sensor {
class Power : ASensor {
}
}

View File

@ -1,10 +1,17 @@
using System; using System;
using System.Windows.Forms;
using Dashboard.Sensor;
namespace Dashboard.Tracings { namespace Dashboard.Tracings {
public abstract class ATracings { public abstract class ATracings {
private ASensor sensor;
public abstract Int32 ElementWidth { get; } public abstract Int32 ElementWidth { get; }
public abstract Int32 ElementHeight { get; } public abstract Int32 ElementHeight { get; }
public void SetSensor(ASensor sensor) {
public abstract void SetSensor(ASensor s); this.sensor = sensor;
this.sensor.Update += this.SensorUpdate;
}
protected abstract void SensorUpdate(Object sender, EventArgs e);
public abstract Panel GetTracing();
} }
} }