Compare commits
No commits in common. "91fbe718e551979c4f57f5e553c510eddec30925" and "ea488067fb9b80d65c12449b702861aec933d1af" have entirely different histories.
91fbe718e5
...
ea488067fb
@ -39,14 +39,13 @@ type Device struct {
|
||||
var ErrNoDevices = errors.New("no InfiniTime devices found")
|
||||
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 +63,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(dev.opts.PairTimeout)
|
||||
dev, err = pair()
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -151,10 +150,7 @@ func connectByName() (*Device, error) {
|
||||
return nil, ErrNoDevices
|
||||
}
|
||||
// Connect to device
|
||||
err = out.device.Connect()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out.device.Connect()
|
||||
// Resolve characteristics
|
||||
err = out.resolveChars()
|
||||
if err != nil {
|
||||
@ -164,7 +160,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
|
||||
@ -194,7 +190,7 @@ discoveryLoop:
|
||||
// Break out of discoveryLoop
|
||||
break discoveryLoop
|
||||
}
|
||||
case <-time.After(timeout):
|
||||
case <-time.After(5 * time.Second):
|
||||
break discoveryLoop
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user