Minor tweaks.
This commit is contained in:
parent
43cf503d77
commit
45863ab212
12
main.go
12
main.go
|
@ -85,7 +85,7 @@ func eventloop() {
|
|||
btns := make([]*widget.Button, 0)
|
||||
|
||||
var autoconnectID string // should load from config file
|
||||
autoconnectID = "93D3A64F-1664-497D-8B01-77951DB8E0F3"
|
||||
//autoconnectID = "93D3A64F-1664-497D-8B01-77951DB8E0F3"
|
||||
|
||||
var page, offpage, scanpage, connpage, hrpage func()
|
||||
|
||||
|
@ -112,7 +112,8 @@ func eventloop() {
|
|||
th.Button(periphs[i].Name).Layout(gtx, btns[i])
|
||||
if btns[i].Clicked(gtx) {
|
||||
b.StopScan()
|
||||
b.Connect(periphs[i])
|
||||
periph = periphs[i]
|
||||
b.Connect(periph)
|
||||
page = connpage
|
||||
w.Invalidate()
|
||||
}
|
||||
|
@ -159,6 +160,7 @@ func eventloop() {
|
|||
case e := <-events:
|
||||
switch e := e.(type) {
|
||||
case ble.UpdateStateEvent:
|
||||
fmt.Printf("UpdateState: %s\n", e.State)
|
||||
state = e.State
|
||||
if state != "powered on" {
|
||||
page = offpage
|
||||
|
@ -172,9 +174,8 @@ func eventloop() {
|
|||
b.Scan()
|
||||
}
|
||||
}
|
||||
w.Invalidate()
|
||||
case ble.DiscoverPeripheralEvent:
|
||||
fmt.Printf("found %s\n", e.Peripheral.Identifier)
|
||||
fmt.Printf("found %s (%s)\n", e.Peripheral.Name, e.Peripheral.Identifier)
|
||||
periphs = append(periphs, e.Peripheral)
|
||||
btns = append(btns, &widget.Button{})
|
||||
if e.Peripheral.Identifier == autoconnectID {
|
||||
|
@ -186,14 +187,12 @@ func eventloop() {
|
|||
periph = e.Peripheral
|
||||
e.Peripheral.DiscoverServices()
|
||||
page = hrpage
|
||||
w.Invalidate()
|
||||
case ble.ConnectTimeoutEvent:
|
||||
fmt.Printf("Connect timeout\n")
|
||||
state = "timeout"
|
||||
autoconnectID = ""
|
||||
page = scanpage
|
||||
b.Scan()
|
||||
w.Invalidate()
|
||||
case ble.DiscoverServiceEvent:
|
||||
fmt.Printf("DiscoverService %s\n", e.Gatt.UUID)
|
||||
if e.Gatt.UUID == "180D" {
|
||||
|
@ -209,6 +208,7 @@ func eventloop() {
|
|||
case ble.UpdateValueEvent:
|
||||
hr = hrDecode(e.Data)
|
||||
}
|
||||
w.Invalidate() // refresh on any Bluetooth event
|
||||
case <-tick.C:
|
||||
w.Invalidate()
|
||||
case e := <-w.Events():
|
||||
|
|
Loading…
Reference in New Issue
Block a user