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.EndInit();
Image image = new Image {
Source = bitmap
Source = bitmap,
Height = 30
};
header.Children.Add(image);
}

View File

@ -7,12 +7,67 @@ using System.Windows;
using System.Windows.Controls;
using BlubbFish.Utils.IoT.Connector;
using System.Windows.Media;
using BlubbFish.Utils.IoT.Events;
using LitJson;
namespace BlubbFish.House.Dashboard.Graphics
{
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) {
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() {
@ -44,11 +99,8 @@ namespace BlubbFish.House.Dashboard.Graphics
Source = Helper.BitmapToImageSource(Properties.Resources.esp_luminence),
Height = 30
});
TextBlock temp = new TextBlock() {
Text = "2000"
};
temp.SetValue(Grid.ColumnProperty, 1);
grid.Children.Add(temp);
this.lumi.SetValue(Grid.ColumnProperty, 1);
grid.Children.Add(this.lumi);
return grid;
}
@ -71,11 +123,8 @@ namespace BlubbFish.House.Dashboard.Graphics
Source = Helper.BitmapToImageSource(Properties.Resources.esp_pressure),
Height = 30
});
TextBlock temp = new TextBlock() {
Text = "1000"
};
temp.SetValue(Grid.ColumnProperty, 1);
grid.Children.Add(temp);
this.pressure.SetValue(Grid.ColumnProperty, 1);
grid.Children.Add(this.pressure);
return grid;
}
@ -98,11 +147,8 @@ namespace BlubbFish.House.Dashboard.Graphics
Source = Helper.BitmapToImageSource(Properties.Resources.esp_humidity),
Height = 30
});
TextBlock temp = new TextBlock() {
Text = "30%"
};
temp.SetValue(Grid.ColumnProperty, 1);
grid.Children.Add(temp);
this.humidity.SetValue(Grid.ColumnProperty, 1);
grid.Children.Add(this.humidity);
return grid;
}
@ -124,11 +170,8 @@ namespace BlubbFish.House.Dashboard.Graphics
Source = Helper.BitmapToImageSource(Properties.Resources.esp_thermometer),
Height = 30
});
TextBlock temp = new TextBlock() {
Text = "20°C"
};
temp.SetValue(Grid.ColumnProperty, 1);
grid.Children.Add(temp);
this.temp.SetValue(Grid.ColumnProperty, 1);
grid.Children.Add(this.temp);
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
{
private TextBlock status;
private TextBlock opy;
private ImageBrush img;
private String topic;
private readonly TextBlock status;
private readonly TextBlock opy;
private readonly ImageBrush img;
private readonly String topic;
private Popup popup;
private Slider popup_slider;
private CheckBox popup_checkbox;
private readonly Slider popup_slider;
private readonly CheckBox popup_checkbox;
public Huelight(Dictionary<String, String> settings, ABackend data, UIElement window) : base(settings, data, window) {
this.status = new TextBlock() {
@ -49,42 +49,44 @@ namespace BlubbFish.House.Dashboard.Graphics
private void Data_MessageIncomming(Object sender, BackendEvent e) {
if (e.From.ToString() == this.topic) {
JsonData json = JsonMapper.ToObject(e.Message);
if(json.ContainsKey("Brightness") && json["Brightness"].IsInt) {
Int32 bright = (Int32)json["Brightness"];
this.opy.Dispatcher.BeginInvoke((Action)(() => {
this.opy.Text = ((bright / 254) * 100).ToString() + " %";
}));
this.img.Dispatcher.BeginInvoke((Action)(() => {
this.img.Opacity = (bright / 254);
}));
this.popup_slider.Dispatcher.BeginInvoke((Action)(() => {
this.popup_slider.Value = bright;
}));
}
Boolean on = false;
if(json.ContainsKey("Reachable") && json["Reachable"].IsBoolean && !(Boolean)json["Reachable"]) {
on = false;
} else if(json.ContainsKey("Reachable") && json["Reachable"].IsBoolean && (Boolean)json["Reachable"]) {
if(json.ContainsKey("State") && json["State"].IsBoolean) {
on = (Boolean)json["State"];
try {
JsonData json = JsonMapper.ToObject(e.Message);
if (json.ContainsKey("Brightness") && json["Brightness"].IsInt) {
Int32 bright = (Int32)json["Brightness"];
this.opy.Dispatcher.BeginInvoke((Action)(() => {
this.opy.Text = ((Int32)(((Single)bright / 254) * 100)).ToString() + " %";
}));
this.img.Dispatcher.BeginInvoke((Action)(() => {
this.img.Opacity = ((Single)bright / 254);
}));
this.popup_slider.Dispatcher.BeginInvoke((Action)(() => {
this.popup_slider.Value = bright;
}));
}
}
if (!on) {
this.img.Dispatcher.BeginInvoke((Action)(() => {
this.img.Opacity = 0;
}));
}
this.status.Dispatcher.BeginInvoke((Action)(() => {
if (on) {
this.status.Text = "An";
} else {
this.status.Text = "Aus";
Boolean on = false;
if (json.ContainsKey("Reachable") && json["Reachable"].IsBoolean && !(Boolean)json["Reachable"]) {
on = false;
} else if (json.ContainsKey("Reachable") && json["Reachable"].IsBoolean && (Boolean)json["Reachable"]) {
if (json.ContainsKey("State") && json["State"].IsBoolean) {
on = (Boolean)json["State"];
}
}
}));
this.popup_checkbox.Dispatcher.BeginInvoke((Action)(() => {
this.popup_checkbox.IsChecked = on;
}));
if (!on) {
this.img.Dispatcher.BeginInvoke((Action)(() => {
this.img.Opacity = 0;
}));
}
this.status.Dispatcher.BeginInvoke((Action)(() => {
if (on) {
this.status.Text = "An";
} else {
this.status.Text = "Aus";
}
}));
this.popup_checkbox.Dispatcher.BeginInvoke((Action)(() => {
this.popup_checkbox.IsChecked = on;
}));
} catch { }
}
}

View File

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

View File

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

View File

@ -53,10 +53,4 @@ using System.Windows;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[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
[assembly: NeutralResourcesLanguage("de-DE")]

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