Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Rambalac committed Apr 26, 2017
1 parent d68ed22 commit 869eb95
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 92 deletions.
36 changes: 18 additions & 18 deletions Core/Camera/Lumix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,24 +310,6 @@ public async Task<bool> MfAssistZoom(PinchStage stage, FloatPoint p, float size)
f => Profile.NewTouch = f);
}

private async Task<bool> OldMfAssistZoom(PinchStage stage, FloatPoint floatPoint, float size)
{
if (stage == PinchStage.Start)
{
lastOldPinchSize = size;
return true;
}

if (LumixState.CameraMode != CameraMode.MFAssist)
{
return await MfAssistMove(stage, floatPoint);
}

var val = size - lastOldPinchSize > 0 ? 10 : 5;
Debug.WriteLine("Mag val:" + val, "MFAssist");
return await TryGet($"?mode=setsetting&type=mf_asst_mag&value={val}");
}

[RunnableAction(MethodGroup.Capture)]
public async Task<bool> RecStart()
{
Expand Down Expand Up @@ -562,6 +544,24 @@ private async Task<bool> NewMfAssistMove(PinchStage stage, FloatPoint p)
return true;
}

private async Task<bool> OldMfAssistZoom(PinchStage stage, FloatPoint floatPoint, float size)
{
if (stage == PinchStage.Start)
{
lastOldPinchSize = size;
return true;
}

if (LumixState.CameraMode != CameraMode.MFAssist)
{
return await MfAssistMove(stage, floatPoint);
}

var val = size - lastOldPinchSize > 0 ? 10 : 5;
Debug.WriteLine("Mag val:" + val, "MFAssist");
return await TryGet($"?mode=setsetting&type=mf_asst_mag&value={val}");
}

private async Task<bool> OldNewAction(Func<Task<bool>> newAction, Func<Task<bool>> oldAction, bool flag, Action<bool> flagSet)
{
return await Try(async () =>
Expand Down
67 changes: 33 additions & 34 deletions Core/Camera/OffFrameProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Text;

namespace GMaster.Core.Camera
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LumixData;
using Tools;

Expand All @@ -15,6 +14,8 @@ public class OffFrameProcessor
private readonly LumixState lumixState;
private readonly CameraParser parser;

private Slice lastPrint;

public OffFrameProcessor(string deviceName, CameraParser parser, LumixState lumixState)
{
this.parser = parser;
Expand Down Expand Up @@ -75,33 +76,6 @@ public void Process(Slice slice, IntPoint size)
}
}

private Slice lastPrint;

private void PrintBytes(Slice slice)
{
Debug.WriteLine(
() =>
{
if (lastPrint == null || slice.Length != lastPrint.Length)
{
lastPrint = slice;
return string.Join(",", slice.Skip(32).Select(a => a.ToString("X2")));
}
var str = new StringBuilder();
for (int i = 0; i < slice.Length; i++)
{
str.Append(slice[i].ToString("X2"));
if (i < slice.Length - 1)
{
str.Append(slice[i] != lastPrint[i] || slice[i + 1] != lastPrint[i + 1] ? '#' : ',');
}
}
lastPrint = slice;
return str.ToString();
}, "OffFrameBytes");
}

private static string FindClosest(IReadOnlyDictionary<int, string> dict, int value)
{
var list = dict.Keys.ToList();
Expand All @@ -128,11 +102,6 @@ private static string FindClosest(IReadOnlyDictionary<int, string> dict, int val
return val2 - value > value - val1 ? dict[val1] : dict[val2];
}

private static int GetMultiplier(Slice slice)
{
return slice[46] == 0xff ? 12 : 16;
}

private static FocusAreas GetFocusPoint(Slice slice, IntPoint size)
{
var pointsNum = slice[47];
Expand Down Expand Up @@ -160,6 +129,11 @@ private static FocusAreas GetFocusPoint(Slice slice, IntPoint size)
return null;
}

private static int GetMultiplier(Slice slice)
{
return slice[46] == 0xff ? 12 : 16;
}

private TextBinValue GetFromShort(Slice slice, int index, IReadOnlyDictionary<int, string> dict)
{
var bin = slice.ToShort(index);
Expand All @@ -180,6 +154,31 @@ private TextBinValue GetFromShort(Slice slice, int index, IReadOnlyDictionary<in
}
}

private void PrintBytes(Slice slice)
{
Debug.WriteLine(
() =>
{
if (lastPrint == null || slice.Length != lastPrint.Length)
{
lastPrint = slice;
return string.Join(",", slice.Skip(32).Select(a => a.ToString("X2")));
}
var str = new StringBuilder();
for (int i = 0; i < slice.Length; i++)
{
str.Append(slice[i].ToString("X2"));
if (i < slice.Length - 1)
{
str.Append(slice[i] != lastPrint[i] || slice[i + 1] != lastPrint[i + 1] ? '#' : ',');
}
}
lastPrint = slice;
return str.ToString();
}, "OffFrameBytes");
}

private class ProcessState
{
public ProcessState(Slice array, int multiplier)
Expand Down
2 changes: 2 additions & 0 deletions Core/Tools/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ private class LogglyMessage
public string Method { get; set; }

public Severity Severity { get; set; }

public string Version { get; set; }

public string Device { get; set; }
}
}
Expand Down
7 changes: 3 additions & 4 deletions GMaster/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System.Linq;
using Windows.Security.ExchangeActiveSyncProvisioning;

namespace GMaster
namespace GMaster
{
using System;
using System.Linq;
using System.Threading.Tasks;
using Core.Tools;
using Views;
using Views.Models;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Resources;
using Windows.Security.ExchangeActiveSyncProvisioning;
using Windows.Storage;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand Down
1 change: 1 addition & 0 deletions GMaster/GMaster.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
</Compile>
<Compile Include="CubeLutParser.cs" />
<Compile Include="Views\Commands\ManualFocusAfCommand.cs" />
<Compile Include="Views\Commands\MfAssistPinpCommand.cs" />
<Compile Include="Views\Commands\TouchAfReleaseCommand.cs" />
<Compile Include="Views\Converters\FalseToVisibileConverter.cs" />
<Compile Include="Views\Converters\GreaterToTrueConverter.cs" />
Expand Down
2 changes: 1 addition & 1 deletion GMaster/Views/CameraViewControlResources.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<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" />
<Style x:Key="TransparentButtonStyle" TargetType="Button">
<Setter Property="Background" Value="Transparent" />
Expand Down
26 changes: 0 additions & 26 deletions GMaster/Views/Commands/ManualFocusAfCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,4 @@ protected override async Task InternalExecute()
}
}
}

