diff --git a/PlantBox.Client/PlantBox.Client/Converters/CaptorValueToDoubleConverter.cs b/PlantBox.Client/PlantBox.Client/Converters/CaptorValueToDoubleConverter.cs index 51d739c..e3b3b1a 100644 --- a/PlantBox.Client/PlantBox.Client/Converters/CaptorValueToDoubleConverter.cs +++ b/PlantBox.Client/PlantBox.Client/Converters/CaptorValueToDoubleConverter.cs @@ -1,4 +1,5 @@ -using PlantBox.Shared.Communication.Commands; +using PlantBox.Client.Models; +using PlantBox.Shared.Communication.Commands; using System; using System.Collections.Generic; using System.Globalization; @@ -9,24 +10,53 @@ namespace PlantBox.Client.Converters { class CaptorValueToDoubleConverter : IValueConverter { + const double HUMIDITY_UPPER_BOUND = 100.0; + const double HUMIDITY_LOWER_BOUND = 0.0; + const double LUMINOSITY_UPPER_BOUND = 1200.0; + const double LUMINOSITY_LOWER_BOUND = 0.0; + const double TEMPERATURE_UPPER_BOUND = 50.0; + const double TEMPERATURE_LOWER_BOUND = -20.0; + const double TANK_UPPER_BOUND = 100.0; + const double TANK_LOWER_BOUND = 0.0; + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if (value is CaptorValue captor) + if (value is double d && parameter is CaptorType type) { - return (captor.Value - captor.Min) / (captor.Max - captor.Min); + double upperBound; + double lowerBound; + + switch (type) + { + case CaptorType.Humidity: + upperBound = HUMIDITY_UPPER_BOUND; + lowerBound = HUMIDITY_LOWER_BOUND; + break; + case CaptorType.Luminosity: + upperBound = LUMINOSITY_UPPER_BOUND; + lowerBound = LUMINOSITY_LOWER_BOUND; + break; + case CaptorType.Temperature: + upperBound = TEMPERATURE_UPPER_BOUND; + lowerBound = TEMPERATURE_LOWER_BOUND; + break; + case CaptorType.Tank: + upperBound = TANK_UPPER_BOUND; + lowerBound = TANK_LOWER_BOUND; + break; + default: + throw new InvalidOperationException("How did you just got here?"); + } + + return (d - lowerBound) / (upperBound - lowerBound); } - throw new ArgumentException($"Invalid source: excepted 'CaptorValue' and got '${value.GetType().Name}'", nameof(value)); + throw new ArgumentException("Invalid source or argument"); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { - if (value is double step && parameter is CaptorValue captor) - { - return new CaptorValue(captor.Min, captor.Max, (captor.Max - captor.Min) * step - captor.Max); - } - - throw new ArgumentException(); + throw new NotImplementedException(); } } } diff --git a/PlantBox.Client/PlantBox.Client/Forms/HomePage.xaml.cs b/PlantBox.Client/PlantBox.Client/Forms/HomePage.xaml.cs index 771db09..bd90d7c 100644 --- a/PlantBox.Client/PlantBox.Client/Forms/HomePage.xaml.cs +++ b/PlantBox.Client/PlantBox.Client/Forms/HomePage.xaml.cs @@ -29,9 +29,8 @@ namespace PlantBox.Client.Forms // Prepare view model var viewModel = new PlantViewModel(plant); - await Navigation.PushAsync(new PlantPage() + await Navigation.PushAsync(new PlantPage(viewModel) { - BindingContext = viewModel, Title = plant.Name }); } diff --git a/PlantBox.Client/PlantBox.Client/Forms/Plant/CaptorsPage.xaml b/PlantBox.Client/PlantBox.Client/Forms/Plant/CaptorsPage.xaml index 86089dc..dedf5eb 100644 --- a/PlantBox.Client/PlantBox.Client/Forms/Plant/CaptorsPage.xaml +++ b/PlantBox.Client/PlantBox.Client/Forms/Plant/CaptorsPage.xaml @@ -1,12 +1,63 @@  + + 17% + + - - + + + + + + + \ No newline at end of file diff --git a/PlantBox.Client/PlantBox.Client/Forms/Plant/CaptorsPage.xaml.cs b/PlantBox.Client/PlantBox.Client/Forms/Plant/CaptorsPage.xaml.cs index 5645478..47023cc 100644 --- a/PlantBox.Client/PlantBox.Client/Forms/Plant/CaptorsPage.xaml.cs +++ b/PlantBox.Client/PlantBox.Client/Forms/Plant/CaptorsPage.xaml.cs @@ -12,9 +12,9 @@ namespace PlantBox.Client.Forms.Plant [XamlCompilation(XamlCompilationOptions.Compile)] public partial class CaptorsPage : ContentPage { - public CaptorsPage () + public CaptorsPage() { - InitializeComponent (); + InitializeComponent(); } } } \ No newline at end of file diff --git a/PlantBox.Client/PlantBox.Client/Forms/Plant/PlantPage.xaml.cs b/PlantBox.Client/PlantBox.Client/Forms/Plant/PlantPage.xaml.cs index 9ea5db9..cd59395 100644 --- a/PlantBox.Client/PlantBox.Client/Forms/Plant/PlantPage.xaml.cs +++ b/PlantBox.Client/PlantBox.Client/Forms/Plant/PlantPage.xaml.cs @@ -1,5 +1,6 @@ using PlantBox.Client.Models; using PlantBox.Client.Resources; +using PlantBox.Client.ViewModels; using System; using System.Collections.Generic; using System.Linq; @@ -14,18 +15,18 @@ namespace PlantBox.Client.Forms.Plant [XamlCompilation(XamlCompilationOptions.Compile)] public partial class PlantPage : TabbedPage { - public PlantPage() + public PlantPage(PlantViewModel viewModel) { InitializeComponent(); Children.Add(new CaptorsPage() { - BindingContext = BindingContext, + BindingContext = viewModel, Title = Locale.Informations }); Children.Add(new HistoricPage() { - BindingContext = BindingContext, + BindingContext = viewModel, Title = Locale.Historic }); } diff --git a/PlantBox.Client/PlantBox.Client/Models/CaptorType.cs b/PlantBox.Client/PlantBox.Client/Models/CaptorType.cs new file mode 100644 index 0000000..8f26647 --- /dev/null +++ b/PlantBox.Client/PlantBox.Client/Models/CaptorType.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace PlantBox.Client.Models +{ + enum CaptorType + { + Humidity, + Luminosity, + Tank, + Temperature + } +} diff --git a/PlantBox.Client/PlantBox.Client/Models/Historic.cs b/PlantBox.Client/PlantBox.Client/Models/Historic.cs index 069a14b..7d6c94a 100644 --- a/PlantBox.Client/PlantBox.Client/Models/Historic.cs +++ b/PlantBox.Client/PlantBox.Client/Models/Historic.cs @@ -4,7 +4,7 @@ using System.Text; namespace PlantBox.Client.Models { - class Historic + public class Historic { public HistoricEntry MinutelyHistoric { get; } public HistoricEntry HourlyHistoric { get; } diff --git a/PlantBox.Client/PlantBox.Client/Models/HistoricEntry.cs b/PlantBox.Client/PlantBox.Client/Models/HistoricEntry.cs index 9c91255..1ce34dd 100644 --- a/PlantBox.Client/PlantBox.Client/Models/HistoricEntry.cs +++ b/PlantBox.Client/PlantBox.Client/Models/HistoricEntry.cs @@ -4,7 +4,7 @@ using System.Text; namespace PlantBox.Client.Models { - class HistoricEntry + public class HistoricEntry { public DateTime LastTime { get; } public TimeSpan TimeInterval { get; } diff --git a/PlantBox.Client/PlantBox.Client/PlantBox.Client.csproj b/PlantBox.Client/PlantBox.Client/PlantBox.Client.csproj index c61e328..c4d3920 100644 --- a/PlantBox.Client/PlantBox.Client/PlantBox.Client.csproj +++ b/PlantBox.Client/PlantBox.Client/PlantBox.Client.csproj @@ -15,18 +15,26 @@ + + + + + + + + diff --git a/PlantBox.Client/PlantBox.Client/Resources/Images/Humidity_Icon.png b/PlantBox.Client/PlantBox.Client/Resources/Images/Humidity_Icon.png new file mode 100644 index 0000000..2d93508 Binary files /dev/null and b/PlantBox.Client/PlantBox.Client/Resources/Images/Humidity_Icon.png differ diff --git a/PlantBox.Client/PlantBox.Client/Resources/Images/Luminosity_Icon.png b/PlantBox.Client/PlantBox.Client/Resources/Images/Luminosity_Icon.png new file mode 100644 index 0000000..b8cced3 Binary files /dev/null and b/PlantBox.Client/PlantBox.Client/Resources/Images/Luminosity_Icon.png differ diff --git a/PlantBox.Client/PlantBox.Client/Resources/Images/Tank_Icon.png b/PlantBox.Client/PlantBox.Client/Resources/Images/Tank_Icon.png new file mode 100644 index 0000000..4c68d85 Binary files /dev/null and b/PlantBox.Client/PlantBox.Client/Resources/Images/Tank_Icon.png differ diff --git a/PlantBox.Client/PlantBox.Client/Resources/Images/Temperature_Icon.png b/PlantBox.Client/PlantBox.Client/Resources/Images/Temperature_Icon.png new file mode 100644 index 0000000..0f4b48d Binary files /dev/null and b/PlantBox.Client/PlantBox.Client/Resources/Images/Temperature_Icon.png differ diff --git a/PlantBox.Client/PlantBox.Client/ViewModels/PlantViewModel.cs b/PlantBox.Client/PlantBox.Client/ViewModels/PlantViewModel.cs index 7acb9b8..41660a2 100644 --- a/PlantBox.Client/PlantBox.Client/ViewModels/PlantViewModel.cs +++ b/PlantBox.Client/PlantBox.Client/ViewModels/PlantViewModel.cs @@ -8,7 +8,7 @@ using System.Text; namespace PlantBox.Client.ViewModels { - class PlantViewModel : INotifyPropertyChanged + public class PlantViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; @@ -89,10 +89,30 @@ namespace PlantBox.Client.ViewModels } } + private double _tankValue; + public double TankValue + { + get => _tankValue; + set + { + if (value != _tankValue) + { + _tankValue = value; + OnPropertyChanged(); + } + } + } + private void LoadValues() { // TODO //throw new NotImplementedException(); + + // Temp + HumidityCaptor = new CaptorValue(20, 80, 21); + LuminosityCaptor = new CaptorValue(50, 1000, 375.6); + TemperatureCaptor = new CaptorValue(20, 35, 27); + TankValue = 78.45; } protected void OnPropertyChanged([CallerMemberName] string propertyName = null)