Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- Bugfix when connecting to drone and drone network

- Fixed memory leak in HUD
- Retry counter for network scan integrated
  • Loading branch information...
commit 57950aed25d3aef11bfb484b9c31304a1d16d3a6 1 parent f94dac2
@theone1984 theone1984 authored
View
9 ARDroneControlLibrary/DroneControl.cs
@@ -153,10 +153,15 @@ public void ConnectToDrone()
connecting = true;
connectToBothNetworkAndDrone = false;
- RunNetworkSanityCheck();
+ ConnectDrone();
}
}
+ private void ConnectDrone()
+ {
+ RunNetworkSanityCheck();
+ }
+
private void RunNetworkSanityCheck()
{
networkSanityChecker.CheckNetworkSanity();
@@ -179,7 +184,7 @@ private void InvokeNetworkConnectionStateChange(DroneNetworkConnectionStateChang
if (e.State == DroneNetworkConnectionState.PingSuccesful)
{
if (connectToBothNetworkAndDrone)
- ConnectToDrone();
+ ConnectDrone();
else
connecting = false;
}
View
24 ARDroneControlLibrary/Workers/NetworkConnector.cs
@@ -29,6 +29,8 @@ public class NetworkConnector : BackgroundWorker
{
private const int connectionTimeout = 10000;
private const int pingTimeout = 3000;
+
+ private const int maxScanRetries = 3;
private const int maxPingRetries = 3;
private const int notificationCodeScanSuccessful = 7;
@@ -45,6 +47,8 @@ public class NetworkConnector : BackgroundWorker
private DroneNetworkConnectionState currentState;
private int currentlyScannedNetworkInterfaceNumber;
+ private int currentScanRetries;
+
private WlanClient.WlanInterface currentWifiInterface;
private int currentPingRetries;
@@ -119,6 +123,7 @@ private void ResetProgressVariables()
currentState = DroneNetworkConnectionState.NotConnected;
currentPingRetries = 0;
+ currentScanRetries = 0;
currentlyScannedNetworkInterfaceNumber = -1;
currentWifiInterface = null;
@@ -166,10 +171,20 @@ private bool DetermineNextNetworkInterface()
private void ScanCurrentNetworkInterface()
{
- currentState = DroneNetworkConnectionState.ScanningForNewNetworks;
- UpdateConnectionStatus();
+ if (currentScanRetries < maxScanRetries)
+ {
+ currentScanRetries++;
- currentWifiInterface.Scan();
+ currentState = DroneNetworkConnectionState.ScanningForNewNetworks;
+ UpdateConnectionStatus();
+
+ currentWifiInterface.Scan();
+ }
+ else
+ {
+ AddFailureReasonForCurrentInterface("The network scan could not be completed");
+ ScanNextNetworkInterface();
+ }
}
private void AddEventHandlersToNewWifiConnection()
@@ -191,8 +206,7 @@ private void ProcessWifiNotificatioEvent(Wlan.WlanNotificationData notificationD
}
else if (notificationData.notificationCode == notificationCodeScanErroneous)
{
- AddFailureReasonForCurrentInterface("The network scan could not be completed");
- ScanNextNetworkInterface();
+ ScanCurrentNetworkInterface();
}
}
View
2  ARDroneInput/InputManager.cs
@@ -117,7 +117,7 @@ private void AddNewDevices()
newDevices.AddRange(KeyboardInput.GetNewInputDevices(windowHandle, inputDevices));
newDevices.AddRange(JoystickInput.GetNewInputDevices(windowHandle, inputDevices));
newDevices.AddRange(WiiMoteInput.GetNewInputDevices(windowHandle, inputDevices));
- //newDevices.AddRange(SpeechInput.GetNewInputDevices(windowHandle, inputDevices));
+ newDevices.AddRange(SpeechInput.GetNewInputDevices(windowHandle, inputDevices));
foreach (GenericInput inputDevice in newDevices)
{
View
11 ARDroneInput/JoystickInput.cs
@@ -43,9 +43,16 @@ public static List<GenericInput> GetNewInputDevices(IntPtr windowHandle, List<Ge
gameControllerList.MoveNext();
DeviceInstance deviceInstance = (DeviceInstance)gameControllerList.Current;
- Device device = new Device(deviceInstance.InstanceGuid);
- if (device.DeviceInformation.ProductGuid != new Guid("0306057e-0000-0000-0000-504944564944") && // Wiimotes are excluded
+ Device device = null;
+ try
+ {
+ device = new Device(deviceInstance.InstanceGuid);
+ }
+ catch (Exception)
+ { }
+
+ if (device != null && device.DeviceInformation.ProductGuid != new Guid("0306057e-0000-0000-0000-504944564944") && // Wiimotes are excluded
!CheckIfDirectInputDeviceExists(device, currentDevices))
{
AcquireDirectInputDevice(windowHandle, device, DeviceDataFormat.Joystick);
View
2  ARDroneInput/WiimoteInput.cs
@@ -171,7 +171,7 @@ void wiimote_WiimoteChanged(object sender, WiimoteChangedEventArgs e)
Dictionary<String, float> axisValues = new Dictionary<String, float>();
axisValues[Axis.Axis_X.ToString()] = state.AccelState.Values.X;
- axisValues[Axis.Axis_Y.ToString()] = state.AccelState.Values.Y;
+ axisValues[Axis.Axis_Y.ToString()] = -state.AccelState.Values.Y;
axisValues[Axis.Axis_Z.ToString()] = state.AccelState.Values.Z;
axisValues[Axis.Axis_Nunchuk_X.ToString()] = -state.NunchukState.Joystick.X * 2.0f;
View
5 HudInstruments/HudInterface.cs
@@ -94,7 +94,10 @@ public BitmapSource DrawHud(BitmapSource cameraImage)
currentBitmap = element.DrawToImage(currentBitmap, currentState);
}
- return drawingUtils.BitmapToSource(currentBitmap);
+ BitmapSource resultingSource = drawingUtils.BitmapToSource(currentBitmap);
+ currentBitmap.Dispose();
+
+ return resultingSource;
}
}
}
View
20 HudInstruments/Utils/DrawingUtils.cs
@@ -20,6 +20,9 @@ namespace ARDrone.Hud.Utils
{
public class DrawingUtils
{
+ [System.Runtime.InteropServices.DllImport("gdi32.dll")]
+ private static extern bool DeleteObject(IntPtr obj);
+
public System.Drawing.Bitmap BitmapFromSource(BitmapSource bitmapsource)
{
Bitmap bitmap;
@@ -35,10 +38,19 @@ public System.Drawing.Bitmap BitmapFromSource(BitmapSource bitmapsource)
public BitmapSource BitmapToSource(Bitmap bitmap)
{
- IntPtr bitmapPointer = bitmap.GetHbitmap();
- BitmapSizeOptions sizeOptions = BitmapSizeOptions.FromEmptyOptions();
- BitmapSource destination = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bitmapPointer, IntPtr.Zero, Int32Rect.Empty, sizeOptions);
- destination.Freeze();
+ BitmapSource destination;
+ try
+ {
+ IntPtr bitmapPointer = bitmap.GetHbitmap();
+ BitmapSizeOptions sizeOptions = BitmapSizeOptions.FromEmptyOptions();
+ destination = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bitmapPointer, IntPtr.Zero, Int32Rect.Empty, sizeOptions);
+ destination.Freeze();
+ DeleteObject(bitmapPointer);
+ }
+ catch (Exception)
+ {
+ destination = null;
+ }
return destination;
}
Please sign in to comment.
Something went wrong with that request. Please try again.