public class MFAssistPinpCommand : AbstractModelCommand<CameraViewModel>
{
protected override bool InternalCanExecute() => true;

protected override async Task InternalExecute()
{
var lumix = Model.SelectedCamera;
if (lumix == null)
{
return;
}

try
{
if (lumix.Camera.LumixState.FocusMode == FocusMode.Manual)
{
await lumix.Camera.MfAssistPinp(false);
}
}
catch (Exception e)
{
Log.Error(e);
}
}
}
}
35 changes: 35 additions & 0 deletions GMaster/Views/Commands/MfAssistPinpCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace GMaster.Views.Commands
{
using System;
using System.Threading.Tasks;
using Core.Camera.LumixData;
using Core.Tools;
using Models;
using Tools;

public class MfAssistPinpCommand : AbstractModelCommand<CameraViewModel>
{
protected override bool InternalCanExecute() => true;

protected override async Task InternalExecute()
{
var lumix = Model.SelectedCamera;
if (lumix == null)
{
return;
}

try
{
if (lumix.Camera.LumixState.FocusMode == FocusMode.Manual)
{
await lumix.Camera.MfAssistPinp(false);
}
}
catch (Exception e)
{
Log.Error(e);
}
}
}
}
5 changes: 1 addition & 4 deletions GMaster/Views/Misc/FrameRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Windows.UI.Xaml;

namespace GMaster.Views
{
using System;
Expand Down Expand Up @@ -94,7 +92,7 @@ public void Draw(CanvasDrawingSession session, double wW, double wH, double aspe
var trans = new Vector2(box.X1, box.Y1);
var scale = new Vector2(box.Width, box.Height);
CanvasGeometry geom;
var col=Colors.White;
var col = Colors.White;
float strokeThickness = 2;

switch (box.Props.Type)
Expand All @@ -106,7 +104,6 @@ public void Draw(CanvasDrawingSession session, double wW, double wH, double aspe
col = Colors.Gold;
break;


case FocusAreaType.Eye:
geom = geomLine;
col = Colors.White;
Expand Down
2 changes: 1 addition & 1 deletion GMaster/_pkginfo.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
E:\Projects\GMaster\GMaster\bin\ARM\Release\Upload\GMaster_1.8.0.0\GMaster_1.8.0.0_x86_x64_arm.appxbundle
E:\Projects\GMaster\GMaster\bin\ARM\Release\Upload\GMaster_1.8.1.0\GMaster_1.8.1.0_x86_x64_arm.appxbundle
1 change: 0 additions & 1 deletion Tools/IObservableHashCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using Core.Tools;

public interface IObservableHashCollection : INotifyCollectionChanged, INotifyPropertyChanged
{
Expand Down
2 changes: 0 additions & 2 deletions Tools/ObservableHashCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using Core.Tools;

public class ObservableHashCollection<TItem> : HashCollection<TItem>, IObservableHashCollection
where TItem : IStringIdItem
Expand Down
1 change: 0 additions & 1 deletion Tools/SettingsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace GMaster.Tools
using System.ComponentModel;
using System.Reflection;
using System.Runtime.CompilerServices;
using Core.Tools;
using Newtonsoft.Json.Linq;

public class SettingsContainer : INotifyPropertyChanged
Expand Down

0 comments on commit 869eb95

Please sign in to comment.