From 452db11a929d0e114e10618842e82095add75e7a Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Mon, 7 Aug 2017 22:15:39 +0000 Subject: [PATCH] =?UTF-8?q?[NF]=20Sensor=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mqtt-Dashboard/Form1.Designer.cs | 54 ++++++++++++++++++++-------- Mqtt-Dashboard/Form1.cs | 9 ++++- Mqtt-Dashboard/Sensor/ASensor.cs | 18 ++++++++++ Mqtt-Dashboard/Sensor/Power.cs | 10 ++++++ Mqtt-Dashboard/Tracings/ATracings.cs | 11 ++++-- 5 files changed, 84 insertions(+), 18 deletions(-) create mode 100644 Mqtt-Dashboard/Sensor/ASensor.cs create mode 100644 Mqtt-Dashboard/Sensor/Power.cs diff --git a/Mqtt-Dashboard/Form1.Designer.cs b/Mqtt-Dashboard/Form1.Designer.cs index 52832df..2aa85a4 100644 --- a/Mqtt-Dashboard/Form1.Designer.cs +++ b/Mqtt-Dashboard/Form1.Designer.cs @@ -23,12 +23,16 @@ /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. /// private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = 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.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); 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(); + this.panel1.SuspendLayout(); + this.flowLayoutPanel2.SuspendLayout(); this.SuspendLayout(); // // statusStrip1 @@ -41,31 +45,49 @@ // // chart1 // - chartArea1.Name = "ChartArea1"; - this.chart1.ChartAreas.Add(chartArea1); - legend1.Name = "Legend1"; - this.chart1.Legends.Add(legend1); - this.chart1.Location = new System.Drawing.Point(62, 21); + chartArea2.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea2); + legend2.Name = "Legend1"; + this.chart1.Legends.Add(legend2); + this.chart1.Location = new System.Drawing.Point(3, 3); this.chart1.Name = "chart1"; - series1.ChartArea = "ChartArea1"; - series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series1.Legend = "Legend1"; - series1.Name = "Series1"; - this.chart1.Series.Add(series1); - this.chart1.Size = new System.Drawing.Size(324, 166); + series2.ChartArea = "ChartArea1"; + series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series2.Legend = "Legend1"; + series2.Name = "Series1"; + this.chart1.Series.Add(series2); + this.chart1.Size = new System.Drawing.Size(183, 136); this.chart1.TabIndex = 1; 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 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(843, 326); - this.Controls.Add(this.chart1); + this.Controls.Add(this.flowLayoutPanel2); this.Controls.Add(this.statusStrip1); this.Name = "Dashboard"; this.Text = "Dashboard"; ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); + this.panel1.ResumeLayout(false); + this.flowLayoutPanel2.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -75,6 +97,8 @@ private System.Windows.Forms.StatusStrip statusStrip1; private System.Windows.Forms.DataVisualization.Charting.Chart chart1; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel2; } } diff --git a/Mqtt-Dashboard/Form1.cs b/Mqtt-Dashboard/Form1.cs index b38465d..34e9031 100644 --- a/Mqtt-Dashboard/Form1.cs +++ b/Mqtt-Dashboard/Form1.cs @@ -8,14 +8,21 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Dashboard.Connector; +using Dashboard.Sensor; +using Dashboard.Tracings; namespace Dashboard { public partial class Dashboard : Form { public Dashboard() { InitializeComponent(); 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; - Mqtt.Instance.MessageIncomming += this.Instance_MessageIncomming; } private void Instance_MessageIncomming(Object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e) { diff --git a/Mqtt-Dashboard/Sensor/ASensor.cs b/Mqtt-Dashboard/Sensor/ASensor.cs new file mode 100644 index 0000000..36e5543 --- /dev/null +++ b/Mqtt-Dashboard/Sensor/ASensor.cs @@ -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(); + } +} \ No newline at end of file diff --git a/Mqtt-Dashboard/Sensor/Power.cs b/Mqtt-Dashboard/Sensor/Power.cs new file mode 100644 index 0000000..6c53e81 --- /dev/null +++ b/Mqtt-Dashboard/Sensor/Power.cs @@ -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 { + } +} diff --git a/Mqtt-Dashboard/Tracings/ATracings.cs b/Mqtt-Dashboard/Tracings/ATracings.cs index ca62c88..e427f3c 100644 --- a/Mqtt-Dashboard/Tracings/ATracings.cs +++ b/Mqtt-Dashboard/Tracings/ATracings.cs @@ -1,10 +1,17 @@ using System; +using System.Windows.Forms; +using Dashboard.Sensor; namespace Dashboard.Tracings { public abstract class ATracings { + private ASensor sensor; public abstract Int32 ElementWidth { get; } public abstract Int32 ElementHeight { get; } - - public abstract void SetSensor(ASensor s); + public void SetSensor(ASensor sensor) { + this.sensor = sensor; + this.sensor.Update += this.SensorUpdate; + } + protected abstract void SensorUpdate(Object sender, EventArgs e); + public abstract Panel GetTracing(); } } \ No newline at end of file