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