feat(windows): use ConnectionPriority for preferred connection parameters - #473
Open
acouvreur wants to merge 1 commit into
Open
feat(windows): use ConnectionPriority for preferred connection parameters#473acouvreur wants to merge 1 commit into
acouvreur wants to merge 1 commit into
Conversation
This was referenced Sep 2, 2026
acouvreur
force-pushed
the
feat/connection-priority
branch
from
September 2, 2026 19:10
7d5e8ad to
ed29352
Compare
acouvreur
force-pushed
the
feat/connection-priority-windows
branch
from
September 2, 2026 19:10
388b58a to
512baa4
Compare
…ters Windows does not accept explicit connection parameters. It has only three presets, and ConnectionPriority maps to them. Thus MinInterval, MaxInterval and Timeout have no effect on this platform. Windows applies a request only while the request object is open. If you close the object, or release the BluetoothLEDevice, Windows restores the system defaults. Therefore the device keeps the request, closes the previous request when you make a new one, and closes the last request on Disconnect. Device is a value type, thus the request is behind a pointer. The code also reads the request status. A success status shows only that the system accepted the request. These functions need Windows 11 build 22000 or later. https://learn.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.bluetoothledevice.requestpreferredconnectionparameters
acouvreur
force-pushed
the
feat/connection-priority
branch
from
September 2, 2026 19:15
ed29352 to
826dd9a
Compare
acouvreur
force-pushed
the
feat/connection-priority-windows
branch
from
September 2, 2026 19:15
512baa4 to
594f102
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is on top of #472. The difference shows only the Windows change. It replaces #423.
What this does
It sends
ConnectionParams.Priorityto the three WinRT presets.ConnectionPriorityBluetoothLEPreferredConnectionParametersThroughputThroughputOptimizedBalancedBalancedPowerSavingPowerOptimizedWindows ignores
MinInterval,MaxIntervalandTimeout, and the doc comment tells the user this. There is no method to obey them, becauseBluetoothLEPreferredConnectionParametershas no public constructor. An unsetPrioritykeeps the open request.The request is an object with a life cycle
Please look at this part with care.
RequestPreferredConnectionParametersreturns aBluetoothLEPreferredConnectionParametersRequest. This object has anIClosableinterface, and Windows applies the request only while the object is open. Microsoft tells the user to restore the defaults with a close of theBluetoothLEDevice, or with a new request.https://learn.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.bluetoothledevice.requestpreferredconnectionparameters
PR #423 discarded the object with
_, err = …. This causes a leak of a COM reference, and the garbage collector then controls the life of the request. This PR does the following instead.Deviceis a value type, thus all copies must share the same object.Disconnectcloses the request while the device is still open.The mutex is necessary because two goroutines can call
RequestConnectionParamson copies of oneDevice.The code reads the status
A success status shows only that the system accepted the request.
DeviceNotAvailableandAccessDeniedwere not visible before. The code now returns an error with the name of the status.The agreed parameters come later, in the
ConnectionParametersChangedevent. This PR does not read that event. ADevice.ConnectionParams()function is a better interface for this, and the other platforms need the same function.Requirements
These functions need Windows 11 build 22000 or later. On Windows 10 the activation factory does not exist. The error message gives the necessary build number.
This PR moves
winrt-gotov0.0.0-20260513072510-45f10383b2b8for the new bindings.Tests
go build,go vetandgo testare satisfactory. golangci-lint finds no new problems.I did not test this on real hardware yet. Before you merge this PR, I want to make sure on a Windows 11 machine that a
Throughputrequest changes the connection interval.