From 338296206c189b606434c52a1cc81fe5d02a6bd2 Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Thu, 6 Sep 2018 20:21:09 +0000 Subject: [PATCH] Some new Features --- House-Dashboard.sln | 12 ++ House-Dashboard/Functions/Tabs.cs | 13 +- House-Dashboard/Functions/Workload.cs | 7 +- House-Dashboard/Graphics/AGraphics.cs | 11 +- House-Dashboard/Graphics/Heater.cs | 190 ++++++++++++++++++++++--- House-Dashboard/House-Dashboard.csproj | 8 +- House-Dashboard/MainWindow.xaml | 58 ++++++-- House-Dashboard/MainWindow.xaml.cs | 9 +- House-Dashboard/packages.config | 4 - 9 files changed, 258 insertions(+), 54 deletions(-) delete mode 100644 House-Dashboard/packages.config diff --git a/House-Dashboard.sln b/House-Dashboard.sln index b3646fc..9c8e8bc 100644 --- a/House-Dashboard.sln +++ b/House-Dashboard.sln @@ -11,6 +11,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMqtt", "..\Uti EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "..\Utils\Utils\Utils.csproj", "{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "litjson_4.7.1", "..\Librarys\litjson\litjson\litjson_4.7.1.csproj", "{91A14CD2-2940-4500-8193-56D37EDDDBAA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "M2Mqtt_4.7.1", "..\Librarys\mqtt\M2Mqtt\M2Mqtt_4.7.1.csproj", "{A11AEF5A-B246-4FE8-8330-06DB73CC8074}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +37,14 @@ Global {FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Any CPU.Build.0 = Debug|Any CPU {FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.ActiveCfg = Release|Any CPU {FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.Build.0 = Release|Any CPU + {91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.Build.0 = Release|Any CPU + {A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/House-Dashboard/Functions/Tabs.cs b/House-Dashboard/Functions/Tabs.cs index b1e523a..63c1542 100644 --- a/House-Dashboard/Functions/Tabs.cs +++ b/House-Dashboard/Functions/Tabs.cs @@ -1,5 +1,6 @@ using System; using System.Net.Cache; +using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Imaging; @@ -9,16 +10,18 @@ using BlubbFish.Utils.IoT.Connector; namespace BlubbFish.House.Dashboard.Functions { class Tabs { - private InIReader ini; - private ADataBackend data; + private readonly InIReader ini; + private readonly ABackend data; + private UIElement window; private TabItem tab; - public Tabs(InIReader settings, ADataBackend data) { + public Tabs(InIReader settings, ABackend data) { this.ini = settings; this.data = data; } - internal TabItem GetTab() { + internal TabItem GetTab(UIElement window) { + this.window = window; this.tab = new TabItem(); this.GenerateHeader(); this.GenerateContent(); @@ -45,7 +48,7 @@ namespace BlubbFish.House.Dashboard.Functions { } foreach (String item in this.ini.GetSections(false)) { if(item != "general") { - AGraphics a = AGraphics.GetInstance(this.ini.GetSection(item), this.data); + AGraphics a = AGraphics.GetInstance(this.ini.GetSection(item), this.data, this.window); if (a != null) { g.Children.Add(a.Draw()); } diff --git a/House-Dashboard/Functions/Workload.cs b/House-Dashboard/Functions/Workload.cs index 22b1aa5..2db3bb7 100644 --- a/House-Dashboard/Functions/Workload.cs +++ b/House-Dashboard/Functions/Workload.cs @@ -4,10 +4,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using BlubbFish.Utils.IoT.Connector; +using BlubbFish.Utils.IoT.Events; namespace BlubbFish.House.Dashboard.Functions { class Workload { - private SortedDictionary list = new SortedDictionary(); + private SortedDictionary list = new SortedDictionary(); public delegate void WorkloadEvent(Object sender, EventArgs e); public event WorkloadEvent Update; @@ -15,7 +16,7 @@ namespace BlubbFish.House.Dashboard.Functions { public Int32 Maximum { get; private set; } public Int32 Now { get; private set; } - internal void SetMessage(MqttEventArgs e) { + internal void SetMessage(BackendEvent e) { DateTime d = DateTime.Now; if (this.list.ContainsKey(d)) { return; @@ -23,7 +24,7 @@ namespace BlubbFish.House.Dashboard.Functions { this.list.Add(d, e); DateTime old = DateTime.Now.AddSeconds(-30); List remove = new List(); - foreach (KeyValuePair item in this.list) { + foreach (KeyValuePair item in this.list) { if(item.Key < old) { remove.Add(item.Key); } diff --git a/House-Dashboard/Graphics/AGraphics.cs b/House-Dashboard/Graphics/AGraphics.cs index 3324b21..9af704e 100644 --- a/House-Dashboard/Graphics/AGraphics.cs +++ b/House-Dashboard/Graphics/AGraphics.cs @@ -3,20 +3,23 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; using System.Windows.Controls; using BlubbFish.Utils.IoT.Connector; namespace BlubbFish.House.Dashboard.Graphics { abstract class AGraphics { - protected ADataBackend data; + protected ABackend data; protected Dictionary settings; + protected UIElement window; - protected AGraphics(Dictionary settings, ADataBackend data) { + protected AGraphics(Dictionary settings, ABackend data, UIElement window) { this.data = data; this.settings = settings; + this.window = window; } - internal static AGraphics GetInstance(Dictionary settings, ADataBackend data) { + internal static AGraphics GetInstance(Dictionary settings, ABackend data, UIElement window) { if(!settings.ContainsKey("graphic")) { return null; } @@ -27,7 +30,7 @@ namespace BlubbFish.House.Dashboard.Graphics { } catch (TypeLoadException) { throw new ArgumentException("tracings.ini: " + settings["graphic"].ToUpperLower() + " is not a Tracing"); } - return (AGraphics)t.GetConstructor(new Type[] { typeof(Dictionary), typeof(ADataBackend) }).Invoke(new Object[] { settings, data }); + return (AGraphics)t.GetConstructor(new Type[] { typeof(Dictionary), typeof(ABackend), typeof(UIElement) }).Invoke(new Object[] { settings, data, window }); } public abstract Grid Draw(); diff --git a/House-Dashboard/Graphics/Heater.cs b/House-Dashboard/Graphics/Heater.cs index f45ee1e..17b8972 100644 --- a/House-Dashboard/Graphics/Heater.cs +++ b/House-Dashboard/Graphics/Heater.cs @@ -5,25 +5,28 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; +using System.Windows.Controls.Primitives; using System.Windows.Media; using BlubbFish.Utils.IoT.Connector; +using BlubbFish.Utils.IoT.Events; using LitJson; namespace BlubbFish.House.Dashboard.Graphics { class Heater : AGraphics { - private TextBlock targetTemp; - private Dictionary targetTemps = new Dictionary(); - private TextBlock mode; - private TextBlock now; - private String topic; - private Dictionary modes = new Dictionary(); + private readonly TextBlock targetTemp; + private readonly Dictionary targetTemps = new Dictionary(); + private readonly TextBlock mode; + private readonly TextBlock now; + private readonly String topic; + private readonly Dictionary modes = new Dictionary(); private Int32 activemode = -1; - private Dictionary replace = new Dictionary { + private Popup popup; + private readonly Dictionary replace = new Dictionary { { "Heat", "Heizen" }, { "Energy Save Heat", "Nacht" } }; - public Heater(Dictionary settings, ADataBackend data) : base(settings, data) { + public Heater(Dictionary settings, ABackend data, UIElement window) : base(settings, data, window) { this.targetTemp = new TextBlock { Text = "0 °C" }; @@ -36,18 +39,20 @@ namespace BlubbFish.House.Dashboard.Graphics { if(this.settings.ContainsKey("topic")) { this.topic = this.settings["topic"]; this.data.MessageIncomming += this.Data_MessageIncomming; - this.data.Send(this.topic + "/0/49/1/get", ""); - this.data.Send(this.topic + "/0/64/get", ""); - this.data.Send(this.topic + "/0/67/1/get", ""); - this.data.Send(this.topic + "/0/67/11/get", ""); + if (this.data is ADataBackend) { + ((ADataBackend)this.data).Send(this.topic + "/0/49/1/get", ""); + ((ADataBackend)this.data).Send(this.topic + "/0/64/get", ""); + ((ADataBackend)this.data).Send(this.topic + "/0/67/1/get", ""); + ((ADataBackend)this.data).Send(this.topic + "/0/67/11/get", ""); + } } } - private void Data_MessageIncomming(Object sender, MqttEventArgs e) { - if (e.Topic.StartsWith(this.topic)) { + private void Data_MessageIncomming(Object sender, BackendEvent e) { + if (e.From.ToString().StartsWith(this.topic)) { try { JsonData j = JsonMapper.ToObject(e.Message); - if (e.Topic == this.topic + "/0/49/1") { + if (e.From.ToString() == this.topic + "/0/49/1") { if (j.Keys.Contains("Level")) { if (Double.TryParse(j["Level"].ToString(), out Double level)) { this.now.Dispatcher.BeginInvoke((Action)(() => { @@ -56,7 +61,7 @@ namespace BlubbFish.House.Dashboard.Graphics { } } } - if (e.Topic == this.topic + "/0/64") { + if (e.From.ToString() == this.topic + "/0/64") { if (j.Keys.Contains("ValidModes") && j["ValidModes"].IsObject && this.modes.Count == 0) { foreach (String item in j["ValidModes"].Keys) { if (Int32.TryParse(item, out Int32 jvmode)) { @@ -78,13 +83,13 @@ namespace BlubbFish.House.Dashboard.Graphics { } } } - if (e.Topic == this.topic + "/0/67/1" || e.Topic == this.topic + "/0/67/11") { + if (e.From.ToString() == this.topic + "/0/67/1" || e.From.ToString() == this.topic + "/0/67/11") { if (j.Keys.Contains("Level")) { if (Double.TryParse(j["Level"].ToString(), out Double temp)) { Int32 id = 0; - if (e.Topic.EndsWith("/1")) { + if (e.From.ToString().EndsWith("/1")) { id = 1; - } else if (e.Topic.EndsWith("/11")) { + } else if (e.From.ToString().EndsWith("/11")) { id = 11; } if (this.targetTemps.ContainsKey(id)) { @@ -112,6 +117,7 @@ namespace BlubbFish.House.Dashboard.Graphics { Grid outergrid = this.CreateOuterGrid(); outergrid.Children.Add(this.CreateInnerGrid()); outergrid.Children.Add(this.CreateTextBlock()); + outergrid.Children.Add(this.CreatePopup()); return outergrid; } @@ -185,6 +191,7 @@ namespace BlubbFish.House.Dashboard.Graphics { Background = new ImageBrush(Helper.BitmapToImageSource(Properties.Resources.graphics_heater)), RenderTransform = new RotateTransform(rotate) }; + grid.MouseDown += this.Grid_MouseDown; Thickness thickness = new Thickness(); Boolean thicknessSet = false; if (this.settings.ContainsKey("x") && Int32.TryParse(this.settings["x"], out Int32 x)) { @@ -202,5 +209,150 @@ namespace BlubbFish.House.Dashboard.Graphics { grid.ColumnDefinitions.Add(new ColumnDefinition()); return grid; } + + private Popup CreatePopup() { + // + this.popup = new Popup { + Placement = PlacementMode.Center, + PopupAnimation = PopupAnimation.Slide, + PlacementTarget = this.window + }; + // + Grid outergrid = new Grid { + Background = new SolidColorBrush(Color.FromRgb(255, 255, 255)), + Opacity = 0.8, + Margin = new Thickness(0, 0, 0, 0) + }; + // + // + // + // + // + // + outergrid.RowDefinitions.Add(new RowDefinition()); + outergrid.RowDefinitions.Add(new RowDefinition()); + outergrid.RowDefinitions.Add(new RowDefinition()); + outergrid.RowDefinitions.Add(new RowDefinition()); + // + Border b = new Border { + BorderBrush = new SolidColorBrush(Color.FromRgb(0, 0, 0)), + BorderThickness = new Thickness(2) + }; + b.SetValue(Grid.RowSpanProperty, 4); + outergrid.Children.Add(b); + // + outergrid.Children.Add(new TextBlock { + Text = "Heater Settings:", + Margin = new Thickness(5), + HorizontalAlignment = HorizontalAlignment.Center + }); + // + Grid innergrid1 = new Grid { + Margin = new Thickness(5) + }; + innergrid1.SetValue(Grid.RowProperty, 1); + // + // + // + // + // + innergrid1.ColumnDefinitions.Add(new ColumnDefinition()); + innergrid1.ColumnDefinitions.Add(new ColumnDefinition()); + innergrid1.ColumnDefinitions.Add(new ColumnDefinition()); + // + innergrid1.Children.Add(new TextBlock { + Text = "Target-Temp:", + Margin = new Thickness(0, 0, 10, 0) + }); + // + TextBox t1 = new TextBox { + Width = 30, + Text = "20", + HorizontalAlignment = HorizontalAlignment.Right, + HorizontalContentAlignment = HorizontalAlignment.Right + }; + t1.SetValue(Grid.ColumnProperty, 1); + innergrid1.Children.Add(t1); + // + TextBlock tb1 = new TextBlock { + Text = "°C" + }; + tb1.SetValue(Grid.ColumnProperty, 2); + innergrid1.Children.Add(tb1); + // + outergrid.Children.Add(innergrid1); + // + Grid innergrid2 = new Grid { + Margin = new Thickness(5), + HorizontalAlignment = HorizontalAlignment.Center + }; + innergrid2.SetValue(Grid.RowProperty, 2); + // + // + // + // + innergrid2.ColumnDefinitions.Add(new ColumnDefinition()); + innergrid2.ColumnDefinitions.Add(new ColumnDefinition()); + // + innergrid2.Children.Add(new TextBlock { + Text = "Target-Mode:", + Margin = new Thickness(0, 0, 10, 0) + }); + // + ComboBox cb1 = new ComboBox { + Width = 50 + }; + cb1.SetValue(Grid.ColumnProperty, 1); + // + cb1.Items.Add(new ComboBoxItem { + Content = "Heating" + }); + // + innergrid2.Children.Add(cb1); + // + outergrid.Children.Add(innergrid2); + // + Grid innergrid3 = new Grid { + Margin = new Thickness(5), + HorizontalAlignment = HorizontalAlignment.Center + }; + innergrid3.SetValue(Grid.RowProperty, 3); + // + // + // + // + innergrid3.ColumnDefinitions.Add(new ColumnDefinition()); + innergrid3.ColumnDefinitions.Add(new ColumnDefinition()); + //