From 9189a1bf3645a50dee34e5e6aec6e34b7859bc66 Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Tue, 2 Jan 2018 23:29:44 +0000 Subject: [PATCH] [NF] Heater now Working --- House-Dashboard/Functions/Tabs.cs | 21 ++- House-Dashboard/Graphics/AGraphics.cs | 35 +++++ House-Dashboard/Graphics/Heater.cs | 148 ++++++++++++++++++ House-Dashboard/Helper.cs | 35 +++++ House-Dashboard/House-Dashboard.csproj | 12 ++ House-Dashboard/MainWindow.xaml | 28 +++- House-Dashboard/MainWindow.xaml.cs | 11 +- .../Properties/Resources.Designer.cs | 10 ++ House-Dashboard/Properties/Resources.resx | 17 +- House-Dashboard/Resources/graphics_heater.png | Bin 0 -> 15741 bytes House-Dashboard/packages.config | 4 + 11 files changed, 310 insertions(+), 11 deletions(-) create mode 100644 House-Dashboard/Graphics/AGraphics.cs create mode 100644 House-Dashboard/Graphics/Heater.cs create mode 100644 House-Dashboard/Helper.cs create mode 100644 House-Dashboard/Resources/graphics_heater.png create mode 100644 House-Dashboard/packages.config diff --git a/House-Dashboard/Functions/Tabs.cs b/House-Dashboard/Functions/Tabs.cs index 8ad4025..b1e523a 100644 --- a/House-Dashboard/Functions/Tabs.cs +++ b/House-Dashboard/Functions/Tabs.cs @@ -3,15 +3,19 @@ using System.Net.Cache; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Imaging; +using BlubbFish.House.Dashboard.Graphics; using BlubbFish.Utils; +using BlubbFish.Utils.IoT.Connector; namespace BlubbFish.House.Dashboard.Functions { class Tabs { private InIReader ini; + private ADataBackend data; private TabItem tab; - public Tabs(InIReader settings) { + public Tabs(InIReader settings, ADataBackend data) { this.ini = settings; + this.data = data; } internal TabItem GetTab() { @@ -22,9 +26,10 @@ namespace BlubbFish.House.Dashboard.Functions { } private void GenerateContent() { - Grid g = new Grid(); - g.Background = new BrushConverter().ConvertFromString("#FFE5E5E5") as SolidColorBrush; - if(this.ini.GetValue("general", "background-image") != null) { + Grid g = new Grid { + Background = new BrushConverter().ConvertFromString("#FFE5E5E5") as SolidColorBrush + }; + if (this.ini.GetValue("general", "background-image") != null) { BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.CacheOption = BitmapCacheOption.None; @@ -38,6 +43,14 @@ namespace BlubbFish.House.Dashboard.Functions { }; g.Children.Add(bgimage); } + foreach (String item in this.ini.GetSections(false)) { + if(item != "general") { + AGraphics a = AGraphics.GetInstance(this.ini.GetSection(item), this.data); + if (a != null) { + g.Children.Add(a.Draw()); + } + } + } this.tab.Content = g; } diff --git a/House-Dashboard/Graphics/AGraphics.cs b/House-Dashboard/Graphics/AGraphics.cs new file mode 100644 index 0000000..3324b21 --- /dev/null +++ b/House-Dashboard/Graphics/AGraphics.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; +using BlubbFish.Utils.IoT.Connector; + +namespace BlubbFish.House.Dashboard.Graphics { + abstract class AGraphics { + protected ADataBackend data; + protected Dictionary settings; + + protected AGraphics(Dictionary settings, ADataBackend data) { + this.data = data; + this.settings = settings; + } + + internal static AGraphics GetInstance(Dictionary settings, ADataBackend data) { + if(!settings.ContainsKey("graphic")) { + return null; + } + String object_sensor = "BlubbFish.House.Dashboard.Graphics." + settings["graphic"].ToUpperLower(); + Type t = null; + try { + t = Type.GetType(object_sensor, true); + } 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 }); + } + + public abstract Grid Draw(); + } +} diff --git a/House-Dashboard/Graphics/Heater.cs b/House-Dashboard/Graphics/Heater.cs new file mode 100644 index 0000000..4c25be9 --- /dev/null +++ b/House-Dashboard/Graphics/Heater.cs @@ -0,0 +1,148 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using BlubbFish.Utils.IoT.Connector; +using LitJson; + +namespace BlubbFish.House.Dashboard.Graphics { + class Heater : AGraphics { + private TextBlock targetTemp; + private TextBlock mode; + private TextBlock now; + private String topic; + + public Heater(Dictionary settings, ADataBackend data) : base(settings, data) { + this.targetTemp = new TextBlock { + Text = "0 °C" + }; + this.mode = new TextBlock { + Text = "Mode" + }; + this.now = new TextBlock { + Text = "0 °C" + }; + 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", ""); + } + } + + private void Data_MessageIncomming(Object sender, MqttEventArgs e) { + if (e.Topic.StartsWith(this.topic)) { + try { + JsonData j = JsonMapper.ToObject(e.Message); + if (e.Topic == this.topic + "/0/49/1") { + if (j.Keys.Contains("Level")) { + if (Double.TryParse(j["Level"].ToString(), out Double level)) { + this.now.Dispatcher.BeginInvoke((Action)(() => { + this.now.Text = level.ToString() + " °C"; + })); + } + } + } + } catch (Exception) { } + } + } + + public override Grid Draw() { + Grid outergrid = this.CreateOuterGrid(); + outergrid.Children.Add(this.CreateInnerGrid()); + outergrid.Children.Add(this.CreateTextBlock()); + return outergrid; + } + + private TextBlock CreateTextBlock() { + // + this.now.HorizontalAlignment = HorizontalAlignment.Left; + this.now.VerticalAlignment = VerticalAlignment.Top; + + this.now.SetValue(Grid.ColumnProperty, 1); + this.now.FontWeight = FontWeights.Bold; + this.now.FontSize = 28; + this.now.Margin = new Thickness(5,0,10,0); + return this.now; + } + + private Grid CreateInnerGrid() { + // + // + // + // + // + // + // + // + Grid grid = new Grid { + Height = 45, + HorizontalAlignment = HorizontalAlignment.Left, + VerticalAlignment = VerticalAlignment.Top, + Margin = new Thickness(10, 0, 0, 0) + }; + + grid.RowDefinitions.Add(new RowDefinition { + Height = new GridLength(22) + }); + grid.RowDefinitions.Add(new RowDefinition()); + this.targetTemp.HorizontalAlignment = HorizontalAlignment.Center; + this.targetTemp.VerticalAlignment = VerticalAlignment.Top; + this.targetTemp.FontSize = 18; + grid.Children.Add(this.targetTemp); + this.mode.HorizontalAlignment = HorizontalAlignment.Center; + this.mode.VerticalAlignment = VerticalAlignment.Top; + this.mode.SetValue(Grid.RowProperty, 1); + this.mode.FontSize = 12; + grid.Children.Add(this.mode); + return grid; + } + + private Grid CreateOuterGrid() { + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + Double rotate = 0; + if (this.settings.ContainsKey("rotate") && Double.TryParse(this.settings["rotate"], out rotate)) { } + Grid grid = new Grid { + HorizontalAlignment = HorizontalAlignment.Left, + VerticalAlignment = VerticalAlignment.Top, + Background = new ImageBrush(Helper.BitmapToImageSource(Properties.Resources.graphics_heater)), + RenderTransform = new RotateTransform(rotate) + }; + Thickness thickness = new Thickness(); + Boolean thicknessSet = false; + if (this.settings.ContainsKey("x") && Int32.TryParse(this.settings["x"], out Int32 x)) { + thickness.Left = x; + thicknessSet = true; + } + if (this.settings.ContainsKey("y") && Int32.TryParse(this.settings["y"], out Int32 y)) { + thickness.Top = y; + thicknessSet = true; + } + if (thicknessSet) { + grid.Margin = thickness; + } + grid.ColumnDefinitions.Add(new ColumnDefinition()); + grid.ColumnDefinitions.Add(new ColumnDefinition()); + return grid; + } + } +} diff --git a/House-Dashboard/Helper.cs b/House-Dashboard/Helper.cs new file mode 100644 index 0000000..87e837e --- /dev/null +++ b/House-Dashboard/Helper.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace BlubbFish.House.Dashboard { + static class Helper { + internal static String ToUpperLower(this String s) { + if (s.Length == 0) { + return ""; + } + if (s.Length == 1) { + return s.ToUpper(); + } + return s[0].ToString().ToUpper() + s.Substring(1).ToLower(); + } + internal static BitmapImage BitmapToImageSource(Bitmap bitmap) { + using (MemoryStream memory = new MemoryStream()) { + bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Png); + memory.Position = 0; + BitmapImage bitmapimage = new BitmapImage(); + bitmapimage.BeginInit(); + bitmapimage.StreamSource = memory; + bitmapimage.CacheOption = BitmapCacheOption.OnLoad; + bitmapimage.EndInit(); + + return bitmapimage; + } + } + } +} diff --git a/House-Dashboard/House-Dashboard.csproj b/House-Dashboard/House-Dashboard.csproj index 5322e20..94b426c 100644 --- a/House-Dashboard/House-Dashboard.csproj +++ b/House-Dashboard/House-Dashboard.csproj @@ -35,8 +35,12 @@ 4 + + ..\packages\LitJson.0.9.0\lib\LitJson.dll + + @@ -65,6 +69,9 @@ + + + MainWindow.xaml Code @@ -86,8 +93,10 @@ ResXFileCodeGenerator + Designer Resources.Designer.cs + SettingsSingleFileGenerator Settings.Designer.cs @@ -110,5 +119,8 @@ Utils + + + \ No newline at end of file diff --git a/House-Dashboard/MainWindow.xaml b/House-Dashboard/MainWindow.xaml index 85bdce4..467191d 100644 --- a/House-Dashboard/MainWindow.xaml +++ b/House-Dashboard/MainWindow.xaml @@ -5,12 +5,38 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:House_Dashboard" mc:Ignorable="d" - Title="Dashboard" WindowState="Maximized" Topmost="True" WindowStyle="None" Height="300" Width="800"> + Title="Dashboard" WindowState="Maximized" Topmost="True" WindowStyle="None" Height="600" Width="800"> + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/House-Dashboard/MainWindow.xaml.cs b/House-Dashboard/MainWindow.xaml.cs index 973e79f..c87b0fd 100644 --- a/House-Dashboard/MainWindow.xaml.cs +++ b/House-Dashboard/MainWindow.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Text; @@ -26,6 +27,14 @@ namespace House_Dashboard { private Workload workload; public MainWindow() { + CultureInfo info = new CultureInfo("de-DE"); + info.NumberFormat.NumberDecimalSeparator = "."; + CultureInfo.DefaultThreadCurrentCulture = info; + CultureInfo.DefaultThreadCurrentUICulture = info; + System.Threading.Thread.CurrentThread.CurrentCulture = info; + System.Threading.Thread.CurrentThread.CurrentUICulture = info; + LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(System.Windows.Markup.XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag))); + InitializeComponent(); InitMqtt(); InitTabs(); @@ -35,7 +44,7 @@ namespace House_Dashboard { if(File.Exists("tabs.ini")) { foreach (String item in InIReader.GetInstance("tabs.ini").GetSections()) { if(InIReader.GetInstance("tabs.ini").GetValue(item, "settings") != null && File.Exists(InIReader.GetInstance("tabs.ini").GetValue(item, "settings"))) { - this.tabs.Items.Add(new Tabs(InIReader.GetInstance(InIReader.GetInstance("tabs.ini").GetValue(item, "settings"))).GetTab()); + this.tabs.Items.Add(new Tabs(InIReader.GetInstance(InIReader.GetInstance("tabs.ini").GetValue(item, "settings")), this.mqtt).GetTab()); } } } else { diff --git a/House-Dashboard/Properties/Resources.Designer.cs b/House-Dashboard/Properties/Resources.Designer.cs index cf23fc9..d82a673 100644 --- a/House-Dashboard/Properties/Resources.Designer.cs +++ b/House-Dashboard/Properties/Resources.Designer.cs @@ -59,5 +59,15 @@ namespace BlubbFish.House.Dashboard.Properties { resourceCulture = value; } } + + /// + /// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap graphics_heater { + get { + object obj = ResourceManager.GetObject("graphics_heater", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } } } diff --git a/House-Dashboard/Properties/Resources.resx b/House-Dashboard/Properties/Resources.resx index ffecec8..3369006 100644 --- a/House-Dashboard/Properties/Resources.resx +++ b/House-Dashboard/Properties/Resources.resx @@ -46,7 +46,7 @@ mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with - : System.Serialization.Formatters.Binary.BinaryFormatter + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 @@ -60,6 +60,7 @@ : and then encoded with base64 encoding. --> + @@ -68,9 +69,10 @@ - + + @@ -85,9 +87,10 @@ - + + @@ -109,9 +112,13 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\graphics_heater.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/House-Dashboard/Resources/graphics_heater.png b/House-Dashboard/Resources/graphics_heater.png new file mode 100644 index 0000000000000000000000000000000000000000..84b4dc46d3e326d603cb1d9f9e71bae25360b3ef GIT binary patch literal 15741 zcmeI3Yg7~08iof1v7o3&#S1DiRx3!DB#;1O2t_W66+}PCu9*Y;C9uO4dEU93H0#%OJ;*|v`Qi~N3^-L0k4T4k8>d(o_;@SgACPyNPGAK|c})VJ}S*Ll>>CyM#ODhM(t)P4+*ClBsJ zkkbqzFi0Kbvk<{ZnH?%2!*Dx|OhKt3NaU(fpxA0$%?iUK2)PUUSz$4oMMzxO%LG1L zAB8&}Nz9K`;sLR~fmrNn%vr*A6`P7Q2$evFt5KFlCY7rYjSE|s7olQpGt6e`B`1j*fxvKdbhKTxy&b8HfO*c&&M=n`^Z6V~!BNG?)u@Ie zS54O^d6&lnS7Ay*p(aQ%vE$rL>U$yMF#D2lKKRlqzuE7#2Os$EJPtVu`&Q~TIaA=j< za}9-{8|i>fRbY$)hy8IC8KuN<&o$JgOdsg#)kJvj;`GU+?HP3LxP}HL&GBsd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