From 8b53f8ee9577a8547da37547490d39a31062bf3f Mon Sep 17 00:00:00 2001 From: Damian Suess Date: Sat, 3 Sep 2022 22:07:42 -0400 Subject: [PATCH 1/6] Moved interfaces and temp disabled --- ...IBluetoothLE.cs => IBluetoothLE.shared.cs} | 0 .../Platform/Base/Adapter.shared.cs | 2 +- .../Base/IAdapter.shared.cs} | 95 ++++++++----------- .../BLE.Client/ViewModels/BaseViewModel.cs | 1 + 4 files changed, 40 insertions(+), 58 deletions(-) rename source/Cross.BluetoothLe/{IBluetoothLE.cs => IBluetoothLE.shared.cs} (100%) rename source/Cross.BluetoothLe/{IAdapter.cs => Platform/Base/IAdapter.shared.cs} (55%) diff --git a/source/Cross.BluetoothLe/IBluetoothLE.cs b/source/Cross.BluetoothLe/IBluetoothLE.shared.cs similarity index 100% rename from source/Cross.BluetoothLe/IBluetoothLE.cs rename to source/Cross.BluetoothLe/IBluetoothLE.shared.cs diff --git a/source/Cross.BluetoothLe/Platform/Base/Adapter.shared.cs b/source/Cross.BluetoothLe/Platform/Base/Adapter.shared.cs index b045abc..ce0f978 100644 --- a/source/Cross.BluetoothLe/Platform/Base/Adapter.shared.cs +++ b/source/Cross.BluetoothLe/Platform/Base/Adapter.shared.cs @@ -9,7 +9,7 @@ namespace Cross.BluetoothLe { - public partial class Adapter // : IAdapter + public partial class Adapter //// : IAdapter { private CancellationTokenSource _scanCancellationTokenSource; private volatile bool _isScanning; diff --git a/source/Cross.BluetoothLe/IAdapter.cs b/source/Cross.BluetoothLe/Platform/Base/IAdapter.shared.cs similarity index 55% rename from source/Cross.BluetoothLe/IAdapter.cs rename to source/Cross.BluetoothLe/Platform/Base/IAdapter.shared.cs index 8e7fbdc..f32c0fe 100644 --- a/source/Cross.BluetoothLe/IAdapter.cs +++ b/source/Cross.BluetoothLe/Platform/Base/IAdapter.shared.cs @@ -2,61 +2,48 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using System.BluetoothLe.EventArgs; +using Cross.BluetoothLe.EventArgs; namespace Cross.BluetoothLe { - /// - /// The bluetooth LE Adapter. - /// + /// The bluetooth LE Adapter. public interface IAdapter { - /// - /// Occurs when the adapter receives an advertisement. - /// + /// Occurs when the adapter receives an advertisement. event EventHandler DeviceAdvertised; + /// - /// Occurs when the adapter receives an advertisement for the first time of the current scan run. - /// This means once per every call. + /// Occurs when the adapter receives an advertisement for the first time of the current scan run. + /// This means once per every call. /// event EventHandler DeviceDiscovered; - /// - /// Occurs when a device has been connected. - /// + + /// Occurs when a device has been connected. event EventHandler DeviceConnected; - /// - /// Occurs when a device has been disconnected. This occurs on intended disconnects after . - /// + + /// Occurs when a device has been disconnected. This occurs on intended disconnects after . event EventHandler DeviceDisconnected; - /// - /// Occurs when a device has been disconnected. This occurs on unintended disconnects (e.g. when the device exploded). - /// + + /// Occurs when a device has been disconnected. This occurs on unintended disconnects (e.g. when the device exploded). event EventHandler DeviceConnectionLost; - /// - /// Occurs when the scan has been stopped due the timeout after ms. - /// + + /// Occurs when the scan has been stopped due the timeout after ms. event EventHandler ScanTimeoutElapsed; - /// - /// Indicates, if the adapter is scanning for devices. - /// + /// Indicates, if the adapter is scanning for devices. bool IsScanning { get; } - /// - /// Timeout for Ble scanning. Default is 10000. - /// + /// Timeout for Ble scanning. Default is 10000. int ScanTimeout { get; set; } /// - /// Specifies the scanning mode. Must be set before calling StartScanningForDevicesAsync(). - /// Changing it while scanning, will have no change the current scan behavior. - /// Default: + /// Specifies the scanning mode. Must be set before calling StartScanningForDevicesAsync(). + /// Changing it while scanning, will have no change the current scan behavior. + /// Default: /// ScanMode ScanMode { get; set; } - /// - /// List of last discovered devices. - /// + /// List of last discovered devices. IReadOnlyList DiscoveredDevices { get; } /// @@ -65,23 +52,21 @@ public interface IAdapter IReadOnlyList ConnectedDevices { get; } /// - /// Starts scanning for BLE devices that fulfill the . - /// DeviceDiscovered will only be called, if returns true for the discovered device. + /// Starts scanning for BLE devices that fulfill the . + /// DeviceDiscovered will only be called, if returns true for the discovered device. /// /// Requested service Ids. The default is null. /// Function that filters the devices. The default is a function that returns true. - /// iOS only: If true, filtering is disabled and a discovery event is generated each time the central receives an advertising packet from the peripheral. - /// Disabling this filtering can have an adverse effect on battery life and should be used only if necessary. - /// If false, multiple discoveries of the same peripheral are coalesced into a single discovery event. - /// If the key is not specified, the default value is false. - /// For android, key is ignored. + /// iOS only: If true, filtering is disabled and a discovery event is generated each time the central receives an advertising packet from the peripheral. + /// Disabling this filtering can have an adverse effect on battery life and should be used only if necessary. + /// If false, multiple discoveries of the same peripheral are coalesced into a single discovery event. + /// If the key is not specified, the default value is false. + /// For android, key is ignored. /// The token to monitor for cancellation requests. The default value is None. /// A task that represents the asynchronous read operation. The Task will finish after the scan has ended. Task StartScanningForDevicesAsync(Guid[] serviceUuids = null, Func deviceFilter = null, bool allowDuplicatesKey = false, CancellationToken cancellationToken = default); - /// - /// Stops scanning for BLE devices. - /// + /// Stops scanning for BLE devices. /// A task that represents the asynchronous read operation. The Task will finish after the scan has ended. Task StopScanningForDevicesAsync(); @@ -96,16 +81,12 @@ public interface IAdapter /// Thrown if the is null. Task ConnectToDeviceAsync(Device device, ConnectParameters connectParameters = default, CancellationToken cancellationToken = default); - /// - /// Disconnects from the . - /// + /// Disconnects from the . /// Device to connect from. /// A task that represents the asynchronous read operation. The Task will finish after the device has been disconnected successfuly. Task DisconnectDeviceAsync(Device device); - /// - /// Connects to a device with a known GUID without scanning and if in range. Does not scan for devices. - /// + /// Connects to a device with a known GUID without scanning and if in range. Does not scan for devices. /// /// Connection parameters. Contains platform specific parameters needed to achieved connection. The default value is None. /// The token to monitor for cancellation requests. The default value is None. @@ -113,14 +94,14 @@ public interface IAdapter Task ConnectToKnownDeviceAsync(Guid deviceGuid, ConnectParameters connectParameters = default, CancellationToken cancellationToken = default); /// - /// Returns all BLE devices connected to the system. For android the implementations uses getConnectedDevices(GATT) & getBondedDevices() - /// and for ios the implementation uses get retrieveConnectedPeripherals(services) - /// https://developer.apple.com/reference/corebluetooth/cbcentralmanager/1518924-retrieveconnectedperipherals - /// - /// For android this function merges the functionality of thw following API calls: - /// https://developer.android.com/reference/android/bluetooth/BluetoothManager.html#getConnectedDevices(int) - /// https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#getBondedDevices() - /// In order to use the device in the app you have to first call ConnectAsync. + /// Returns all BLE devices connected to the system. For android the implementations uses getConnectedDevices(GATT) & getBondedDevices() + /// and for ios the implementation uses get retrieveConnectedPeripherals(services) + /// https://developer.apple.com/reference/corebluetooth/cbcentralmanager/1518924-retrieveconnectedperipherals + /// + /// For android this function merges the functionality of thw following API calls: + /// https://developer.android.com/reference/android/bluetooth/BluetoothManager.html#getConnectedDevices(int) + /// https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#getBondedDevices() + /// In order to use the device in the app you have to first call ConnectAsync. /// /// IMPORTANT: Only considered by iOS due to platform limitations. Filters devices by advertised services. SET THIS VALUE FOR ANY RESULTS /// List of Devices connected to the OS. In case of no devices the list is empty. diff --git a/source/Sample/BLE.Client/ViewModels/BaseViewModel.cs b/source/Sample/BLE.Client/ViewModels/BaseViewModel.cs index bdc5dc4..1e91c8b 100644 --- a/source/Sample/BLE.Client/ViewModels/BaseViewModel.cs +++ b/source/Sample/BLE.Client/ViewModels/BaseViewModel.cs @@ -11,6 +11,7 @@ namespace BLE.Client.ViewModels { public class BaseViewModel : MvxViewModel { + ////protected readonly IAdapter Adapter; protected readonly Adapter Adapter; protected const string DeviceIdKey = "DeviceIdNavigationKey"; protected const string ServiceIdKey = "ServiceIdNavigationKey"; From 3032c9f496be9d1800da9811007061ec5f2b51e0 Mon Sep 17 00:00:00 2001 From: Damian Suess Date: Sun, 4 Sep 2022 08:05:53 -0400 Subject: [PATCH 2/6] Added device interface --- .../Cross.BluetoothLe.csproj | 11 +- .../Platform/Android/Adapter.android.cs | 12 +- .../Platform/Base/Adapter.shared.cs | 9 +- .../Platform/Base/IAdapter.shared.cs | 13 ++- .../Platform/Base/IDevice.shared.cs | 106 ++++++++++++++++++ .../Windows/Adapter.uwp.netcore.netf.cs | 10 +- 6 files changed, 138 insertions(+), 23 deletions(-) create mode 100644 source/Cross.BluetoothLe/Platform/Base/IDevice.shared.cs diff --git a/source/Cross.BluetoothLe/Cross.BluetoothLe.csproj b/source/Cross.BluetoothLe/Cross.BluetoothLe.csproj index 15ecd9c..2ad177e 100644 --- a/source/Cross.BluetoothLe/Cross.BluetoothLe.csproj +++ b/source/Cross.BluetoothLe/Cross.BluetoothLe.csproj @@ -23,7 +23,7 @@ https://github.com/SuessLabs/Cross.BluetoothLe [1.1] -- Drop +- Reintroduced interfaces for cleaner dependency injection [1.0] - Added NET 5.x support @@ -68,7 +68,11 @@ true - + + + true + + @@ -115,4 +119,7 @@ + + + diff --git a/source/Cross.BluetoothLe/Platform/Android/Adapter.android.cs b/source/Cross.BluetoothLe/Platform/Android/Adapter.android.cs index d16aeb1..33e85c8 100644 --- a/source/Cross.BluetoothLe/Platform/Android/Adapter.android.cs +++ b/source/Cross.BluetoothLe/Platform/Android/Adapter.android.cs @@ -145,18 +145,16 @@ protected void DisconnectDeviceNative(Device device) ((Device)device).Disconnect(); } - public async Task ConnectToKnownDeviceAsync(Guid deviceGuid, ConnectParameters connectParameters = default(ConnectParameters), CancellationToken cancellationToken = default(CancellationToken), bool dontThrowExceptionOnNotFound = false) + public async Task ConnectToKnownDeviceAsync( + Guid deviceGuid, + ConnectParameters connectParameters = default(ConnectParameters), + CancellationToken cancellationToken = default(CancellationToken)) { var macBytes = deviceGuid.ToByteArray().Skip(10).Take(6).ToArray(); var nativeDevice = _bluetoothAdapter.GetRemoteDevice(macBytes); - if (nativeDevice == null) - { - if (dontThrowExceptionOnNotFound == true) - return null; - + if (nativeDevice is null) throw new DeviceNotFoundException(deviceGuid); - } var device = new Device(this, nativeDevice, null, 0, new byte[] { }); diff --git a/source/Cross.BluetoothLe/Platform/Base/Adapter.shared.cs b/source/Cross.BluetoothLe/Platform/Base/Adapter.shared.cs index ce0f978..f4f91d7 100644 --- a/source/Cross.BluetoothLe/Platform/Base/Adapter.shared.cs +++ b/source/Cross.BluetoothLe/Platform/Base/Adapter.shared.cs @@ -29,6 +29,10 @@ public partial class Adapter //// : IAdapter public event EventHandler ScanTimeoutElapsed; + public Adapter() + { + } + public bool IsScanning { get => _isScanning; @@ -36,6 +40,7 @@ public bool IsScanning } public int ScanTimeout { get; set; } = 10000; + public ScanMode ScanMode { get; set; } = ScanMode.LowPower; protected ConcurrentDictionary DiscoveredDevicesRegistry { get; } = new ConcurrentDictionary(); @@ -238,9 +243,5 @@ public void HandleConnectionFail(Device device, string errorMessage) ErrorMessage = errorMessage }); } - - public Adapter() - { - } } } diff --git a/source/Cross.BluetoothLe/Platform/Base/IAdapter.shared.cs b/source/Cross.BluetoothLe/Platform/Base/IAdapter.shared.cs index f32c0fe..9174f03 100644 --- a/source/Cross.BluetoothLe/Platform/Base/IAdapter.shared.cs +++ b/source/Cross.BluetoothLe/Platform/Base/IAdapter.shared.cs @@ -46,10 +46,9 @@ public interface IAdapter /// List of last discovered devices. IReadOnlyList DiscoveredDevices { get; } - /// - /// List of currently connected devices. - /// + /// List of currently connected devices. IReadOnlyList ConnectedDevices { get; } + ////IReadOnlyList ConnectedDevices { get; } /// /// Starts scanning for BLE devices that fulfill the . @@ -65,10 +64,12 @@ public interface IAdapter /// The token to monitor for cancellation requests. The default value is None. /// A task that represents the asynchronous read operation. The Task will finish after the scan has ended. Task StartScanningForDevicesAsync(Guid[] serviceUuids = null, Func deviceFilter = null, bool allowDuplicatesKey = false, CancellationToken cancellationToken = default); - + ////Task ScanStartAsync(Guid[] serviceUuids = null, Func deviceFilter = null, bool allowDuplicatesKey = false, CancellationToken cancellationToken = default); + /// Stops scanning for BLE devices. /// A task that represents the asynchronous read operation. The Task will finish after the scan has ended. Task StopScanningForDevicesAsync(); + ////Task ScanStopAsync(); /// /// Connects to the . @@ -80,11 +81,13 @@ public interface IAdapter /// Thrown if the device connection fails. /// Thrown if the is null. Task ConnectToDeviceAsync(Device device, ConnectParameters connectParameters = default, CancellationToken cancellationToken = default); + ////Task ConnectAsync(IDevice device, ConnectParameters connectParameters = default, CancellationToken cancellationToken = default); /// Disconnects from the . /// Device to connect from. /// A task that represents the asynchronous read operation. The Task will finish after the device has been disconnected successfuly. Task DisconnectDeviceAsync(Device device); + ////Task DisconnectAsync(Device device); /// Connects to a device with a known GUID without scanning and if in range. Does not scan for devices. /// @@ -92,6 +95,7 @@ public interface IAdapter /// The token to monitor for cancellation requests. The default value is None. /// Task ConnectToKnownDeviceAsync(Guid deviceGuid, ConnectParameters connectParameters = default, CancellationToken cancellationToken = default); + ////Task ConnectAsync(Guid deviceGuid, ConnectParameters connectParameters = default, CancellationToken cancellationToken = default); /// /// Returns all BLE devices connected to the system. For android the implementations uses getConnectedDevices(GATT) & getBondedDevices() @@ -106,5 +110,6 @@ public interface IAdapter /// IMPORTANT: Only considered by iOS due to platform limitations. Filters devices by advertised services. SET THIS VALUE FOR ANY RESULTS /// List of Devices connected to the OS. In case of no devices the list is empty. IReadOnlyList GetSystemConnectedOrPairedDevices(Guid[] services = null); + ////IReadOnlyList GetKnownDevices(Guid[] services = null); } } diff --git a/source/Cross.BluetoothLe/Platform/Base/IDevice.shared.cs b/source/Cross.BluetoothLe/Platform/Base/IDevice.shared.cs new file mode 100644 index 0000000..3f0f0ae --- /dev/null +++ b/source/Cross.BluetoothLe/Platform/Base/IDevice.shared.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace Cross.BluetoothLe.Platform.Base +{ + /// + /// A bluetooth LE device. + /// + public interface IDevice : IDisposable + { + /// + /// Id of the device. + /// + Guid Id { get; } + + /// + /// Advertised Name of the Device. + /// + string Name { get; } + + /// + /// Last known rssi value in decibals. + /// Can be updated via . + /// + int Rssi { get; } + + /// + /// Gets the native device object reference. Should be cast to the + /// appropriate type on each platform. + /// + /// The native device. + object NativeDevice { get; } + + /// + /// State of the device. + /// + DeviceState State { get; } + + /// + /// All the advertisment records + /// For example: + /// - Advertised Service UUIDS + /// - Manufacturer Specifc data + /// - ... + /// + IReadOnlyList AdvertisementRecords { get; } + + /// + /// Gets all services of the device. + /// + /// + /// A task that represents the asynchronous read operation. The Result property will contain a list of all available services. + Task> GetServicesAsync(CancellationToken cancellationToken = default); + + /// + /// Gets the first service with the Id . + /// + /// The id of the searched service. + /// + /// + /// A task that represents the asynchronous read operation. + /// The Result property will contain the service with the specified . + /// If the service doesn't exist, the Result will be null. + /// + Task GetServiceAsync(Guid id, CancellationToken cancellationToken = default); + + /// + /// Updates the rssi value. + /// + /// Important: + /// On Android: This function will only work if the device is connected. The Rssi value will be determined once on the discovery of the device. + /// + /// + /// A task that represents the asynchronous read operation. The Result property will contain a boolean that inticates if the update was successful. + /// The Task will finish after Rssi has been updated. + /// + Task UpdateRssiAsync(); + + /// + /// Requests a MTU update and fires an "Exchange MTU Request" on the ble stack. Be aware that the resulting MTU value will be negotiated between master and slave using your requested value for the negotiation. + /// + /// Important: + /// On Android: This function will only work with API level 21 and higher. Other API level will get an default value as function result. + /// On iOS: Requesting MTU sizes is not supported by iOS. The function will return the current negotiated MTU between master / slave. + /// + /// + /// A task that represents the asynchronous operation. The result contains the negotiated MTU size between master and slave + /// The requested MTU + Task RequestMtuAsync(int requestValue); + + /// + /// Requests a bluetooth-le connection update request. Be aware that this is only implemented on Android (>= API 21). + /// You can choose between a high, low and a normal mode which will requests the following connection intervals: HIGH (11-15ms). NORMAL (30-50ms). LOW (100-125ms). + /// Its not possible to request a specific connection interval. + /// + /// Important: + /// On Android: This function will only work with API level 21 and higher. Other API level will return false as function result. + /// On iOS: Updating the connection interval is not supported by iOS. The function simply returns false. + /// + /// True if the update request was sucessfull. On iOS it will always return false. + /// The requested interval (High/Low/Normal) + bool UpdateConnectionInterval(ConnectionInterval interval); + } +} diff --git a/source/Cross.BluetoothLe/Platform/Windows/Adapter.uwp.netcore.netf.cs b/source/Cross.BluetoothLe/Platform/Windows/Adapter.uwp.netcore.netf.cs index a344b1c..5bd51b4 100644 --- a/source/Cross.BluetoothLe/Platform/Windows/Adapter.uwp.netcore.netf.cs +++ b/source/Cross.BluetoothLe/Platform/Windows/Adapter.uwp.netcore.netf.cs @@ -105,7 +105,10 @@ protected void DisconnectDeviceNative(Device device) } } - public async Task ConnectToKnownDeviceAsync(Guid deviceGuid, ConnectParameters connectParameters = default, CancellationToken cancellationToken = default, bool dontThrowExceptionOnNotFound = false) + public async Task ConnectToKnownDeviceAsync( + Guid deviceGuid, + ConnectParameters connectParameters = default, + CancellationToken cancellationToken = default) { //convert GUID to string and take last 12 characters as MAC address var guidString = deviceGuid.ToString("N").Substring(20); @@ -113,12 +116,7 @@ public async Task ConnectToKnownDeviceAsync(Guid deviceGuid, ConnectPara var nativeDevice = await BluetoothLEDevice.FromBluetoothAddressAsync(bluetoothAddress); if (nativeDevice == null) - { - if (dontThrowExceptionOnNotFound == true) - return null; - throw new DeviceNotFoundException(deviceGuid); - } var knownDevice = new Device(this, nativeDevice, 0, deviceGuid); From 60deee678bde487866960113a3ab64266f9fcc93 Mon Sep 17 00:00:00 2001 From: Damian Suess Date: Thu, 22 Sep 2022 22:44:53 -0400 Subject: [PATCH 3/6] Readme and cleanup --- readme.md | 7 ++-- .../Cross.BluetoothLe.csproj | 8 ++-- .../ViewModels/DeviceListItemViewModel.cs | 16 ++++---- .../ViewModels/DeviceListViewModel.cs | 37 +++++++++---------- 4 files changed, 33 insertions(+), 35 deletions(-) diff --git a/readme.md b/readme.md index 24371c5..409f126 100644 --- a/readme.md +++ b/readme.md @@ -41,7 +41,8 @@ Android 12 and above Set in your `.appxmanifest` file ```xml - + + ``` ### iOS @@ -49,10 +50,10 @@ Set in your `.appxmanifest` file ```xml UIBackgroundModes - + bluetooth-central - + bluetooth-peripheral diff --git a/source/Cross.BluetoothLe/Cross.BluetoothLe.csproj b/source/Cross.BluetoothLe/Cross.BluetoothLe.csproj index 2ad177e..0b244a5 100644 --- a/source/Cross.BluetoothLe/Cross.BluetoothLe.csproj +++ b/source/Cross.BluetoothLe/Cross.BluetoothLe.csproj @@ -13,7 +13,9 @@ true true Cross.BluetoothLe + BluetoothLe xamarin mac ios android uwp wpf netcore dotnet tizen tvos watchos Suess Labs + Copyright © 2022 Xeno Innovations, Inc. MIT Cross-platform Bluetooth Low Energy library, based on Plugin.BLE, for Xamarin.iOS, Xamarin.Android, Mac, UWP(Preview), .Net Core 3.x, Net5.x and .Net Framework 4.6.1+(Preview - Windows 10 only - WPF and Windows.Forms), TVOS(Preview) and WatchOS(Preview), Tizen(coming soon) Cross.BluetoothLe @@ -21,6 +23,7 @@ https://github.com/SuessLabs/Cross.BluetoothLe git https://github.com/SuessLabs/Cross.BluetoothLe + readme.md [1.1] - Reintroduced interfaces for cleaner dependency injection @@ -28,10 +31,7 @@ [1.0] - Added NET 5.x support - Update windows API to 10.0.19041 - - readme.md - BluetoothLe xamarin mac ios android uwp wpf netcore dotnet tizen tvos watchos - Copyright © 2022 Xeno Innovations, Inc. + true diff --git a/source/Sample/BLE.Client/ViewModels/DeviceListItemViewModel.cs b/source/Sample/BLE.Client/ViewModels/DeviceListItemViewModel.cs index 49ae97a..ec2da20 100644 --- a/source/Sample/BLE.Client/ViewModels/DeviceListItemViewModel.cs +++ b/source/Sample/BLE.Client/ViewModels/DeviceListItemViewModel.cs @@ -4,8 +4,13 @@ namespace BLE.Client.ViewModels { - public class DeviceListItemViewModel : MvxNotifyPropertyChanged + public class DeviceListItemViewModel : MvxNotifyPropertyChanged // BindableBase { + public DeviceListItemViewModel(Device device) + { + Device = device; + } + public Device Device { get; private set; } public Guid Id => Device.Id; @@ -16,17 +21,10 @@ public class DeviceListItemViewModel : MvxNotifyPropertyChanged public string Name => Device.Name; - public DeviceListItemViewModel(Device device) - { - Device = device; - } - - public void Update(Device newDevice = null) + public void Update(Device? newDevice = null) { if (newDevice != null) - { Device = newDevice; - } RaisePropertyChanged(nameof(IsConnected)); RaisePropertyChanged(nameof(Rssi)); diff --git a/source/Sample/BLE.Client/ViewModels/DeviceListViewModel.cs b/source/Sample/BLE.Client/ViewModels/DeviceListViewModel.cs index 69cd567..bc1dd5b 100644 --- a/source/Sample/BLE.Client/ViewModels/DeviceListViewModel.cs +++ b/source/Sample/BLE.Client/ViewModels/DeviceListViewModel.cs @@ -22,10 +22,27 @@ public class DeviceListViewModel : BaseViewModel { private readonly BluetoothLE _bluetoothLe; private readonly IUserDialogs _userDialogs; - private Guid _previousGuid; private CancellationTokenSource _cancellationTokenSource; + public DeviceListViewModel(BluetoothLE bluetoothLe, Adapter adapter, IUserDialogs userDialogs) + : base(adapter) + { + _bluetoothLe = bluetoothLe; + _userDialogs = userDialogs; + + // quick and dirty :> + _bluetoothLe.StateChanged += OnStateChanged; + Adapter.DeviceDiscovered += OnDeviceDiscovered; + Adapter.DeviceAdvertised += OnDeviceDiscovered; + Adapter.ScanTimeoutElapsed += Adapter_ScanTimeoutElapsed; + Adapter.DeviceDisconnected += OnDeviceDisconnected; + Adapter.DeviceConnectionLost += OnDeviceConnectionLost; + //Adapter.DeviceConnected += (sender, e) => Adapter.DisconnectDeviceAsync(e.Device); + + Adapter.ScanMode = ScanMode.LowLatency; + } + public Guid PreviousGuid { get => _previousGuid; @@ -101,24 +118,6 @@ public ScanMode SelectedScanMode set => Adapter.ScanMode = value; } - public DeviceListViewModel(BluetoothLE bluetoothLe, Adapter adapter, IUserDialogs userDialogs) - : base(adapter) - { - _bluetoothLe = bluetoothLe; - _userDialogs = userDialogs; - - // quick and dirty :> - _bluetoothLe.StateChanged += OnStateChanged; - Adapter.DeviceDiscovered += OnDeviceDiscovered; - Adapter.DeviceAdvertised += OnDeviceDiscovered; - Adapter.ScanTimeoutElapsed += Adapter_ScanTimeoutElapsed; - Adapter.DeviceDisconnected += OnDeviceDisconnected; - Adapter.DeviceConnectionLost += OnDeviceConnectionLost; - //Adapter.DeviceConnected += (sender, e) => Adapter.DisconnectDeviceAsync(e.Device); - - Adapter.ScanMode = ScanMode.LowLatency; - } - private Task GetPreviousGuidAsync() { return Task.Run(() => From d1552e995e507b7748912938cb45a002b5fdaab9 Mon Sep 17 00:00:00 2001 From: Damian Suess Date: Thu, 22 Sep 2022 22:47:14 -0400 Subject: [PATCH 4/6] . --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index 20adee8..22b9240 100644 --- a/readme.md +++ b/readme.md @@ -69,3 +69,5 @@ Set in your `.appxmanifest` file ### Linux _Coming soon._ + +Until then check out the [Plugin.BlueZ](https://github.com/SuessLabs/Plugin.BlueZ) NuGet package for .NET Linux Bluetooth LE. From d33ca4bd64cca94dbdeb027841f9d3f0d87e87f2 Mon Sep 17 00:00:00 2001 From: Damian Suess Date: Fri, 14 Oct 2022 17:42:05 -0400 Subject: [PATCH 5/6] Property group --- source/Cross.BluetoothLe/Cross.BluetoothLe.csproj | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/Cross.BluetoothLe/Cross.BluetoothLe.csproj b/source/Cross.BluetoothLe/Cross.BluetoothLe.csproj index 0b244a5..834ecc6 100644 --- a/source/Cross.BluetoothLe/Cross.BluetoothLe.csproj +++ b/source/Cross.BluetoothLe/Cross.BluetoothLe.csproj @@ -33,9 +33,21 @@ - Update windows API to 10.0.19041 + + + true + true @@ -44,9 +56,11 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + + From 330ef97a8889c74ad317a19dc90559df758aad37 Mon Sep 17 00:00:00 2001 From: Damian Suess Date: Mon, 17 Oct 2022 13:43:55 -0400 Subject: [PATCH 6/6] c# ver 10 --- source/Sample/BLE.Client/BLE.Client.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/source/Sample/BLE.Client/BLE.Client.csproj b/source/Sample/BLE.Client/BLE.Client.csproj index e909bb4..04cc8f3 100644 --- a/source/Sample/BLE.Client/BLE.Client.csproj +++ b/source/Sample/BLE.Client/BLE.Client.csproj @@ -2,6 +2,7 @@ netstandard2.0 + 10.0