Skip to content

Commit

Permalink
Added Battery indicator for #15
Browse files Browse the repository at this point in the history
  • Loading branch information
Rambalac committed Apr 28, 2017
1 parent fbcda2e commit ec8858d
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Core/Camera/LumixData/CameraState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class CameraState
public OnOff AddLocationData { get; set; }

[XmlElement(ElementName = "batt")]
public string Batt { get; set; }
public string Battery { get; set; }

[XmlElement(ElementName = "burst_interval_status")]
public string BurstIntervalStatus { get; set; }
Expand Down Expand Up @@ -92,7 +92,7 @@ public override int GetHashCode()
{
unchecked
{
var hashCode = Batt?.GetHashCode() ?? 0;
var hashCode = Battery?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ (Cammode?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ Remaincapacity;
hashCode = (hashCode * 397) ^ (Sdcardstatus?.GetHashCode() ?? 0);
Expand All @@ -119,7 +119,7 @@ public override int GetHashCode()

protected bool Equals(CameraState other)
{
return string.Equals(Batt, other.Batt) &&
return string.Equals(Battery, other.Battery) &&
string.Equals(Cammode, other.Cammode) &&
Remaincapacity == other.Remaincapacity &&
string.Equals(Sdcardstatus, other.Sdcardstatus) &&
Expand Down
2 changes: 1 addition & 1 deletion GMaster.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.3
VisualStudioVersion = 15.0.26403.7
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GMaster", "GMaster\GMaster.csproj", "{F361EA15-EF81-4B2D-9D9B-B32B4D174934}"
EndProject
Expand Down
1 change: 1 addition & 0 deletions GMaster/GMaster.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
<Compile Include="Views\Commands\ManualFocusAfCommand.cs" />
<Compile Include="Views\Commands\MfAssistPinpCommand.cs" />
<Compile Include="Views\Commands\TouchAfReleaseCommand.cs" />
<Compile Include="Views\Converters\BatteryToIconConverter.cs" />
<Compile Include="Views\Converters\FalseToVisibileConverter.cs" />
<Compile Include="Views\Converters\GreaterToTrueConverter.cs" />
<Compile Include="Views\Converters\NullToFalseConverter.cs" />
Expand Down
11 changes: 9 additions & 2 deletions GMaster/Views/CameraViewControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@
</Viewbox>
</tools:PressButton>
</StackPanel>

<StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,10,100,0" Height="40">
<Viewbox>
<Viewbox.RenderTransform>
<ScaleTransform ScaleX="-1" CenterX="20"/>
</Viewbox.RenderTransform>
<TextBlock Text="{Binding BatteryLevel, Converter={StaticResource BatteryToIconConverter}}" FontFamily="Segoe MDL2 Assets" />
</Viewbox>
</StackPanel>
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Right" Height="70">
<Button Padding="-15"
Visibility="{Binding CanManualFocusAf, Mode=TwoWay, Converter={StaticResource TrueToVisibileConverter}}"
Expand All @@ -97,7 +104,7 @@
</Button>
<Button Padding="-15"
Visibility="{Binding CanManualFocusAf, Mode=TwoWay, Converter={StaticResource TrueToVisibileConverter}}"
Command="{StaticResource MFAssistPinpCommand}"
Command="{StaticResource MfAssistPinpCommand}"
Style="{StaticResource TransparentButtonStyle}">
<Viewbox>
<TextBlock Padding="5" FontFamily="Segoe MDL2 Assets" Text="&#xE191;" />
Expand Down
3 changes: 2 additions & 1 deletion GMaster/Views/CameraViewControlResources.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
<commands:RecCommand x:Key="RecCommand" Model="{Binding}" />
<commands:TouchAfReleaseCommand x:Key="TouchAfReleaseCommand" Model="{Binding}" />
<commands:ManualFocusAfCommand x:Key="ManualFocusAfCommand" Model="{Binding}" />
<commands:MfAssistPinpCommand x:Key="MFAssistPinpCommand" Model="{Binding}" />
<commands:MfAssistPinpCommand x:Key="MfAssistPinpCommand" Model="{Binding}" />
<converters:RecStateToIconConvertor x:Key="RecStateConvertor" />
<converters:BatteryToIconConverter x:Key="BatteryToIconConverter"/>
<Style x:Key="TransparentButtonStyle" TargetType="Button">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="{ThemeResource ButtonForeground}" />
Expand Down
12 changes: 12 additions & 0 deletions GMaster/Views/Converters/BatteryToIconConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace GMaster.Views.Converters
{
using System;
using Tools;

public class BatteryToIconConverter : DelegateConverter<float, string>
{
private static readonly string[] Bars = { "\xE850", "\xE851", "\xE852", "\xE853", "\xE854", "\xE855", "\xE856", "\xE857", "\xE858", "\xE859", "\xE83F" };

protected override Func<float, string> Converter => value => Bars[(int)Math.Round(value * 10f)];
}
}
30 changes: 27 additions & 3 deletions GMaster/Views/Models/CameraViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,35 @@ public ICollection<string> Apertures
public bool CanPowerZoom => lumixState?.LensInfo?.HasPowerZoom ?? false;

public bool CanReleaseTouchAf => (AutoFocusMode.ToValue<AutoFocusModeFlags>().HasFlag(AutoFocusModeFlags.TouchAFRelease)
&& FocusAreas != null && FocusAreas.Boxes.Count > 0)
&& FocusAreas != null && FocusAreas.Boxes.Count > 0)
|| lumixState?.CameraMode == CameraMode.MFAssist
|| (FocusAreas?.Boxes.Any(b => b.Props.Type == FocusAreaType.MfAssistPinP
|| b.Props.Type == FocusAreaType.MfAssistFullscreen) ?? false);
|| (FocusAreas?.Boxes.Any(b => b.Props.Type == FocusAreaType.MfAssistPinP
|| b.Props.Type == FocusAreaType.MfAssistFullscreen) ?? false);

public bool CanManualFocusAf => (lumixState?.FocusMode ?? FocusMode.Unknown) == FocusMode.Manual && (selectedCamera?.Camera.Profile.ManualFocusAF ?? false);

public int CurentZoom => lumixState?.Zoom ?? 0;

public float BatteryLevel
{
get
{
var numbers = lumixState?.State.Battery.Split('/');
if (numbers?.Length != 2)
{
return 0;
}

if (!float.TryParse(numbers[0], out var val1)
|| !int.TryParse(numbers[1], out var val2) || val2 == 0)
{
return 0;
}

return val1 / val2;
}
}

public string CurrentAperture
{
get => lumixState?.Aperture.Text;
Expand Down Expand Up @@ -312,6 +332,9 @@ await RunAsync(() =>
case nameof(LumixState.IsBusy):
OnPropertyChanged(nameof(IsConnectionActive));
break;
case nameof(LumixState.State):
OnPropertyChanged(nameof(BatteryLevel));
break;
}
}
catch (Exception ex)
Expand Down Expand Up @@ -350,6 +373,7 @@ private void RefreshAll()
OnPropertyChanged(nameof(CurentZoom));

OnPropertyChanged(nameof(FocusAreas));
OnPropertyChanged(nameof(BatteryLevel));
}
catch (Exception ex)
{
Expand Down

0 comments on commit ec8858d

Please sign in to comment.