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 {
|
||||
AttemptReconnect bool
|
||||
PairTimeout time.Duration
|
||||
}
|
||||
|
||||
var DefaultOptions = &Options{
|
||||
AttemptReconnect: true,
|
||||
PairTimeout: time.Minute,
|
||||
}
|
||||
|
||||
// Connect will attempt to connect to a
|
||||
@ -64,7 +62,7 @@ func Connect(opts *Options) (*Device, error) {
|
||||
// If such device does not exist
|
||||
if errors.Is(err, ErrNoDevices) {
|
||||
// Attempt to pair device
|
||||
dev, err = pair(opts.PairTimeout)
|
||||
dev, err = pair()
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -164,7 +162,7 @@ func connectByName() (*Device, error) {
|
||||
}
|
||||
|
||||
// Pair attempts to discover and pair an InfiniTime device
|
||||
func pair(timeout time.Duration) (*Device, error) {
|
||||
func pair() (*Device, error) {
|
||||
// Create new device
|
||||
out := &Device{}
|
||||
// Start bluetooth discovery
|
||||
@ -173,28 +171,22 @@ func pair(timeout time.Duration) (*Device, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
discoveryLoop:
|
||||
for {
|
||||
select {
|
||||
case event := <-discovery:
|
||||
// If device removed, skip event
|
||||
if event.Type == adapter.DeviceRemoved {
|
||||
continue
|
||||
}
|
||||
// Create new device with discovered path
|
||||
dev, err := device.NewDevice1(event.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// If device name is InfiniTime
|
||||
if dev.Properties.Name == BTName {
|
||||
// Set output device
|
||||
out.device = dev
|
||||
// Break out of discoveryLoop
|
||||
break discoveryLoop
|
||||
}
|
||||
case <-time.After(timeout):
|
||||
break discoveryLoop
|
||||
// For every discovery event
|
||||
for event := range discovery {
|
||||
// If device removed, skip event
|
||||
if event.Type == adapter.DeviceRemoved {
|
||||
continue
|
||||
}
|
||||
// Create new device with discovered path
|
||||
dev, err := device.NewDevice1(event.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// If device name is InfiniTime
|
||||
if dev.Properties.Name == BTName {
|
||||
// Set output device
|
||||
out.device = dev
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user