|
@@ -27,7 +27,7 @@ namespace InABox.Mobile
|
|
|
public List<string> SavedBlueToothMACAddresses { get; set; }
|
|
|
|
|
|
private Dictionary<String, IDevice> _devicemap = new Dictionary<string, IDevice>();
|
|
|
-
|
|
|
+
|
|
|
IBluetoothLE bluetooth = null;
|
|
|
private bool bScanning = false;
|
|
|
|
|
@@ -74,20 +74,20 @@ namespace InABox.Mobile
|
|
|
if (!_disabled)
|
|
|
throw new Exception("BT Scanning must be disabled!");
|
|
|
|
|
|
- _devicemap.TryGetValue(macaddress,out IDevice device);
|
|
|
+ _devicemap.TryGetValue(macaddress, out IDevice device);
|
|
|
if (device == null)
|
|
|
throw new Exception("Device not Found!");
|
|
|
-
|
|
|
+
|
|
|
try
|
|
|
{
|
|
|
await bluetooth.Adapter.ConnectToDeviceAsync(device);
|
|
|
if (!bluetooth.Adapter.ConnectedDevices.Contains(device))
|
|
|
throw new Exception("Cannot Connect to Device!");
|
|
|
-
|
|
|
+
|
|
|
var service = await device.GetServiceAsync(serviceid);
|
|
|
if (service == null)
|
|
|
throw new Exception("Service Not Found!");
|
|
|
-
|
|
|
+
|
|
|
var characteristic = await service.GetCharacteristicAsync(characteristicid);
|
|
|
if (characteristic == null)
|
|
|
throw new Exception("Characteristic Not Found!");
|
|
@@ -104,7 +104,7 @@ namespace InABox.Mobile
|
|
|
throw;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public bool IsScanning { get; private set; }
|
|
|
|
|
|
private async Task<bool> UnlockDevice(IDevice idevice, String key)
|
|
@@ -158,8 +158,12 @@ namespace InABox.Mobile
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(e.Device.NativeDevice.ToString()))
|
|
|
return;
|
|
|
- _devicemap[e.Device.NativeDevice.ToString()] = e.Device;
|
|
|
-
|
|
|
+
|
|
|
+ if (_devicemap.ContainsKey(e.Device.NativeDevice.ToString()))
|
|
|
+ _devicemap[e.Device.NativeDevice.ToString()] = e.Device;
|
|
|
+ else
|
|
|
+ return;
|
|
|
+
|
|
|
if (KnownBlueToothMACAddresses.Count == 0)
|
|
|
return;
|
|
|
|
|
@@ -222,7 +226,7 @@ namespace InABox.Mobile
|
|
|
{
|
|
|
if (_disabled)
|
|
|
return;
|
|
|
-
|
|
|
+
|
|
|
try
|
|
|
{
|
|
|
if (bluetooth.Adapter.IsScanning)
|