Begin CaptorsPage
This commit is contained in:
@@ -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?");
|
||||
}
|
||||
|
||||
throw new ArgumentException($"Invalid source: excepted 'CaptorValue' and got '${value.GetType().Name}'", nameof(value));
|
||||
return (d - lowerBound) / (upperBound - lowerBound);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,12 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:converters="clr-namespace:PlantBox.Client.Converters"
|
||||
xmlns:statusbar="clr-namespace:PlantBox.Client.Forms.Controls.StatusBar"
|
||||
xmlns:models="clr-namespace:PlantBox.Client.Models"
|
||||
xmlns:viewmodels="clr-namespace:PlantBox.Client.ViewModels"
|
||||
xmlns:extensions="clr-namespace:PlantBox.Client.Extensions"
|
||||
x:Class="PlantBox.Client.Forms.Plant.CaptorsPage">
|
||||
<ContentPage.Resources>
|
||||
<FlexBasis x:Key="BarWidth">17%</FlexBasis>
|
||||
<converters:CaptorValueToDoubleConverter x:Key="CaptorConverter" />
|
||||
</ContentPage.Resources>
|
||||
<ContentPage.Content>
|
||||
<StackLayout>
|
||||
<Label Text="Welcome to Xamarin.Forms!"
|
||||
VerticalOptions="CenterAndExpand"
|
||||
HorizontalOptions="CenterAndExpand" />
|
||||
</StackLayout>
|
||||
<FlexLayout Direction="Row"
|
||||
JustifyContent="SpaceAround"
|
||||
VerticalOptions="FillAndExpand"
|
||||
HorizontalOptions="FillAndExpand"
|
||||
Margin="20">
|
||||
<statusbar:StatusBar Progress="{Binding HumidityCaptor.Value, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Humidity}}"
|
||||
Label="{Binding HumidityCaptor.Value, StringFormat='\{0:F1} %'}"
|
||||
ForegroundColor="DeepSkyBlue"
|
||||
HintColor="SkyBlue"
|
||||
BoundColor="DarkSlateGray"
|
||||
BoundHeight="2"
|
||||
LowerBound="{Binding HumidityCaptor.Min, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Humidity}}"
|
||||
UpperBound="{Binding HumidityCaptor.Max, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Humidity}}"
|
||||
Image="{extensions:ImageResource Humidity_Icon.png}"
|
||||
FlexLayout.Basis="{StaticResource BarWidth}" />
|
||||
<statusbar:StatusBar Progress="{Binding LuminosityCaptor.Value, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Luminosity}}"
|
||||
Label="{Binding LuminosityCaptor.Value, StringFormat='\{0:F0} lux'}"
|
||||
ForegroundColor="Bisque"
|
||||
HintColor="AntiqueWhite"
|
||||
BoundColor="DarkSlateGray"
|
||||
BoundHeight="2"
|
||||
LowerBound="{Binding LuminosityCaptor.Min, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Luminosity}}"
|
||||
UpperBound="-1"
|
||||
Image="{extensions:ImageResource Luminosity_Icon.png}"
|
||||
FlexLayout.Basis="{StaticResource BarWidth}" />
|
||||
<statusbar:StatusBar Progress="{Binding TemperatureCaptor.Value, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Temperature}}"
|
||||
Label="{Binding TemperatureCaptor.Value, StringFormat='\{0:F1} °C'}"
|
||||
ForegroundColor="Crimson"
|
||||
HintColor="IndianRed"
|
||||
BoundColor="DarkSlateGray"
|
||||
BoundHeight="2"
|
||||
LowerBound="{Binding TemperatureCaptor.Min, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Temperature}}"
|
||||
UpperBound="{Binding TemperatureCaptor.Max, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Temperature}}"
|
||||
Image="{extensions:ImageResource Temperature_Icon.png}"
|
||||
FlexLayout.Basis="{StaticResource BarWidth}" />
|
||||
<statusbar:StatusBar Progress="{Binding TankValue, Converter={x:StaticResource CaptorConverter}, ConverterParameter={x:Static models:CaptorType.Tank}}"
|
||||
Label="{Binding TankValue, StringFormat='\{0:F0} %'}"
|
||||
ForegroundColor="DeepSkyBlue"
|
||||
HintColor="SkyBlue"
|
||||
BoundColor="DarkSlateGray"
|
||||
BoundHeight="2"
|
||||
LowerBound="-1"
|
||||
UpperBound="-1"
|
||||
Image="{extensions:ImageResource Tank_Icon.png}"
|
||||
FlexLayout.Basis="{StaticResource BarWidth}" />
|
||||
|
||||
</FlexLayout>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
||||
@@ -12,9 +12,9 @@ namespace PlantBox.Client.Forms.Plant
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class CaptorsPage : ContentPage
|
||||
{
|
||||
public CaptorsPage ()
|
||||
public CaptorsPage()
|
||||
{
|
||||
InitializeComponent ();
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
14
PlantBox.Client/PlantBox.Client/Models/CaptorType.cs
Normal file
14
PlantBox.Client/PlantBox.Client/Models/CaptorType.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace PlantBox.Client.Models
|
||||
{
|
||||
enum CaptorType
|
||||
{
|
||||
Humidity,
|
||||
Luminosity,
|
||||
Tank,
|
||||
Temperature
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using System.Text;
|
||||
|
||||
namespace PlantBox.Client.Models
|
||||
{
|
||||
class Historic
|
||||
public class Historic
|
||||
{
|
||||
public HistoricEntry MinutelyHistoric { get; }
|
||||
public HistoricEntry HourlyHistoric { get; }
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Text;
|
||||
|
||||
namespace PlantBox.Client.Models
|
||||
{
|
||||
class HistoricEntry
|
||||
public class HistoricEntry
|
||||
{
|
||||
public DateTime LastTime { get; }
|
||||
public TimeSpan TimeInterval { get; }
|
||||
|
||||
@@ -15,18 +15,26 @@
|
||||
<None Remove="Resources\Images\Banner.png" />
|
||||
<None Remove="Resources\Images\Help.png" />
|
||||
<None Remove="Resources\Images\Home.png" />
|
||||
<None Remove="Resources\Images\Humidity_Icon.png" />
|
||||
<None Remove="Resources\Images\Info.png" />
|
||||
<None Remove="Resources\Images\Logo_Gray.png" />
|
||||
<None Remove="Resources\Images\Luminosity_Icon.png" />
|
||||
<None Remove="Resources\Images\Settings.png" />
|
||||
<None Remove="Resources\Images\Tank_Icon.png" />
|
||||
<None Remove="Resources\Images\Temperature_Icon.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\Images\Banner.png" />
|
||||
<EmbeddedResource Include="Resources\Images\Help.png" />
|
||||
<EmbeddedResource Include="Resources\Images\Home.png" />
|
||||
<EmbeddedResource Include="Resources\Images\Humidity_Icon.png" />
|
||||
<EmbeddedResource Include="Resources\Images\Info.png" />
|
||||
<EmbeddedResource Include="Resources\Images\Logo_Gray.png" />
|
||||
<EmbeddedResource Include="Resources\Images\Luminosity_Icon.png" />
|
||||
<EmbeddedResource Include="Resources\Images\Settings.png" />
|
||||
<EmbeddedResource Include="Resources\Images\Tank_Icon.png" />
|
||||
<EmbeddedResource Include="Resources\Images\Temperature_Icon.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
BIN
PlantBox.Client/PlantBox.Client/Resources/Images/Tank_Icon.png
Normal file
BIN
PlantBox.Client/PlantBox.Client/Resources/Images/Tank_Icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user