Skip to content

feat(gap): add ConnectionLatency in ConnectionParams#422

Open
acouvreur wants to merge 1 commit intotinygo-org:devfrom
acouvreur:add-connection-latency
Open

feat(gap): add ConnectionLatency in ConnectionParams#422
acouvreur wants to merge 1 commit intotinygo-org:devfrom
acouvreur:add-connection-latency

Conversation

@acouvreur
Copy link
Copy Markdown
Contributor

@acouvreur acouvreur commented Mar 17, 2026

These settings are alternatives for platforms that do not support settings the MinInterval and MaxInterval directly.

I will follow up with a pull request adding support for Windows.
Edit: here is the follow up pull request: #423

The current enumeration is heavily inspired from https://developer.apple.com/documentation/corebluetooth/cbperipheralmanagerconnectionlatency

However, we could also use the enumeration from windows:

  • ThroughputOptimized
  • Balanced
  • PowerOptimized

What do you think @deadprogram ?

These settings are alternatives for platforms that do not support settings the MinInterval and MaxInterval directly.
//
// Some platforms (e.g. Windows) may not support setting the connection parameters directly,
// but may support setting a latency level that corresponds to a set of connection parameters.
// In this case, the Latency field can be used to set the latency level instead of setting the connection parameters directly.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wonder about this, in part because that would probably mean we need to decide what connection params would be associated with a latency level for platforms where it does not exist.

Maybe we should go the other direction, meaning determine what latency would best match a set of connection params?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can create named ConnectionParams with a pre-defined set of values.

Then depending on the platform, they may use that how they want.

But what happens when using a non pre-defined for platforms that only support pre-defined set ?


Let me update the PR with the suggestions

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmmh. I wanted to do something like

var lowLatencyConnectionParams = ConnectionParams{
	MinInterval: NewDuration(7.5 * time.Millisecond),
	MaxInterval: NewDuration(15 * time.Millisecond),
	Timeout:     NewDuration(4 * time.Second),
}

var mediumLatencyConnectionParams = ConnectionParams{
	MinInterval: NewDuration(15 * time.Millisecond),
	MaxInterval: NewDuration(30 * time.Millisecond),
	Timeout:     NewDuration(4 * time.Second),
}

var highLatencyConnectionParams = ConnectionParams{
	MinInterval: NewDuration(30 * time.Millisecond),
	MaxInterval: NewDuration(60 * time.Millisecond),
	Timeout:     NewDuration(4 * time.Second),
}

func ConnectionParamsLowLatency() ConnectionParams {
	return lowLatencyConnectionParams
}

func ConnectionParamsMediumLatency() ConnectionParams {
	return mediumLatencyConnectionParams
}

func ConnectionParamsHighLatency() ConnectionParams {
	return highLatencyConnectionParams
}

But I don't like it.

I wanted to be able to do some equality comparison on windows for example but it won't work as I expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants