Add some tiny features to House-Dashboard

Add ESP Graphics to Dashboard
This commit is contained in:
BlubbFish 2018-09-11 07:57:28 +00:00
parent c970172c46
commit 45a6458506
8 changed files with 127 additions and 75 deletions

View File

@ -71,7 +71,8 @@ namespace BlubbFish.House.Dashboard.Functions {
bitmap.UriSource = new Uri(this.ini.GetValue("general", "icon"), UriKind.RelativeOrAbsolute); bitmap.UriSource = new Uri(this.ini.GetValue("general", "icon"), UriKind.RelativeOrAbsolute);
bitmap.EndInit(); bitmap.EndInit();
Image image = new Image { Image image = new Image {
Source = bitmap Source = bitmap,
Height = 30
}; };
header.Children.Add(image); header.Children.Add(image);
} }

View File

@ -7,12 +7,67 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using BlubbFish.Utils.IoT.Connector; using BlubbFish.Utils.IoT.Connector;
using System.Windows.Media; using System.Windows.Media;
using BlubbFish.Utils.IoT.Events;
using LitJson;
namespace BlubbFish.House.Dashboard.Graphics namespace BlubbFish.House.Dashboard.Graphics
{ {
class Esp : AGraphics class Esp : AGraphics
{ {
private readonly TextBlock lumi;
private readonly TextBlock pressure;
private readonly TextBlock humidity;
private readonly TextBlock temp;
private readonly String topic;
public Esp(Dictionary<String, String> settings, ABackend data, UIElement window) : base(settings, data, window) { public Esp(Dictionary<String, String> settings, ABackend data, UIElement window) : base(settings, data, window) {
this.lumi = new TextBlock() {
Text = ""
};
this.pressure = new TextBlock() {
Text = ""
};
this.humidity = new TextBlock() {
Text = ""
};
this.temp = new TextBlock() {
Text = ""
};
if (this.settings.ContainsKey("topic")) {
this.topic = this.settings["topic"];
this.data.MessageIncomming += this.Data_MessageIncomming;
if (this.data is ADataBackend) {
((ADataBackend)this.data).Send(this.topic + "/get", "");
}
}
}
private void Data_MessageIncomming(Object sender, BackendEvent e) {
if (e.From.ToString() == this.topic) {
try {
JsonData j = JsonMapper.ToObject(e.Message);
if (j.ContainsKey("Temperature") && j["Temperature"].IsDouble) {
this.temp.Dispatcher.BeginInvoke((Action)(() => {
this.temp.Text = ((Double)j["Temperature"]).ToString() + " °C";
}));
}
if (j.ContainsKey("Humidity") && j["Humidity"].IsDouble) {
this.humidity.Dispatcher.BeginInvoke((Action)(() => {
this.humidity.Text = ((Double)j["Humidity"]).ToString("F2") + " %";
}));
}
if (j.ContainsKey("Pressure") && j["Pressure"].IsDouble) {
this.pressure.Dispatcher.BeginInvoke((Action)(() => {
this.pressure.Text = ((Double)j["Pressure"]).ToString("F2") + " hPa";
}));
}
if (j.ContainsKey("Lux") && j["Lux"].IsDouble) {
this.lumi.Dispatcher.BeginInvoke((Action)(() => {
this.lumi.Text = ((Double)j["Lux"]).ToString("F4") + " Lux";
}));
}
} catch { }
}
} }
public override Grid Draw() { public override Grid Draw() {
@ -44,11 +99,8 @@ namespace BlubbFish.House.Dashboard.Graphics
Source = Helper.BitmapToImageSource(Properties.Resources.esp_luminence), Source = Helper.BitmapToImageSource(Properties.Resources.esp_luminence),
Height = 30 Height = 30
}); });
TextBlock temp = new TextBlock() { this.lumi.SetValue(Grid.ColumnProperty, 1);
Text = "2000" grid.Children.Add(this.lumi);
};
temp.SetValue(Grid.ColumnProperty, 1);
grid.Children.Add(temp);
return grid; return grid;
} }
@ -71,11 +123,8 @@ namespace BlubbFish.House.Dashboard.Graphics
Source = Helper.BitmapToImageSource(Properties.Resources.esp_pressure), Source = Helper.BitmapToImageSource(Properties.Resources.esp_pressure),
Height = 30 Height = 30
}); });
TextBlock temp = new TextBlock() { this.pressure.SetValue(Grid.ColumnProperty, 1);
Text = "1000" grid.Children.Add(this.pressure);
};
temp.SetValue(Grid.ColumnProperty, 1);
grid.Children.Add(temp);
return grid; return grid;
} }
@ -98,11 +147,8 @@ namespace BlubbFish.House.Dashboard.Graphics
Source = Helper.BitmapToImageSource(Properties.Resources.esp_humidity), Source = Helper.BitmapToImageSource(Properties.Resources.esp_humidity),
Height = 30 Height = 30
}); });
TextBlock temp = new TextBlock() { this.humidity.SetValue(Grid.ColumnProperty, 1);
Text = "30%" grid.Children.Add(this.humidity);
};
temp.SetValue(Grid.ColumnProperty, 1);
grid.Children.Add(temp);
return grid; return grid;
} }
@ -124,11 +170,8 @@ namespace BlubbFish.House.Dashboard.Graphics
Source = Helper.BitmapToImageSource(Properties.Resources.esp_thermometer), Source = Helper.BitmapToImageSource(Properties.Resources.esp_thermometer),
Height = 30 Height = 30
}); });
TextBlock temp = new TextBlock() { this.temp.SetValue(Grid.ColumnProperty, 1);
Text = "20°C" grid.Children.Add(this.temp);
};
temp.SetValue(Grid.ColumnProperty, 1);
grid.Children.Add(temp);
return grid; return grid;
} }

