@@ -18,20 +18,23 @@ The primary goal of the project is to get battery level of `WH-1000XM4` headphon
1818 - [ Is Connected or Not?] ( #is-connected-or-not )
1919 - [ What Is The Last Connected Time?] ( #what-is-the-last-connected-time )
2020 - [ Headphones Battery Level] ( #headphones-battery-level )
21+ - [ Re/Connect Already Paired] ( #reconnect-already-paired )
2122- [ PnpEntity] ( #pnpentity )
2223 - [ How To Find PNP Device?] ( #how-to-find-pnp-device )
2324 - [ Get / Update Specific Device Property] ( #get--update-specific-device-property )
2425 - [ Enumerate Device Properties] ( #enumerate-device-properties )
26+ - [ Enable-Disable Device] ( #enable-disable-device )
2527- [ Device Specific Properties] ( #device-specific-properties )
2628- [ XM4 Related Properties] ( #xm4-related-properties )
2729- [ Windows Radio] ( #windows-radio )
28- - [ Links ] ( #links )
30+ - [ References ] ( #references )
2931
3032## Xm4Battery Application
3133
32- The Windows Forms, window-less and trayicon application. Ready to run app is available under the [ Latest Release] ( https://github.com/nikvoronin/WmiPnp/releases/latest ) section.
34+ The Windows Forms, trayiconed and window-less application at once.\
35+ Ready to run app is available under the [ Latest Release] ( https://github.com/nikvoronin/WmiPnp/releases/latest ) section.
3336
34- System requirements: Windows 10 x64, .NET 6.0.
37+ System requirements: Windows 10 x64, [ .NET Desktop Runtime 6.0] ( https://dotnet.microsoft.com/en-us/download/dotnet/6.0 ) .
3538
3639### User Interface
3740
@@ -92,7 +95,8 @@ statePoll.ConnectionChanged += Xm4state_ConnectionChanged;
9295statePoll .BatteryLevelChanged += Xm4state_BatteryLevelChanged ;
9396statePoll .Start ();
9497
95- Application .Run (); // run WinForms app, for ex
98+ // starts main loop of window-less WinForms app
99+ Application .Run ();
96100
97101// application was closed, quit
98102statePoll .Stop ();
@@ -101,7 +105,9 @@ statePoll.Stop();
101105### Connection Changed
102106
103107``` csharp
104- private static void Xm4state_ConnectionChanged ( object ? sender , bool connected )
108+ private static void Xm4state_ConnectionChanged (
109+ object ? sender
110+ , bool connected )
105111{
106112 var xm4 = sender as Xm4Entity ;
107113 .. .
@@ -110,7 +116,9 @@ private static void Xm4state_ConnectionChanged( object? sender, bool connected )
110116### Battery Level Changed
111117
112118```csharp
113- private static void Xm4state_BatteryLevelChanged ( object ? sender , int batteryLevel )
119+ private static void Xm4state_BatteryLevelChanged
120+ object ? sender
121+ , int batteryLevel )
114122{
115123 var xm4 = sender as Xm4Entity ;
116124 .. .
@@ -158,13 +166,21 @@ It can get the actual battery level if headphones are connected. Otherwise, head
158166int level = _xm4 .BatteryLevel ;
159167```
160168
169+ ### Re/Connect Already Paired
170+
171+ When headphones are used with multiple sources (laptop , pc , smartphone , etc ) you have to reconnect headphones from time to time . So headphones are already paired but disconnected . In this case `WmiPnp ` has experimental `Xm4Entity .TryConnect ()` and very unstable `Xm4Entity .TryDisconnect ()`. Both want the application run as administrator . Otherwise these functions are ignored .
172+
173+ If you are curious to find out about turn off bluetooth at all , see topic about [Windows Radio ](#windows - radio ).
174+
161175## PnpEntity
162176
163- First , we should know the `name ` or `device id ` of the device we are working with or at least a part of the device name .
177+ First , we should know a `name ` or `device id ` of the device we are working with or at least a part of the device name .
164178
165- - ByFriendlyName ( exact a friendly name )
166- - ByDeviceId ( exact a device id , like `{GUID } pid ` )
167- - LikeFriendlyName ( a part of a friendly name ) - returns a list of founded devices `IEnumerable < PnpEntity > ` or empty list otherwise .
179+ - ByFriendlyName - exact a friendly name .
180+ - ByDeviceId - exact a device id , like `{GUID } pid `.
181+ - LikeFriendlyName - a part of a friendly name . Returns a list of founded devices `IEnumerable < PnpEntity > ` or empty list otherwise .
182+ - EntityOrNone - a `where ` part of WQL request to retrieve exact a single device only .
183+ - EntitiesOrNone - a `where ` part of WQL request to retrieve zero , one or several devices at once .
168184
169185All of methods produce instances of `PnpEntity ` or `Result .Fail ` if the given device was not found .
170186
@@ -226,6 +242,18 @@ foreach( var p in btDevice.Properties ) {
226242 .. .
227243```
228244
245+ ### Enable-Disable Device
246+
247+ Some devices could be enabled or disabled .
248+
249+ ```csharp
250+ .. .
251+ PnpEntity btDevice = result .Value ;
252+
253+ btDevice .Disable ();
254+ btDevice .Enable ();
255+ ```
256+
229257## Device Specific Properties
230258
231259> Key = {GUID } pid
@@ -348,12 +376,9 @@ private async Task InternalBluetoothState( bool enable )
348376}
349377```
350378
351- < ! -- omit in toc -- >
352- ### Notes
353-
354- We can also use `Windows .Devices .Bluetooth ` namespace or even `Windows .Devices .*** ` for other peripheral devices .
379+ > We can also use `Windows .Devices .Bluetooth ` namespace or even `Windows .Devices .*** ` for other peripheral devices .
355380
356- ## Links
381+ ## References
357382
358383- [Enumerating windows device ](https :// www.codeproject.com/articles/14412/enumerating-windows-device). Enumerating the device using the SetupDi* API provided with WinXP. CodeProject // 17 Jun 2006
359384- Visual Basic : [How to get the details for each enumerated device ? ](https :// social.msdn.microsoft.com/Forums/en-US/65086709-cee8-4efa-a794-b32979abb0ea/how-to-get-the-details-for-each-enumerated-device?forum=vbgeneral) MSDN, Archived Forums 421-440.
0 commit comments