Compare commits
11
Commits
265caa30a2
...
v1.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
087b6d3d06 | ||
|
|
6c00897583 | ||
|
|
acf0e7efe9 | ||
|
|
9484ffac99 | ||
|
|
52806e3f6b | ||
|
|
94638e9710 | ||
|
|
363ada0b85 | ||
|
|
81ee9c3c2b | ||
|
|
6e020858d9 | ||
|
|
31fa374c7f | ||
|
|
14bbbf0679 |
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
hrm
|
hrm/hrm
|
||||||
*.apk
|
*.apk
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2019 Gregory Pomerantz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
@@ -2,11 +2,16 @@
|
|||||||
|
|
||||||
An example heart rate monitor app for Android and MacOS using [git.wow.st/gmp/ble](https://git.wow.st/gmp/ble) and [Gio](https://gioui.org).
|
An example heart rate monitor app for Android and MacOS using [git.wow.st/gmp/ble](https://git.wow.st/gmp/ble) and [Gio](https://gioui.org).
|
||||||
|
|
||||||
|
The MacOS implementation uses a Core Bluetooth binding created by
|
||||||
|
[NSWrap](https://git.wow.st/gmp/nswrap). On Android, Martijn van Welie's
|
||||||
|
[Blessed](https://github.com/weliem/blessed-android) library is used to
|
||||||
|
simplify access to the Bluetooth Low-Energy hardware.
|
||||||
|
|
||||||
## MacOS:
|
## MacOS:
|
||||||
|
|
||||||
```
|
```
|
||||||
go get git.wow.st/gmp/hrm
|
git clone https://git.wow.st/gmp/hrm
|
||||||
cd ~/go/src/git.wow.st/gmp/hrm
|
cd hrm/hrm
|
||||||
go build
|
go build
|
||||||
./hrm
|
./hrm
|
||||||
```
|
```
|
||||||
@@ -17,8 +22,13 @@ The `gogio` command from `gioui.org/cmd/gogio` must be installed to build
|
|||||||
an Android APK.
|
an Android APK.
|
||||||
|
|
||||||
```
|
```
|
||||||
go get git.wow.st/gmp/hrm
|
git clone https://git.wow.st/gmp/hrm
|
||||||
cd ~/go/src/git.wow.st/gmp/hrm
|
cd hrm/hrm
|
||||||
gogio -target android .
|
gogio -target android .
|
||||||
adb install -r hrm.apk
|
adb install -r hrm.apk
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The compiled Java code for the Android implementation is pre-packaged in
|
||||||
|
jar files. If you want to, you can re-compile these dependencies by running
|
||||||
|
`go generate` from the `depjars` directory. You will need to have `gradle`,
|
||||||
|
an Android SDK, and who knows what else installed on your machine.
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
//go:generate go generate git.wow.st/gmp/ble/depjars
|
||||||
|
|
||||||
|
package main
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
Simple bluetooth low-energy heart rate monitor with a stopwatch function to
|
||||||
|
time your workouts. Automatically connects to your last-used peripheral or you
|
||||||
|
can scan for nearby bluetooth devices.
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 62 KiB |
@@ -0,0 +1 @@
|
|||||||
|
Simple bluetooth low-energy heart rate monitor
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
+1
-1
@@ -4,7 +4,7 @@ go 1.13
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
gioui.org v0.0.0-20191126175243-2ca2e5462f16
|
gioui.org v0.0.0-20191126175243-2ca2e5462f16
|
||||||
git.wow.st/gmp/ble v0.0.0-20191205134941-3bc712870db2
|
git.wow.st/gmp/ble v0.0.0-20191230162624-2d7594514cb3
|
||||||
github.com/google/go-github/v24 v24.0.1 // indirect
|
github.com/google/go-github/v24 v24.0.1 // indirect
|
||||||
golang.org/x/oauth2 v0.0.0-20191122200657-5d9234df094c // indirect
|
golang.org/x/oauth2 v0.0.0-20191122200657-5d9234df094c // indirect
|
||||||
gopkg.in/yaml.v2 v2.2.7
|
gopkg.in/yaml.v2 v2.2.7
|
||||||
@@ -9,6 +9,20 @@ git.wow.st/gmp/ble v0.0.0-20191204220614-4cdaceda7601/go.mod h1:Fh9BYe6AckJS7dzv
|
|||||||
git.wow.st/gmp/ble v0.0.0-20191204222510-e7f82ac9e7f9/go.mod h1:Fh9BYe6AckJS7dzv2LFPr/wSYVMROUwmtc01VyQmuZo=
|
git.wow.st/gmp/ble v0.0.0-20191204222510-e7f82ac9e7f9/go.mod h1:Fh9BYe6AckJS7dzv2LFPr/wSYVMROUwmtc01VyQmuZo=
|
||||||
git.wow.st/gmp/ble v0.0.0-20191205134941-3bc712870db2 h1:yYtHMSaVp/dqxuv/GA63C7xIGbN9mrSICEZB3NHdrzc=
|
git.wow.st/gmp/ble v0.0.0-20191205134941-3bc712870db2 h1:yYtHMSaVp/dqxuv/GA63C7xIGbN9mrSICEZB3NHdrzc=
|
||||||
git.wow.st/gmp/ble v0.0.0-20191205134941-3bc712870db2/go.mod h1:Fh9BYe6AckJS7dzv2LFPr/wSYVMROUwmtc01VyQmuZo=
|
git.wow.st/gmp/ble v0.0.0-20191205134941-3bc712870db2/go.mod h1:Fh9BYe6AckJS7dzv2LFPr/wSYVMROUwmtc01VyQmuZo=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191206192216-c6f6e4f3174d h1:ur7fwGJ/P92xYTAvczK5VrtnFXDAlStlnK+kAAy4mjc=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191206192216-c6f6e4f3174d/go.mod h1:Fh9BYe6AckJS7dzv2LFPr/wSYVMROUwmtc01VyQmuZo=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191206212213-ca70d55f7ed5 h1:Zo9nEEbm7eHW9vA5jWkI10lJC2rpSoNjsc1W1MA2woA=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191206212213-ca70d55f7ed5/go.mod h1:Fh9BYe6AckJS7dzv2LFPr/wSYVMROUwmtc01VyQmuZo=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191210141332-1601787ecfa0 h1:EGEsiQf4Ke36NxTkdr6dTBPdCVd032NMCK1I/n4hWwY=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191210141332-1601787ecfa0/go.mod h1:Fh9BYe6AckJS7dzv2LFPr/wSYVMROUwmtc01VyQmuZo=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191211145827-dd7d927044f3 h1:EI7VhFijk85f3kcJ301QaHvxoDhQChAzfzlByrnpW0g=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191211145827-dd7d927044f3/go.mod h1:Fh9BYe6AckJS7dzv2LFPr/wSYVMROUwmtc01VyQmuZo=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191213173536-99bfee1cbdbf h1:LBqP/fMUR0FZN7YwiwuZ6i5XhgDzpOqMhUhZTA4+s/A=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191213173536-99bfee1cbdbf/go.mod h1:Fh9BYe6AckJS7dzv2LFPr/wSYVMROUwmtc01VyQmuZo=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191213182030-52217c3f6a2f h1:rLZaIsaH0Ai7W6sWunN16dQ9rRTuvRcegZS/nkNbPpU=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191213182030-52217c3f6a2f/go.mod h1:Fh9BYe6AckJS7dzv2LFPr/wSYVMROUwmtc01VyQmuZo=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191230162624-2d7594514cb3 h1:rMmx9qz3lb6kdzKzU2cJgb9opi+W/YQwtAbbjSCmVGg=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191230162624-2d7594514cb3/go.mod h1:Fh9BYe6AckJS7dzv2LFPr/wSYVMROUwmtc01VyQmuZo=
|
||||||
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=
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
+222
-48
@@ -9,6 +9,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.wow.st/gmp/ble"
|
"git.wow.st/gmp/ble"
|
||||||
|
|
||||||
@@ -77,9 +78,25 @@ func hrDecode(x []byte) int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Stopwatch struct {
|
||||||
|
lasttime time.Time
|
||||||
|
elapsed time.Time
|
||||||
|
running bool
|
||||||
|
startstopBtn *widget.Button
|
||||||
|
resetBtn *widget.Button
|
||||||
|
h, m, s int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewStopwatch() Stopwatch {
|
||||||
|
return Stopwatch{
|
||||||
|
startstopBtn: &widget.Button{},
|
||||||
|
resetBtn: &widget.Button{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func eventloop() {
|
func eventloop() {
|
||||||
w := app.NewWindow(
|
w := app.NewWindow(
|
||||||
app.Size(unit.Dp(400), unit.Dp(400)),
|
app.Size(unit.Dp(350), unit.Dp(600)),
|
||||||
app.Title("HRM"),
|
app.Title("HRM"),
|
||||||
)
|
)
|
||||||
gofont.Register()
|
gofont.Register()
|
||||||
@@ -102,6 +119,7 @@ func eventloop() {
|
|||||||
state := "starting"
|
state := "starting"
|
||||||
var hr int
|
var hr int
|
||||||
var periph ble.Peripheral
|
var periph ble.Peripheral
|
||||||
|
var wide bool
|
||||||
periphs := make([]ble.Peripheral, 0)
|
periphs := make([]ble.Peripheral, 0)
|
||||||
btns := make([]*widget.Button, 0)
|
btns := make([]*widget.Button, 0)
|
||||||
backBtn := &widget.Button{}
|
backBtn := &widget.Button{}
|
||||||
@@ -110,22 +128,42 @@ func eventloop() {
|
|||||||
|
|
||||||
f := &layout.Flex{Axis: layout.Vertical}
|
f := &layout.Flex{Axis: layout.Vertical}
|
||||||
offpage = func() {
|
offpage = func() {
|
||||||
c1 := f.Rigid(gtx, func() {
|
f.Layout(gtx,
|
||||||
|
f.Rigid(gtx, func() {
|
||||||
th.Body1("Heart Rate Monitor").Layout(gtx)
|
th.Body1("Heart Rate Monitor").Layout(gtx)
|
||||||
})
|
}),
|
||||||
c2 := f.Rigid(gtx, func() {
|
f.Rigid(gtx, func() {
|
||||||
th.Body1("Bluetooth is Powered Off").Layout(gtx)
|
th.Body1("Bluetooth is Powered Off").Layout(gtx)
|
||||||
})
|
}),
|
||||||
f.Layout(gtx, c1, c2)
|
)
|
||||||
}
|
}
|
||||||
scanpage = func() {
|
|
||||||
c1 := f.Rigid(gtx, func() {
|
appname := func() {
|
||||||
|
layout.Align(layout.Center).Layout(gtx, func() {
|
||||||
th.Body1("Heart Rate Monitor").Layout(gtx)
|
th.Body1("Heart Rate Monitor").Layout(gtx)
|
||||||
})
|
})
|
||||||
c2 := f.Rigid(gtx, func() {
|
}
|
||||||
|
appstate := func() {
|
||||||
|
layout.Align(layout.Center).Layout(gtx, func() {
|
||||||
th.Body1(state).Layout(gtx)
|
th.Body1(state).Layout(gtx)
|
||||||
})
|
})
|
||||||
c3 := f.Rigid(gtx, func() {
|
}
|
||||||
|
periphname := func() {
|
||||||
|
layout.Align(layout.Center).Layout(gtx, func() {
|
||||||
|
th.Body1(periph.Name).Layout(gtx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
leftbar := func() {
|
||||||
|
f := &layout.Flex{Axis: layout.Vertical}
|
||||||
|
f.Layout(gtx,
|
||||||
|
f.Rigid(gtx, appname),
|
||||||
|
f.Rigid(gtx, func() { th.Body1("").Layout(gtx) }),
|
||||||
|
f.Rigid(gtx, appstate),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
scanlist := func() {
|
||||||
lst := &layout.List{Axis: layout.Vertical}
|
lst := &layout.List{Axis: layout.Vertical}
|
||||||
lst.Layout(gtx, len(periphs), func(i int) {
|
lst.Layout(gtx, len(periphs), func(i int) {
|
||||||
gtx.Constraints.Width.Min = gtx.Constraints.Width.Max
|
gtx.Constraints.Width.Min = gtx.Constraints.Width.Max
|
||||||
@@ -141,21 +179,30 @@ func eventloop() {
|
|||||||
w.Invalidate()
|
w.Invalidate()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
f.Layout(gtx, c1, c2, c3)
|
|
||||||
|
scanpage = func() {
|
||||||
|
if wide {
|
||||||
|
f2 := &layout.Flex{Axis: layout.Horizontal}
|
||||||
|
f2.Layout(gtx,
|
||||||
|
f2.Flex(gtx, 0.2, leftbar),
|
||||||
|
f2.Rigid(gtx, scanlist),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
f.Layout(gtx,
|
||||||
|
f.Rigid(gtx, appname),
|
||||||
|
f.Rigid(gtx, appstate),
|
||||||
|
f.Rigid(gtx, scanlist),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connpage = func() {
|
connpage = func() {
|
||||||
c1 := f.Rigid(gtx, func() {
|
f.Layout(gtx,
|
||||||
th.Body1("Heart Rate Monitor").Layout(gtx)
|
f.Rigid(gtx, appname),
|
||||||
})
|
f.Rigid(gtx, appstate),
|
||||||
c2 := f.Rigid(gtx, func() {
|
f.Rigid(gtx, periphname),
|
||||||
th.Body1("Connecting").Layout(gtx)
|
f.Rigid(gtx, func() {
|
||||||
})
|
|
||||||
c3 := f.Rigid(gtx, func() {
|
|
||||||
th.Body1(periph.Name).Layout(gtx)
|
|
||||||
})
|
|
||||||
c4 := f.Rigid(gtx, func() {
|
|
||||||
th.Button("Cancel").Layout(gtx, backBtn)
|
th.Button("Cancel").Layout(gtx, backBtn)
|
||||||
if backBtn.Clicked(gtx) {
|
if backBtn.Clicked(gtx) {
|
||||||
ble.CancelConnection(periph)
|
ble.CancelConnection(periph)
|
||||||
@@ -166,35 +213,16 @@ func eventloop() {
|
|||||||
state = "scanning"
|
state = "scanning"
|
||||||
page = scanpage
|
page = scanpage
|
||||||
}
|
}
|
||||||
})
|
}),
|
||||||
f.Layout(gtx, c1, c2, c3, c4)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
hrpage = func() {
|
hrcircle := func() int {
|
||||||
c1 := f.Rigid(gtx, func() {
|
var w, h1 float32
|
||||||
th.Body1("Heart Rate Monitor").Layout(gtx)
|
layout.Align(layout.Center).Layout(gtx, func() {
|
||||||
})
|
|
||||||
c2 := f.Rigid(gtx, func() {
|
|
||||||
th.Body1(periph.Name).Layout(gtx)
|
|
||||||
})
|
|
||||||
c4 := f.Rigid(gtx, func() {
|
|
||||||
layout.UniformInset(unit.Dp(2)).Layout(gtx, func() {
|
|
||||||
th.Button("Stop").Layout(gtx, backBtn)
|
|
||||||
})
|
|
||||||
if backBtn.Clicked(gtx) {
|
|
||||||
ble.Disconnect(periph)
|
|
||||||
periphs = periphs[:0]
|
|
||||||
Config.Autoconnect = ""
|
|
||||||
saveConfig()
|
|
||||||
b.Scan()
|
|
||||||
state = "scanning"
|
|
||||||
page = scanpage
|
|
||||||
}
|
|
||||||
})
|
|
||||||
c3 := f.Rigid(gtx, func() {
|
|
||||||
blue := color.RGBA{0x3f, 0x51, 0xb5, 255}
|
blue := color.RGBA{0x3f, 0x51, 0xb5, 255}
|
||||||
white := color.RGBA{255, 255, 255, 255}
|
white := color.RGBA{255, 255, 255, 255}
|
||||||
w, h1 := float32(gtx.Constraints.Width.Max), float32(gtx.Constraints.Height.Max)
|
w, h1 = float32(gtx.Constraints.Width.Max), float32(gtx.Constraints.Height.Max)
|
||||||
if w < h1 {
|
if w < h1 {
|
||||||
h1 = w
|
h1 = w
|
||||||
}
|
}
|
||||||
@@ -221,13 +249,154 @@ func eventloop() {
|
|||||||
})
|
})
|
||||||
gtx.Dimensions.Size = image.Point{int(h1), int(h1)}
|
gtx.Dimensions.Size = image.Point{int(h1), int(h1)}
|
||||||
})
|
})
|
||||||
f.Layout(gtx, c1, c2, c3, c4)
|
return int(h1)
|
||||||
|
}
|
||||||
|
|
||||||
|
sw := NewStopwatch()
|
||||||
|
|
||||||
|
stopwatch := func() {
|
||||||
|
startstoptxt := "start"
|
||||||
|
if sw.running {
|
||||||
|
sw.elapsed = sw.elapsed.Add(time.Since(sw.lasttime))
|
||||||
|
startstoptxt = "stop"
|
||||||
|
}
|
||||||
|
sw.lasttime = time.Now()
|
||||||
|
f := layout.Flex{Axis: layout.Vertical}
|
||||||
|
f.Layout(gtx,
|
||||||
|
f.Rigid(gtx, func() {
|
||||||
|
layout.Align(layout.Center).Layout(gtx, func() {
|
||||||
|
gtx.Constraints.Width.Max = 1e6
|
||||||
|
th.H4(sw.elapsed.Format("15:04:05.00")).Layout(gtx)
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
f.Rigid(gtx, func() {
|
||||||
|
f2 := layout.Flex{Axis: layout.Horizontal}
|
||||||
|
gtx.Constraints.Height.Min = 100
|
||||||
|
f2.Layout(gtx,
|
||||||
|
f2.Flex(gtx, 0.5, func() {
|
||||||
|
layout.UniformInset(unit.Dp(2)).Layout(gtx, func() {
|
||||||
|
th.Button(startstoptxt).Layout(gtx, sw.startstopBtn)
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
f2.Flex(gtx, 0.5, func() {
|
||||||
|
layout.UniformInset(unit.Dp(2)).Layout(gtx, func() {
|
||||||
|
th.Button("reset").Layout(gtx, sw.resetBtn)
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
if sw.startstopBtn.Clicked(gtx) {
|
||||||
|
if sw.running {
|
||||||
|
sw.running = false
|
||||||
|
} else {
|
||||||
|
sw.running = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sw.resetBtn.Clicked(gtx) {
|
||||||
|
sw.elapsed = time.Time{}
|
||||||
|
sw.running = false
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
swidth := new(int)
|
||||||
|
hrpage = func() {
|
||||||
|
stopbtn := func() {
|
||||||
|
gtx.Constraints.Height.Min = 100
|
||||||
|
layout.UniformInset(unit.Dp(2)).Layout(gtx, func() {
|
||||||
|
th.Button("Disconnect").Layout(gtx, backBtn)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if wide {
|
||||||
|
f2 := &layout.Flex{Axis: layout.Horizontal}
|
||||||
|
f2.Layout(gtx,
|
||||||
|
f2.Flex(gtx, 0.4, func() {
|
||||||
|
f3 := &layout.Flex{Axis: layout.Vertical}
|
||||||
|
c1 := f3.Rigid(gtx, func() {
|
||||||
|
appname()
|
||||||
|
*swidth = gtx.Dimensions.Size.X
|
||||||
|
})
|
||||||
|
c2 := f3.Rigid(gtx, func() {
|
||||||
|
periphname()
|
||||||
|
s2 := gtx.Dimensions.Size.X
|
||||||
|
if s2 > *swidth {
|
||||||
|
*swidth = s2
|
||||||
|
}
|
||||||
|
})
|
||||||
|
var c3 layout.FlexChild
|
||||||
|
if gtx.Constraints.Width.Max > 370 {
|
||||||
|
c3 = f3.Rigid(gtx, stopwatch)
|
||||||
|
}
|
||||||
|
c4 := f3.Rigid(gtx, stopbtn)
|
||||||
|
f3.Layout(gtx,
|
||||||
|
c1,
|
||||||
|
f3.Rigid(gtx, appstate),
|
||||||
|
c2,
|
||||||
|
f3.Flex(gtx, 1.0, func() { th.Body1("").Layout(gtx) }),
|
||||||
|
c3,
|
||||||
|
c4,
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
f2.Flex(gtx, 0.6, func() { hrcircle() }),
|
||||||
|
)
|
||||||
|
} else { // !wide
|
||||||
|
c1 := f.Rigid(gtx, func() {
|
||||||
|
layout.Align(layout.Center).Layout(gtx, func() {
|
||||||
|
gtx.Constraints.Width.Min = *swidth
|
||||||
|
gtx.Constraints.Width.Max = *swidth
|
||||||
|
stopwatch()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
swheight := gtx.Dimensions.Size.Y
|
||||||
|
c2 := f.Rigid(gtx, func() {
|
||||||
|
layout.Align(layout.Center).Layout(gtx, func() {
|
||||||
|
gtx.Constraints.Width.Min = *swidth
|
||||||
|
gtx.Constraints.Width.Max = *swidth
|
||||||
|
stopbtn()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
if gtx.Constraints.Height.Max < 775 {
|
||||||
|
gtx.Constraints.Height.Max += swheight
|
||||||
|
f.Layout(gtx,
|
||||||
|
f.Rigid(gtx, appname),
|
||||||
|
f.Rigid(gtx, appstate),
|
||||||
|
f.Rigid(gtx, periphname),
|
||||||
|
f.Flex(gtx, 1.0, func() {
|
||||||
|
*swidth = hrcircle()
|
||||||
|
}),
|
||||||
|
c2,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
f.Layout(gtx,
|
||||||
|
f.Rigid(gtx, appname),
|
||||||
|
f.Rigid(gtx, appstate),
|
||||||
|
f.Rigid(gtx, periphname),
|
||||||
|
f.Flex(gtx, 1.0, func() {
|
||||||
|
*swidth = hrcircle()
|
||||||
|
}),
|
||||||
|
c1,
|
||||||
|
c2,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if backBtn.Clicked(gtx) {
|
||||||
|
ble.Disconnect(periph)
|
||||||
|
periphs = periphs[:0]
|
||||||
|
Config.Autoconnect = ""
|
||||||
|
saveConfig()
|
||||||
|
b.Scan()
|
||||||
|
state = "scanning"
|
||||||
|
page = scanpage
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
page = offpage
|
page = offpage
|
||||||
|
|
||||||
|
t := time.NewTicker(time.Second/30)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
case <-t.C:
|
||||||
|
w.Invalidate()
|
||||||
case e := <-b.Events():
|
case e := <-b.Events():
|
||||||
switch e := e.(type) {
|
switch e := e.(type) {
|
||||||
case ble.UpdateStateEvent:
|
case ble.UpdateStateEvent:
|
||||||
@@ -297,6 +466,11 @@ func eventloop() {
|
|||||||
return
|
return
|
||||||
case system.FrameEvent:
|
case system.FrameEvent:
|
||||||
gtx.Reset(e.Config, e.Size)
|
gtx.Reset(e.Config, e.Size)
|
||||||
|
if e.Size.X > e.Size.Y {
|
||||||
|
wide = true
|
||||||
|
} else {
|
||||||
|
wide = false
|
||||||
|
}
|
||||||
resetSysinset(e.Insets)
|
resetSysinset(e.Insets)
|
||||||
sysinset.Layout(gtx, func() {
|
sysinset.Layout(gtx, func() {
|
||||||
margin.Layout(gtx, page)
|
margin.Layout(gtx, page)
|
||||||
Reference in New Issue
Block a user