View File

@ -117,7 +117,7 @@ namespace BlubbFish.House.Dashboard.Graphics {
} }
} }
} }
} catch (Exception) { } } catch { }
} }
} }

View File

@ -15,13 +15,13 @@ namespace BlubbFish.House.Dashboard.Graphics
{ {
class Huelight : AGraphics class Huelight : AGraphics
{ {
private TextBlock status; private readonly TextBlock status;
private TextBlock opy; private readonly TextBlock opy;
private ImageBrush img; private readonly ImageBrush img;
private String topic; private readonly String topic;
private Popup popup; private Popup popup;
private Slider popup_slider; private readonly Slider popup_slider;
private CheckBox popup_checkbox; private readonly CheckBox popup_checkbox;
public Huelight(Dictionary<String, String> settings, ABackend data, UIElement window) : base(settings, data, window) { public Huelight(Dictionary<String, String> settings, ABackend data, UIElement window) : base(settings, data, window) {
this.status = new TextBlock() { this.status = new TextBlock() {
@ -49,24 +49,25 @@ namespace BlubbFish.House.Dashboard.Graphics
private void Data_MessageIncomming(Object sender, BackendEvent e) { private void Data_MessageIncomming(Object sender, BackendEvent e) {
if (e.From.ToString() == this.topic) { if (e.From.ToString() == this.topic) {
try {
JsonData json = JsonMapper.ToObject(e.Message); JsonData json = JsonMapper.ToObject(e.Message);
if(json.ContainsKey("Brightness") && json["Brightness"].IsInt) { if (json.ContainsKey("Brightness") && json["Brightness"].IsInt) {
Int32 bright = (Int32)json["Brightness"]; Int32 bright = (Int32)json["Brightness"];
this.opy.Dispatcher.BeginInvoke((Action)(() => { this.opy.Dispatcher.BeginInvoke((Action)(() => {
this.opy.Text = ((bright / 254) * 100).ToString() + " %"; this.opy.Text = ((Int32)(((Single)bright / 254) * 100)).ToString() + " %";
})); }));
this.img.Dispatcher.BeginInvoke((Action)(() => { this.img.Dispatcher.BeginInvoke((Action)(() => {
this.img.Opacity = (bright / 254); this.img.Opacity = ((Single)bright / 254);
})); }));
this.popup_slider.Dispatcher.BeginInvoke((Action)(() => { this.popup_slider.Dispatcher.BeginInvoke((Action)(() => {
this.popup_slider.Value = bright; this.popup_slider.Value = bright;
})); }));
} }
Boolean on = false; Boolean on = false;
if(json.ContainsKey("Reachable") && json["Reachable"].IsBoolean && !(Boolean)json["Reachable"]) { if (json.ContainsKey("Reachable") && json["Reachable"].IsBoolean && !(Boolean)json["Reachable"]) {
on = false; on = false;
} else if(json.ContainsKey("Reachable") && json["Reachable"].IsBoolean && (Boolean)json["Reachable"]) { } else if (json.ContainsKey("Reachable") && json["Reachable"].IsBoolean && (Boolean)json["Reachable"]) {
if(json.ContainsKey("State") && json["State"].IsBoolean) { if (json.ContainsKey("State") && json["State"].IsBoolean) {
on = (Boolean)json["State"]; on = (Boolean)json["State"];
} }
} }
@ -85,6 +86,7 @@ namespace BlubbFish.House.Dashboard.Graphics
this.popup_checkbox.Dispatcher.BeginInvoke((Action)(() => { this.popup_checkbox.Dispatcher.BeginInvoke((Action)(() => {
this.popup_checkbox.IsChecked = on; this.popup_checkbox.IsChecked = on;
})); }));
} catch { }
} }
} }

View File

@ -140,5 +140,10 @@
<ItemGroup> <ItemGroup>
<None Include="Resources\esp_luminence.png" /> <None Include="Resources\esp_luminence.png" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Resource Include="credits.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@ -28,6 +28,7 @@ namespace House_Dashboard {
private Workload workload; private Workload workload;
public MainWindow() { public MainWindow() {
InIReader.SetSearchPath(new List<String>() { "/etc/homedash", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\homedash" });
CultureInfo info = new CultureInfo("de-DE"); CultureInfo info = new CultureInfo("de-DE");
info.NumberFormat.NumberDecimalSeparator = "."; info.NumberFormat.NumberDecimalSeparator = ".";
CultureInfo.DefaultThreadCurrentCulture = info; CultureInfo.DefaultThreadCurrentCulture = info;
@ -42,10 +43,10 @@ namespace House_Dashboard {
} }
private void InitTabs() { private void InitTabs() {
if(File.Exists("tabs.ini")) { if(InIReader.ConfigExist("tabs")) {
foreach (String item in InIReader.GetInstance("tabs.ini").GetSections()) { foreach (String item in InIReader.GetInstance("tabs").GetSections()) {
if(InIReader.GetInstance("tabs.ini").GetValue(item, "settings") != null && File.Exists(InIReader.GetInstance("tabs.ini").GetValue(item, "settings"))) { if(InIReader.GetInstance("tabs").GetValue(item, "settings") != null && InIReader.ConfigExist(InIReader.GetInstance("tabs").GetValue(item, "settings"))) {
this.tabs.Items.Add(new Tabs(InIReader.GetInstance(InIReader.GetInstance("tabs.ini").GetValue(item, "settings")), this.mqtt).GetTab(this.myWindow)); this.tabs.Items.Add(new Tabs(InIReader.GetInstance(InIReader.GetInstance("tabs").GetValue(item, "settings")), this.mqtt).GetTab(this.myWindow));
} }
} }
} else { } else {
@ -55,8 +56,8 @@ namespace House_Dashboard {
} }
private void InitMqtt() { private void InitMqtt() {
if(File.Exists("mqtt.ini")) { if(InIReader.ConfigExist("mqtt")) {
this.mqtt = ABackend.GetInstance(InIReader.GetInstance("mqtt.ini").GetSection("settings"), ABackend.BackendType.Data); this.mqtt = ABackend.GetInstance(InIReader.GetInstance("mqtt").GetSection("settings"), ABackend.BackendType.Data);
if(this.mqtt == null) { if(this.mqtt == null) {
MessageBox.Show("Der Mqtt Treiber konnte nicht geladen werden.", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show("Der Mqtt Treiber konnte nicht geladen werden.", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
this.ApplicationShutdown(null, null); this.ApplicationShutdown(null, null);

View File

@ -54,9 +54,3 @@ using System.Windows;
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: NeutralResourcesLanguage("de-DE")] [assembly: NeutralResourcesLanguage("de-DE")]
/// Icons made by https://www.flaticon.com/authors/nice-and-serious Nice and Serious from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
/// Icons made by https://www.flaticon.com/authors/epiccoders EpicCoders from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
/// Icons made by https://www.flaticon.com/authors/photo3idea-studio photo3idea_studio from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
/// Icons made by https://www.flaticon.com/authors/good-ware Good Ware from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
/// Icons made by https://www.flaticon.com/authors/lucy-g Lucy G from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0

View File

@ -0,0 +1,6 @@
Icons made by https://www.flaticon.com/authors/freepik Freepik from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
Icons made by https://www.flaticon.com/authors/nice-and-serious Nice and Serious from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
Icons made by https://www.flaticon.com/authors/epiccoders EpicCoders from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
Icons made by https://www.flaticon.com/authors/photo3idea-studio photo3idea_studio from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
Icons made by https://www.flaticon.com/authors/good-ware Good Ware from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
Icons made by https://www.flaticon.com/authors/lucy-g Lucy G from Flaticon is licensed by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0