From b15b1f0c3318cce39cff82ad9d4cc08414188b67 Mon Sep 17 00:00:00 2001 From: freqyXin Date: Wed, 12 May 2021 15:45:45 -0700 Subject: [PATCH] tuning sleep commands --- src/scanStuff/scanStuff.go | 12 +++++++++--- vendor/tinygo.org/x/bluetooth/gattc_linux.go | 4 +++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/scanStuff/scanStuff.go b/src/scanStuff/scanStuff.go index bd6dfa5..d0ca0bf 100644 --- a/src/scanStuff/scanStuff.go +++ b/src/scanStuff/scanStuff.go @@ -120,6 +120,9 @@ func (s *Scan) Start() error { projVars.ScanAdapter.SetConnectHandler(func(result bluetooth.Addresser, connected bool) { }) + + //time.Sleep(1 * time.Second) + TargetDevice, _ := projVars.ScanAdapter.Connect(result.Address, bluetooth.ConnectionParams{}) var targetServices []bluetooth.DeviceService @@ -134,16 +137,16 @@ func (s *Scan) Start() error { UUID: srvcs.String(), } - time.Sleep(1 * time.Second) + //time.Sleep(1 * time.Second) chars, _ := srvcs.DiscoverCharacteristics(nil) dev.Services = append(dev.Services, charSer) for _, char := range chars { - //dev.Services = append(dev.Services, ) + dev.Services = append(dev.Services) - time.Sleep(1 * time.Second) + //time.Sleep(1 * time.Second) //if char. @@ -151,6 +154,8 @@ func (s *Scan) Start() error { ReadPos, _ := char.Read(buf) println("data bytes", strconv.Itoa(ReadPos)) println("vale = ", string(buf[:ReadPos])) + println("Rawvalue = ", buf[:ReadPos]) + } sublog.Debug().Str("Connected and enumerated", charSer.UUID).Msg("Yay!") @@ -192,6 +197,7 @@ func (s *Scan) Start() error { //projVars.ScanAdapter.StopScan() //dust.Must("start scan", err) + time.Sleep(10 * time.Millisecond) return nil diff --git a/vendor/tinygo.org/x/bluetooth/gattc_linux.go b/vendor/tinygo.org/x/bluetooth/gattc_linux.go index 5591955..c972ba2 100644 --- a/vendor/tinygo.org/x/bluetooth/gattc_linux.go +++ b/vendor/tinygo.org/x/bluetooth/gattc_linux.go @@ -48,7 +48,7 @@ func (d *Device) DiscoverServices(uuids []UUID) ([]DeviceService, error) { break } // This is a terrible hack, but I couldn't find another way. - time.Sleep(40 * time.Millisecond) + time.Sleep(50 * time.Millisecond) } services := []DeviceService{} @@ -179,6 +179,8 @@ func (s *DeviceService) DiscoverCharacteristics(uuids []UUID) ([]DeviceCharacter } } + time.Sleep(50 * time.Millisecond) + if _, ok := uuidChars[char.Properties.UUID]; ok { // There is more than one characteristic with the same UUID? // Don't overwrite it, to keep the servicesFound count correct.