Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions gap.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,19 @@ func (buf *rawAdvertisementPayload) addServiceUUID(uuid UUID) (ok bool) {
}
}

type ConnectionLatency uint8

const (
// A latency setting that uses the default connection parameters of the system.
ConnectionLatencyDefault ConnectionLatency = 0
// A latency setting indicating that prioritizes rapid communication over battery life.
ConnectionLatencyLow ConnectionLatency = 1
// A latency setting that balances communication frequency and battery life.
ConnectionLatencyMedium ConnectionLatency = 2
// A latency setting that prioritizes extending battery life over rapid communication.
ConnectionLatencyHigh ConnectionLatency = 3
)

// ConnectionParams are used when connecting to a peripherals or when changing
// the parameters of an active connection.
type ConnectionParams struct {
Expand All @@ -604,4 +617,14 @@ type ConnectionParams struct {
// communication, the connection is considered lost. If no timeout is
// specified, the timeout will be unchanged.
Timeout Duration

// Latency setting. This is a high-level setting that indicates whether the connection should
// prioritize rapid communication or battery life.
//
// 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.

//
// If no latency is specified, the latency will be unchanged.
Latency ConnectionLatency
}
Loading