Remove pair timeout entirely
This commit is contained in:
parent
613a7cb044
commit
cd3daa5848
@ -41,12 +41,10 @@ var ErrNotFound = errors.New("could not find any advertising InfiniTime devices"
|
|||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
AttemptReconnect bool
|
AttemptReconnect bool
|
||||||
PairTimeout time.Duration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var DefaultOptions = &Options{
|
var DefaultOptions = &Options{
|
||||||
AttemptReconnect: true,
|
AttemptReconnect: true,
|
||||||
PairTimeout: time.Minute,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect will attempt to connect to a
|
// Connect will attempt to connect to a
|
||||||
@ -64,7 +62,7 @@ func Connect(opts *Options) (*Device, error) {
|
|||||||
// If such device does not exist
|
// If such device does not exist
|
||||||
if errors.Is(err, ErrNoDevices) {
|
if errors.Is(err, ErrNoDevices) {
|
||||||
// Attempt to pair device
|
// Attempt to pair device
|
||||||
dev, err = pair(opts.PairTimeout)
|
dev, err = pair()
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -164,7 +162,7 @@ func connectByName() (*Device, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pair attempts to discover and pair an InfiniTime device
|
// Pair attempts to discover and pair an InfiniTime device
|
||||||
func pair(timeout time.Duration) (*Device, error) {
|
func pair() (*Device, error) {
|
||||||
// Create new device
|
// Create new device
|
||||||
out := &Device{}
|
out := &Device{}
|
||||||
// Start bluetooth discovery
|
// Start bluetooth discovery
|
||||||
@ -173,10 +171,8 @@ func pair(timeout time.Duration) (*Device, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
discoveryLoop:
|
// For every discovery event
|
||||||
for {
|
for event := range discovery {
|
||||||
select {
|
|
||||||
case event := <-discovery:
|
|
||||||
// If device removed, skip event
|
// If device removed, skip event
|
||||||
if event.Type == adapter.DeviceRemoved {
|
if event.Type == adapter.DeviceRemoved {
|
||||||
continue
|
continue
|
||||||
@ -190,11 +186,7 @@ discoveryLoop:
|
|||||||
if dev.Properties.Name == BTName {
|
if dev.Properties.Name == BTName {
|
||||||
// Set output device
|
// Set output device
|
||||||
out.device = dev
|
out.device = dev
|
||||||
// Break out of discoveryLoop
|
break
|
||||||
break discoveryLoop
|
|
||||||
}
|
|
||||||
case <-time.After(timeout):
|
|
||||||
break discoveryLoop
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user