[NF] Heater now Working

This commit is contained in:
BlubbFish 2018-01-02 23:29:44 +00:00
parent 08868a1c2e
commit 9189a1bf36
11 changed files with 310 additions and 11 deletions

View File

@ -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,8 +26,9 @@ namespace BlubbFish.House.Dashboard.Functions {
}
private void GenerateContent() {
Grid g = new Grid();
g.Background = new BrushConverter().ConvertFromString("#FFE5E5E5") as SolidColorBrush;
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();
@ -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;
}

View File

@ -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<String, String> settings;
protected AGraphics(Dictionary<String, String> settings, ADataBackend data) {
this.data = data;
this.settings = settings;
}
internal static AGraphics GetInstance(Dictionary<String, String> 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<String, String>), typeof(ADataBackend) }).Invoke(new Object[] { settings, data });
}
public abstract Grid Draw();
}
}

View File

@ -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<String, String> 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() {
//<TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Text="0 °C" Grid.Column="1" FontWeight="Bold" FontSize="28" Margin="5,0,10,0"/>
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 Height="45" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,0,0,0">
// <Grid.RowDefinitions>
// <RowDefinition Height="22"/>
// <RowDefinition/>
// </Grid.RowDefinitions>
// <TextBlock HorizontalAlignment="Center" VerticalAlignment="Top" Text="0 °C" FontSize="18"/>
// <TextBlock HorizontalAlignment="Center" VerticalAlignment="Top" Text="Mode" Grid.Row="1" FontSize="12"/>
//</Grid>
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() {
//<Grid HorizontalAlignment="Left" Margin="x,y,0,0" VerticalAlignment="Top">
// <Grid.RenderTransform>
// <TransformGroup>
// <ScaleTransform/>
// <SkewTransform/>
// <RotateTransform Angle="0"/>
// <TranslateTransform/>
// </TransformGroup>
// </Grid.RenderTransform>
// <Grid.Background>
// <ImageBrush ImageSource = "pack://siteoforigin:,,,/Resources/graphics_heater.png" />
// </Grid.Background>
// <Grid.ColumnDefinitions>
// <ColumnDefinition/>
// <ColumnDefinition/>
// </Grid.ColumnDefinitions>
//</Grid>
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;
}
}
}

35
House-Dashboard/Helper.cs Normal file
View File

@ -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;
}
}
}
}

View File

@ -35,8 +35,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="LitJson, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\LitJson.0.9.0\lib\LitJson.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
@ -65,6 +69,9 @@
</Compile>
<Compile Include="Functions\Tabs.cs" />
<Compile Include="Functions\Workload.cs" />
<Compile Include="Graphics\AGraphics.cs" />
<Compile Include="Graphics\Heater.cs" />
<Compile Include="Helper.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
@ -86,8 +93,10 @@
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<SubType>Designer</SubType>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@ -110,5 +119,8 @@
<Name>Utils</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Resources\graphics_heater.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -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">
<Grid>
<TabControl x:Name="tabs" Padding="0" Margin="0,0,0,26">
<TabItem Header="Home" FontSize="20">
<Grid Background="#FFE5E5E5">
<Image Source="E:\Eigene Dateien\Dokumente\Visual Studio 2017\Projects\House-Dashboard\House-Dashboard\bin\Debug\Images\Grundriss.png"/>
<Grid HorizontalAlignment="Left" Margin="20,87,0,0" VerticalAlignment="Top">
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="90"/>
<TranslateTransform/>
</TransformGroup>
</Grid.RenderTransform>
<Grid.Background>
<ImageBrush ImageSource="E:\Eigene Dateien\Dokumente\Visual Studio 2017\Projects\House-Dashboard\House-Dashboard\Resources\graphics_heater.png"/>
</Grid.Background>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid Height="45" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="22"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock HorizontalAlignment="Center" Text="0 °C" VerticalAlignment="Top" FontSize="18"/>
<TextBlock HorizontalAlignment="Center" Text="Mode" VerticalAlignment="Top" Grid.Row="1" FontSize="12"/>
</Grid>
<TextBlock HorizontalAlignment="Left" Text="99 °C" VerticalAlignment="Top" Grid.Column="1" FontWeight="Bold" FontSize="28" Margin="5,0,10,0"/>
</Grid>
</Grid>
</TabItem>

View File

@ -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 {

View File

@ -59,5 +59,15 @@ namespace BlubbFish.House.Dashboard.Properties {
resourceCulture = value;
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap graphics_heater {
get {
object obj = ResourceManager.GetObject("graphics_heater", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -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.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
@ -68,9 +69,10 @@
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
@ -85,9 +87,10 @@
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
@ -109,9 +112,13 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="graphics_heater" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\graphics_heater.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="LitJson" version="0.9.0" targetFramework="net471" />
</packages>