forked from Elara6331/infinitime
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,10 +171,8 @@ func pair(timeout time.Duration) (*Device, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
discoveryLoop:
|
||||
for {
|
||||
select {
|
||||
case event := <-discovery:
|
||||
// For every discovery event
|
||||
for event := range discovery {
|
||||
// If device removed, skip event
|
||||
if event.Type == adapter.DeviceRemoved {
|
||||
continue
|
||||
@ -190,11 +186,7 @@ discoveryLoop:
|
||||
if dev.Properties.Name == BTName {
|
||||
// Set output device
|
||||
out.device = dev
|
||||
// Break out of discoveryLoop
|
||||
break discoveryLoop
|
||||
}
|
||||
case <-time.After(timeout):
|
||||
break discoveryLoop
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user