Compare commits

..

3 Commits

Author SHA1 Message Date
fa469ac9b9 Working Android version. 2019-11-27 10:48:13 -05:00
c6a4d14f34 Larger font on Android. 2019-11-22 16:44:26 -05:00
fe2dadfa1f Some tweaks for the beginning of Android support. 2019-11-22 16:17:17 -05:00
5 changed files with 29 additions and 22 deletions

6
go.mod
View File

@ -3,7 +3,7 @@ module git.wow.st/gmp/hrm
go 1.13 go 1.13
require ( require (
gioui.org v0.0.0-20191101175813-af353822fa5e gioui.org v0.0.0-20191126175243-2ca2e5462f16
git.wow.st/gmp/ble v0.0.0-20191101185903-829baedeac2b git.wow.st/gmp/ble v0.0.0-20191127154437-321b94a48682
gopkg.in/yaml.v2 v2.2.4 gopkg.in/yaml.v2 v2.2.7
) )

18
go.sum
View File

@ -1,14 +1,8 @@
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
gioui.org v0.0.0-20191031200634-4e71f195ab51 h1:Epxo/e6oPvbDMMB8rrpmUlBe6ELeDpRuLzFUGfT6kJM= gioui.org v0.0.0-20191126175243-2ca2e5462f16 h1:p31rtmKm51xpj2QtqGNlljAyHEP1oStU8MDRl2Dv7Gs=
gioui.org v0.0.0-20191031200634-4e71f195ab51/go.mod h1:KqFFi2Dq5gYA3FJ0sDOt8OBXoMsuxMtE8v2f0JExXAY= gioui.org v0.0.0-20191126175243-2ca2e5462f16/go.mod h1:KqFFi2Dq5gYA3FJ0sDOt8OBXoMsuxMtE8v2f0JExXAY=
gioui.org v0.0.0-20191101175813-af353822fa5e h1:8NpYJwhzVg0A34MikFWRS65/PoYcluBGWZ3fgy8iXIg= git.wow.st/gmp/ble v0.0.0-20191127154437-321b94a48682 h1:8b9kt3AbWqpJwLukguXBGyUbidbgxpxrToUSX5rUSDE=
gioui.org v0.0.0-20191101175813-af353822fa5e/go.mod h1:KqFFi2Dq5gYA3FJ0sDOt8OBXoMsuxMtE8v2f0JExXAY= git.wow.st/gmp/ble v0.0.0-20191127154437-321b94a48682/go.mod h1:Fh9BYe6AckJS7dzv2LFPr/wSYVMROUwmtc01VyQmuZo=
git.wow.st/gmp/ble v0.0.0-20191030160916-4e4c07169707 h1:46SbpM1pnBe+VNUSohkKz16s/8BFY2+hzRLZEiRR1Y0=
git.wow.st/gmp/ble v0.0.0-20191030160916-4e4c07169707/go.mod h1:MiidWVofL6FTtRokC5JGBdVUhKyvZtnia5noj08r944=
git.wow.st/gmp/ble v0.0.0-20191101184817-0ab45a1d9d54 h1:Tdomh1qilIgDXWU+CksM6682BKomGKFyw3+JXcP0LLo=
git.wow.st/gmp/ble v0.0.0-20191101184817-0ab45a1d9d54/go.mod h1:MiidWVofL6FTtRokC5JGBdVUhKyvZtnia5noj08r944=
git.wow.st/gmp/ble v0.0.0-20191101185903-829baedeac2b h1:ccSukYa0YCYZEXaweXXf/103edYKBECsQjExQBTH0vE=
git.wow.st/gmp/ble v0.0.0-20191101185903-829baedeac2b/go.mod h1:MiidWVofL6FTtRokC5JGBdVUhKyvZtnia5noj08r944=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@ -34,5 +28,5 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190927191325-030b2cf1153e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190927191325-030b2cf1153e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

14
main.go
View File

@ -60,9 +60,12 @@ func saveConfig() {
} }
func hrDecode(x []byte) int { func hrDecode(x []byte) int {
if len(x) < 4 {
return 0
}
flags := x[0] flags := x[0]
if flags&0x80 != 0 { // uint16 format if flags&0x80 != 0 { // uint16 format
return int(binary.BigEndian.Uint16(x[1:2])) return int(binary.BigEndian.Uint16(x[1:3]))
} else { } else {
return int(x[1]) return int(x[1])
} }
@ -73,9 +76,9 @@ func eventloop() {
app.Size(unit.Dp(400), unit.Dp(400)), app.Size(unit.Dp(400), unit.Dp(400)),
app.Title("HRM"), app.Title("HRM"),
) )
ble.Init() // allow ble driver to set up the JVM on Android
gofont.Register() gofont.Register()
th := material.NewTheme() th := material.NewTheme()
th.TextSize = unit.Sp(fontSize)
gtx := &layout.Context{Queue: w.Queue()} gtx := &layout.Context{Queue: w.Queue()}
sysinset := &layout.Inset{} sysinset := &layout.Inset{}
@ -88,6 +91,7 @@ func eventloop() {
margin := layout.UniformInset(unit.Dp(10)) margin := layout.UniformInset(unit.Dp(10))
b := ble.NewBLE() b := ble.NewBLE()
b.Enable(w)
state := "starting" state := "starting"
var hr int var hr int
@ -240,13 +244,15 @@ func eventloop() {
b.Scan() b.Scan()
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" {
if e.Gatt.IsHRM() {
fmt.Printf("Found HRM Service\n") fmt.Printf("Found HRM Service\n")
e.Peripheral.DiscoverCharacteristics(e.Service) e.Peripheral.DiscoverCharacteristics(e.Service)
} }
case ble.DiscoverCharacteristicEvent: case ble.DiscoverCharacteristicEvent:
fmt.Printf("DiscoverCharacteristic %s\n", e.Gatt.UUID) fmt.Printf("DiscoverCharacteristic %s\n", e.Gatt.UUID)
if e.Gatt.UUID == "2A37" { //if e.Gatt.UUID == "2A37" {
if e.Gatt.IsHRV() {
fmt.Printf("Found heart rate value\n") fmt.Printf("Found heart rate value\n")
e.Peripheral.SetNotifyValue(e.Characteristic) e.Peripheral.SetNotifyValue(e.Characteristic)
} }

View File

@ -1,15 +1,21 @@
package main package main
import ( import (
"log"
"gioui.org/app" "gioui.org/app"
) )
var confDir string var confDir string
var fontSize float32 = 24
func getConfDir() string { func getConfDir() string {
if confDir != "" { if confDir == "" {
return confDir var err error
} confDir,err = app.DataDir()
confDir,_ = app.DataDir() if err != nil {
log.Fatal("Cannot get configuration directory")
}
}
return confDir return confDir
} }

View File

@ -8,6 +8,7 @@ import (
) )
var confDir string var confDir string
var fontSize float32 = 16
func getConfDir() string { func getConfDir() string {
if confDir != "" { if confDir != "" {