From 2488dd4f28be4658741b4ef504eb95a9620df2be Mon Sep 17 00:00:00 2001 From: onurcoskun14 Date: Tue, 20 Feb 2024 16:17:00 +0300 Subject: [PATCH 1/3] fix WaitForPropertyValueInternal --- src/Extensions.cs | 58 +++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/src/Extensions.cs b/src/Extensions.cs index 3216d09..8bdc8ce 100644 --- a/src/Extensions.cs +++ b/src/Extensions.cs @@ -144,34 +144,44 @@ public static async Task WaitForPropertyValueAsync(this IDevice1 obj, string await watchTask; } - private static (Task, IDisposable) WaitForPropertyValueInternal(IDevice1 obj, string propertyName, T value) + private static (Task, IDisposable) WaitForPropertyValueInternal(IDevice1 obj, string propertyName, T value) { - var taskSource = new TaskCompletionSource(); - - IDisposable watcher = null; - watcher = obj.WatchPropertiesAsync(propertyChanges => { - try + var taskSource = new TaskCompletionSource(); + var isCompleted = false; + + IDisposable watcher = null; + watcher = obj.WatchPropertiesAsync(propertyChanges => { - if (propertyChanges.Changed.Any(kvp => kvp.Key == propertyName)) - { - var pair = propertyChanges.Changed.Single(kvp => kvp.Key == propertyName); - if (pair.Value.Equals(value)) + try { - // Console.WriteLine($"[CHG] {propertyName}: {pair.Value}."); - taskSource.SetResult(true); - watcher.Dispose(); + if (isCompleted) + { + watcher.Dispose(); + return; + } + + if (propertyChanges.Changed.Any(kvp => kvp.Key == propertyName)) + { + var pair = propertyChanges.Changed.Single(kvp => kvp.Key == propertyName); + if (pair.Value.Equals(value)) + { + // Console.WriteLine($"[CHG] {propertyName}: {pair.Value}."); + isCompleted = true; + taskSource.SetResult(true); + watcher.Dispose(); + } + } } - } - } - catch (Exception ex) - { - Console.WriteLine($"Exception: {ex}"); - taskSource.SetException(ex); - watcher.Dispose(); - } - }); - - return (taskSource.Task, watcher); + catch (Exception ex) + { + Console.WriteLine($"Exception: {ex}"); + isCompleted = true; + taskSource.SetException(ex); + watcher.Dispose(); + } + }); + + return (taskSource.Task, watcher); } } } From 21bbc8ba6289db334f5b8e396f36223000e3d952 Mon Sep 17 00:00:00 2001 From: onurcoskun14 Date: Wed, 21 Feb 2024 08:34:25 +0300 Subject: [PATCH 2/3] .net8 upgrade --- src/DotNetBlueZ.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/DotNetBlueZ.csproj b/src/DotNetBlueZ.csproj index 7409ef8..79996ab 100644 --- a/src/DotNetBlueZ.csproj +++ b/src/DotNetBlueZ.csproj @@ -1,15 +1,15 @@ - netstandard2.0 + net8.0 HashtagChris.DotNetBlueZ HashtagChris.DotNetBlueZ - 1.3.1 - Chris Sidi + 1.0.1 + Onur Coskun Quick and dirty library for BlueZ's D-Bus APIs A quick and dirty library for BlueZ's D-Bus APIs. Focus is on Bluetooth Low Energy APIs. BlueZ;net-core;netstandard;Bluetooth;BluetoothLowEnergy;BLE @@ -19,7 +19,7 @@ - + From f3ba13b562e159a9b454651583088853accb411f Mon Sep 17 00:00:00 2001 From: onurcoskun14 Date: Wed, 21 Feb 2024 08:37:27 +0300 Subject: [PATCH 3/3] fix --- README.md | 6 +++--- manualTests/DotNetBlueZTest1/Program.cs | 4 ++-- samples/printDeviceInfo/Program.cs | 6 +++--- samples/scan/Program.cs | 4 ++-- samples/subscribeToCharacteristic/Program.cs | 4 ++-- script/nuget-push.sh | 2 +- src/Adapter.cs | 4 ++-- src/BlueZManager.cs | 2 +- src/Constants.cs | 2 +- src/DBusInterfaces.cs | 2 +- src/Device.cs | 2 +- src/DotNetBlueZ.csproj | 6 +++--- src/EventArgs.cs | 2 +- src/Extensions.cs | 2 +- src/GattCharacteristic.cs | 2 +- 15 files changed, 25 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index f653eb3..c407514 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # DotNet-BlueZ A quick and dirty library for BlueZ's D-Bus APIs. Primary focus is Bluetooth Low Energy. -[![DotNetBlueZ NuGet Badge](https://buildstats.info/nuget/HashtagChris.DotNetBlueZ?dWidth=70&includePreReleases=true)](https://www.nuget.org/packages/HashtagChris.DotNetBlueZ/) +[![DotNetBlueZ NuGet Badge](https://buildstats.info/nuget/DotnetBlueZ?dWidth=70&includePreReleases=true)](https://www.nuget.org/packages/DotnetBlueZ/) Uses [Tmds.DBus](https://github.com/tmds/Tmds.DBus) to access D-Bus. Tmds.DBus.Tool was used to generate the D-Bus object interfaces. D-Bus is the preferred interface for Bluetooth in userspace. The [Doing Bluetooth Low Energy on Linux](https://elinux.org/images/3/32/Doing_Bluetooth_Low_Energy_on_Linux.pdf) presentation says "Use D-Bus API (documentation in [doc/]((https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc))) whenever possible". @@ -13,7 +13,7 @@ Uses [Tmds.DBus](https://github.com/tmds/Tmds.DBus) to access D-Bus. Tmds.DBus.T # Installation ```bash -dotnet add package HashtagChris.DotNetBlueZ +dotnet add package DotnetBlueZ ``` # Events @@ -25,7 +25,7 @@ C# events are available for several properties. Events are useful for properly h ## Get a Bluetooth adapter ```C# -using HashtagChris.DotNetBlueZ; +using DotnetBlueZ; ... IAdapter1 adapter = (await BlueZManager.GetAdaptersAsync()).FirstOrDefault(); diff --git a/manualTests/DotNetBlueZTest1/Program.cs b/manualTests/DotNetBlueZTest1/Program.cs index 57d84cc..d64c85a 100644 --- a/manualTests/DotNetBlueZTest1/Program.cs +++ b/manualTests/DotNetBlueZTest1/Program.cs @@ -2,8 +2,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using HashtagChris.DotNetBlueZ; -using HashtagChris.DotNetBlueZ.Extensions; +using DotnetBlueZ; +using DotnetBlueZ.Extensions; namespace DotNetBlueZTest1 { diff --git a/samples/printDeviceInfo/Program.cs b/samples/printDeviceInfo/Program.cs index d014b21..1129213 100644 --- a/samples/printDeviceInfo/Program.cs +++ b/samples/printDeviceInfo/Program.cs @@ -1,5 +1,5 @@ // This program is the equivalent of the sample code posted to https://stackoverflow.com/questions/53933345/utilizing-bluetooth-le-on-raspberry-pi-using-net-core/56623587#56623587 -// This uses HashtagChris.DotNetBlueZ instead of Tmds.DBus directly. +// This uses DotnetBlueZ instead of Tmds.DBus directly. // // Use the `bluetoothctl` command-line tool or the Bluetooth Manager GUI to scan for devices and possibly pair. // Then you can use this program to connect and print "Device Information" GATT service values. @@ -7,8 +7,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using HashtagChris.DotNetBlueZ; -using HashtagChris.DotNetBlueZ.Extensions; +using DotnetBlueZ; +using DotnetBlueZ.Extensions; class Program { diff --git a/samples/scan/Program.cs b/samples/scan/Program.cs index f28ffaf..b181792 100644 --- a/samples/scan/Program.cs +++ b/samples/scan/Program.cs @@ -1,8 +1,8 @@ using System; using System.Linq; using System.Threading.Tasks; -using HashtagChris.DotNetBlueZ; -using HashtagChris.DotNetBlueZ.Extensions; +using DotnetBlueZ; +using DotnetBlueZ.Extensions; namespace Scan { diff --git a/samples/subscribeToCharacteristic/Program.cs b/samples/subscribeToCharacteristic/Program.cs index 93af09b..d81c189 100644 --- a/samples/subscribeToCharacteristic/Program.cs +++ b/samples/subscribeToCharacteristic/Program.cs @@ -2,8 +2,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using HashtagChris.DotNetBlueZ; -using HashtagChris.DotNetBlueZ.Extensions; +using DotnetBlueZ; +using DotnetBlueZ.Extensions; // An event-driven example that subscribes to one GATT characteristic and prints the value on updates. namespace subscribeToCharacteristic diff --git a/script/nuget-push.sh b/script/nuget-push.sh index eb5433a..7a515d2 100755 --- a/script/nuget-push.sh +++ b/script/nuget-push.sh @@ -10,7 +10,7 @@ SCRIPT_PATH=`dirname $0` NUGET_PKG=$1 if [ -z "$NUGET_PKG" ]; then - NUGET_PKG=`find $SCRIPT_PATH/.. -name "HashtagChris.DotNetBlueZ.*.nupkg" | sort | tail -1` + NUGET_PKG=`find $SCRIPT_PATH/.. -name "DotnetBlueZ.*.nupkg" | sort | tail -1` fi if [ -z "$NUGET_PKG" ]; then diff --git a/src/Adapter.cs b/src/Adapter.cs index 2e85b36..16698fc 100644 --- a/src/Adapter.cs +++ b/src/Adapter.cs @@ -1,10 +1,10 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using HashtagChris.DotNetBlueZ.Extensions; +using DotnetBlueZ.Extensions; using Tmds.DBus; -namespace HashtagChris.DotNetBlueZ +namespace DotnetBlueZ { public delegate Task DeviceChangeEventHandlerAsync(Adapter sender, DeviceFoundEventArgs eventArgs); diff --git a/src/BlueZManager.cs b/src/BlueZManager.cs index 8fa5dcc..c5aecd0 100644 --- a/src/BlueZManager.cs +++ b/src/BlueZManager.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; using Tmds.DBus; -namespace HashtagChris.DotNetBlueZ +namespace DotnetBlueZ { public static class BlueZManager { diff --git a/src/Constants.cs b/src/Constants.cs index 08ae230..a5876c6 100644 --- a/src/Constants.cs +++ b/src/Constants.cs @@ -1,6 +1,6 @@ using System; -namespace HashtagChris.DotNetBlueZ +namespace DotnetBlueZ { public static class BluezConstants { diff --git a/src/DBusInterfaces.cs b/src/DBusInterfaces.cs index 12a12e6..b8f9003 100644 --- a/src/DBusInterfaces.cs +++ b/src/DBusInterfaces.cs @@ -9,7 +9,7 @@ using Tmds.DBus; [assembly: InternalsVisibleTo(Tmds.DBus.Connection.DynamicAssemblyName)] -namespace HashtagChris.DotNetBlueZ +namespace DotnetBlueZ { [DBusInterface("org.freedesktop.DBus.ObjectManager")] public interface IObjectManager : IDBusObject diff --git a/src/Device.cs b/src/Device.cs index 460be94..a39b4bb 100644 --- a/src/Device.cs +++ b/src/Device.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using Tmds.DBus; -namespace HashtagChris.DotNetBlueZ +namespace DotnetBlueZ { public delegate Task DeviceEventHandlerAsync(Device sender, BlueZEventArgs eventArgs); diff --git a/src/DotNetBlueZ.csproj b/src/DotNetBlueZ.csproj index 79996ab..861cb2d 100644 --- a/src/DotNetBlueZ.csproj +++ b/src/DotNetBlueZ.csproj @@ -2,18 +2,18 @@ net8.0 - HashtagChris.DotNetBlueZ + DotnetBlueZ - HashtagChris.DotNetBlueZ + DotNetBlueZ 1.0.1 Onur Coskun Quick and dirty library for BlueZ's D-Bus APIs A quick and dirty library for BlueZ's D-Bus APIs. Focus is on Bluetooth Low Energy APIs. BlueZ;net-core;netstandard;Bluetooth;BluetoothLowEnergy;BLE - https://github.com/hashtagchris/DotNet-BlueZ + https://github.com/onurcoskun14/DotNet-BlueZ Apache-2.0 true diff --git a/src/EventArgs.cs b/src/EventArgs.cs index 1698a3e..e6dab6c 100644 --- a/src/EventArgs.cs +++ b/src/EventArgs.cs @@ -1,6 +1,6 @@ using System; -namespace HashtagChris.DotNetBlueZ +namespace DotnetBlueZ { public class BlueZEventArgs : EventArgs { diff --git a/src/Extensions.cs b/src/Extensions.cs index 8bdc8ce..6cd6d14 100644 --- a/src/Extensions.cs +++ b/src/Extensions.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; using Tmds.DBus; -namespace HashtagChris.DotNetBlueZ.Extensions +namespace DotnetBlueZ.Extensions { public static class Extensions { diff --git a/src/GattCharacteristic.cs b/src/GattCharacteristic.cs index c252024..a082204 100644 --- a/src/GattCharacteristic.cs +++ b/src/GattCharacteristic.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Tmds.DBus; -namespace HashtagChris.DotNetBlueZ +namespace DotnetBlueZ { public delegate Task GattCharacteristicEventHandlerAsync(GattCharacteristic sender, GattCharacteristicValueEventArgs eventArgs);