Skip to content

Commit

Permalink
Fixed WiFi switch while connected to camera wifi
Browse files Browse the repository at this point in the history
  • Loading branch information
Rambalac committed Apr 13, 2017
1 parent db1b632 commit db41fb3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 29 deletions.
4 changes: 3 additions & 1 deletion Core/Camera/Lumix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ public void Dispose()
connectCancellation.Cancel();
connectCancellation.Dispose();
http.Dispose();
stateTimer.Dispose();
}

public override bool Equals(object obj)
Expand Down Expand Up @@ -663,8 +664,9 @@ private async void StateTimer_Tick(object sender)

stateFiledTimes = 0;
}
catch (LumixException)
catch (LumixException ex)
{
Debug.WriteLine(ex);
await Disconnect(false);
}
catch (Exception)
Expand Down
17 changes: 12 additions & 5 deletions Core/Camera/LumixManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,14 @@ private void Camera_Disconnected(Lumix obj, bool stillAvailable)
foundDevices.Remove(usn + host);
Debug.WriteLine("Undiscovered: " + usn, "Discovery");
}
}
Debug.WriteLine("Remove listener: " + host, "UDP");

Debug.WriteLine("Remove listener: " + host, "UDP");
ipToLumix.TryRemove(host, out _);
usnToLumix.TryRemove(usn, out _);
}
else
{
ipToLumix.TryRemove(host, out _);
usnToLumix.TryRemove(usn, out _);
}
}

private async void DeviceLocator_DeviceAvailable(object sender, DeviceAvailableEventArgs arg)
Expand Down Expand Up @@ -217,7 +220,11 @@ private async void DeviceLocator_DeviceAvailable(object sender, DeviceAvailableE

if (usnToLumix.TryGetValue(usn, out var oldcamera))
{
await oldcamera.Disconnect();
await oldcamera.Disconnect(false);
lock (foundDevices)
{
foundDevices.Add(usn + host);
}
}

var dev = new DeviceInfo(info, usn);
Expand Down
11 changes: 2 additions & 9 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
<PackageReference Include="Nito.AsyncEx.Coordination" Version="1.0.2" />
<PackageReference Include="Rssdp" Version="3.0.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.3.1" />
<PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>C:\Users\new\.nuget\packages\Newtonsoft.Json\10.0.2\lib\netstandard1.3\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Nito.AsyncEx.Coordination">
<HintPath>C:\Users\new\.nuget\packages\Nito.AsyncEx.Coordination\1.0.2\lib\netstandard1.3\Nito.AsyncEx.Coordination.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion GMaster/Views/Models/CameraViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private void SelectedCamera_PropertyChanged(object sender, PropertyChangedEventA
{
OnPropertyChanged(nameof(IsConnectionActive));

if (selectedCamera.Camera != null)
if (selectedCamera?.Camera != null)
{
selectedCamera.Camera.PropertyChanged += Camera_PropertyChanged;
selectedCamera.Camera.OffFrameProcessor.PropertyChanged += OfframeProcessor_PropertyChanged;
Expand Down
34 changes: 21 additions & 13 deletions GMaster/Views/Models/MainPageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,28 +407,36 @@ await RunAsync(() =>
{
try
{
var camerafound = false;
var cameraauto = false;
if (GeneralSettings.Cameras.TryGetValue(dev.Uuid, out var settings))
var existing = ConnectableDevices.SingleOrDefault(d => d.Uuid == dev.Uuid);
if (existing == null)
{
cameraauto = settings.Autoconnect;
camerafound = true;
}
var camerafound = false;
var cameraauto = false;
if (GeneralSettings.Cameras.TryGetValue(dev.Uuid, out var settings))
{
cameraauto = settings.Autoconnect;
camerafound = true;
}

if ((camerafound && cameraauto) || (!camerafound && GeneralSettings.Autoconnect))
{
try
if ((camerafound && cameraauto) || (!camerafound && GeneralSettings.Autoconnect))
{
ConnectCamera(dev);
try
{
ConnectCamera(dev);
}
catch (Exception e)
{
Log.Error(e);
}
}
catch (Exception e)
else
{
Log.Error(e);
AddConnectableDevice(dev);
}
}
else
{
AddConnectableDevice(dev);
ConnectCamera(dev);
}
}
catch (Exception ex)
Expand Down

0 comments on commit db41fb3

Please sign in to comment.