Compare commits
20
Commits
fa469ac9b9
..
v1.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41129e49cc | ||
|
|
63330567f0 | ||
|
|
7852de3edc | ||
|
|
f7c201a3cd | ||
|
|
087b6d3d06 | ||
|
|
6c00897583 | ||
|
|
acf0e7efe9 | ||
|
|
9484ffac99 | ||
|
|
52806e3f6b | ||
|
|
94638e9710 | ||
|
|
363ada0b85 | ||
|
|
81ee9c3c2b | ||
|
|
6e020858d9 | ||
|
|
31fa374c7f | ||
|
|
14bbbf0679 | ||
|
|
265caa30a2 | ||
|
|
05665cdd8f | ||
|
|
c93d5b6906 | ||
|
|
11962c3372 | ||
|
|
66c4ac4885 |
+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.
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
# HRM
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
```
|
||||||
|
git clone https://git.wow.st/gmp/hrm
|
||||||
|
cd hrm/hrm
|
||||||
|
go build
|
||||||
|
./hrm
|
||||||
|
```
|
||||||
|
|
||||||
|
## Android:
|
||||||
|
|
||||||
|
The `gogio` command from `gioui.org/cmd/gogio` must be installed to build
|
||||||
|
an Android APK.
|
||||||
|
|
||||||
|
```
|
||||||
|
git clone https://git.wow.st/gmp/hrm
|
||||||
|
cd hrm/hrm
|
||||||
|
gogio -target android .
|
||||||
|
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
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
module git.wow.st/gmp/hrm
|
|
||||||
|
|
||||||
go 1.13
|
|
||||||
|
|
||||||
require (
|
|
||||||
gioui.org v0.0.0-20191126175243-2ca2e5462f16
|
|
||||||
git.wow.st/gmp/ble v0.0.0-20191127154437-321b94a48682
|
|
||||||
gopkg.in/yaml.v2 v2.2.7
|
|
||||||
)
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
|
||||||
gioui.org v0.0.0-20191126175243-2ca2e5462f16 h1:p31rtmKm51xpj2QtqGNlljAyHEP1oStU8MDRl2Dv7Gs=
|
|
||||||
gioui.org v0.0.0-20191126175243-2ca2e5462f16/go.mod h1:KqFFi2Dq5gYA3FJ0sDOt8OBXoMsuxMtE8v2f0JExXAY=
|
|
||||||
git.wow.st/gmp/ble v0.0.0-20191127154437-321b94a48682 h1:8b9kt3AbWqpJwLukguXBGyUbidbgxpxrToUSX5rUSDE=
|
|
||||||
git.wow.st/gmp/ble v0.0.0-20191127154437-321b94a48682/go.mod h1:Fh9BYe6AckJS7dzv2LFPr/wSYVMROUwmtc01VyQmuZo=
|
|
||||||
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=
|
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
|
||||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
|
||||||
golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3 h1:n9HxLrNxWWtEb1cA950nuEEj3QnKbtsCJ6KjcgisNUs=
|
|
||||||
golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3/go.mod h1:NOZ3BPKG0ec/BKJQgnvsSFpcKLM5xXVWnvZS97DWHgE=
|
|
||||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
|
||||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4=
|
|
||||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
|
||||||
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
|
||||||
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
|
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ=
|
|
||||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
|
||||||
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/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/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
|
|
||||||
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
+10
@@ -0,0 +1,10 @@
|
|||||||
|
module st.wow.git/gmp/hrm/hrm
|
||||||
|
|
||||||
|
go 1.14
|
||||||
|
|
||||||
|
require (
|
||||||
|
gioui.org v0.0.0-20200829162755-829ee4559c5a
|
||||||
|
gioui.org/cmd v0.0.0-20200829162755-829ee4559c5a
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20200905181229-90ab682a4410
|
||||||
|
gopkg.in/yaml.v2 v2.3.0
|
||||||
|
)
|
||||||
+107
@@ -0,0 +1,107 @@
|
|||||||
|
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
|
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||||
|
gioui.org v0.0.0-20191126175243-2ca2e5462f16 h1:p31rtmKm51xpj2QtqGNlljAyHEP1oStU8MDRl2Dv7Gs=
|
||||||
|
gioui.org v0.0.0-20191126175243-2ca2e5462f16/go.mod h1:KqFFi2Dq5gYA3FJ0sDOt8OBXoMsuxMtE8v2f0JExXAY=
|
||||||
|
gioui.org v0.0.0-20200612151431-2dc19a36959c h1:sGUKyRMv2bbfbsRyG8ghOI12l+WCGta+PivmznjuLgo=
|
||||||
|
gioui.org v0.0.0-20200612151431-2dc19a36959c/go.mod h1:AHI9rFr6AEEHCb8EPVtb/p5M+NMJRKH58IOp8O3Je04=
|
||||||
|
gioui.org v0.0.0-20200619121558-88ced59dad93/go.mod h1:jiUwifN9cRl/zmco43aAqh0aV+s9GbhG13KcD+gEpkU=
|
||||||
|
gioui.org v0.0.0-20200715100850-e48b85f8d92e/go.mod h1:jiUwifN9cRl/zmco43aAqh0aV+s9GbhG13KcD+gEpkU=
|
||||||
|
gioui.org v0.0.0-20200726090130-3b95e2918359 h1:lae3H0ZryBOt3Kboxa55mpo5KsASVHSdS65EsGMf9kc=
|
||||||
|
gioui.org v0.0.0-20200726090130-3b95e2918359/go.mod h1:jiUwifN9cRl/zmco43aAqh0aV+s9GbhG13KcD+gEpkU=
|
||||||
|
gioui.org v0.0.0-20200829162755-829ee4559c5a h1:mciXRGzQwU0TbgCILZzl6L1nYIWU31lDGIb+8RYige8=
|
||||||
|
gioui.org v0.0.0-20200829162755-829ee4559c5a/go.mod h1:Y+uS7hHMvku1Q+ooaoq6fYD5B2LGoT8JtFgvmYmRzTw=
|
||||||
|
gioui.org/cmd v0.0.0-20200726090130-3b95e2918359 h1:oIoK6LiOPvctO41lzgsQckWuN+nKO5WktPNUplEZf68=
|
||||||
|
gioui.org/cmd v0.0.0-20200726090130-3b95e2918359/go.mod h1:HNGpTdPoljZA5nsjt6wLgnB6gyU6WL6531yQdsD7cE4=
|
||||||
|
gioui.org/cmd v0.0.0-20200829162755-829ee4559c5a h1:TXnkA3Fdk7FpwZ6x9lbIAZoTKOg/i5aTLIJ4f7SSagY=
|
||||||
|
gioui.org/cmd v0.0.0-20200829162755-829ee4559c5a/go.mod h1:dlmJnCEkOpRaChYxRmJZ5S4jk6y7DCfWnec39xGbUYk=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191127164604-2af636b9461a h1:Nr6kwAliHs2EsGv4Q1EgQACfbb/hVnTYq0CkWfqIj+g=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191127164604-2af636b9461a/go.mod h1:Fh9BYe6AckJS7dzv2LFPr/wSYVMROUwmtc01VyQmuZo=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191204220614-4cdaceda7601 h1:lgoKiQ1MzXfh4+sl601d0RR6/Kt182MiegqLtdVBy1I=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20191204220614-4cdaceda7601/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/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=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20200204223639-7a583419c528 h1:jXHDwWWs11Qua2DSdgU1WBW2HNDPQU9/IjoZ4d5oAsI=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20200204223639-7a583419c528/go.mod h1:Fh9BYe6AckJS7dzv2LFPr/wSYVMROUwmtc01VyQmuZo=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20200612201046-f5cc27a30de7 h1:RoWGPgYpz5szRySgT6/Vykxw0nBMH39Mv2+ghsMy82I=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20200612201046-f5cc27a30de7/go.mod h1:CpPW2hELyNbPdD2I6XvJsu3PQ23iPYtlLTydJ+KZMbQ=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20200619183549-b0b310a7b0d2 h1:X/NZSZaKiBOfLR3V+8+erNYJrwLfTD+dukqhCpjWgzo=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20200619183549-b0b310a7b0d2/go.mod h1:ObxuF1L41fWoIEfwX2Rww1veGj77dXVISXJA6sqThBA=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20200905181229-90ab682a4410 h1:oR4E/sHCCJ6GnZGWJb2pIwuSKAO/P1QfB3sXHUQHWXU=
|
||||||
|
git.wow.st/gmp/ble v0.0.0-20200905181229-90ab682a4410/go.mod h1:NrH2R84qUcPGoI9MmPGB1GFIbQxCWEw4WpVnDEn/WUc=
|
||||||
|
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||||
|
github.com/chromedp/cdproto v0.0.0-20191114225735-6626966fbae4/go.mod h1:PfAWWKJqjlGFYJEidUM6aVIWPr0EpobeyVWEEmplX7g=
|
||||||
|
github.com/chromedp/chromedp v0.5.2/go.mod h1:rsTo/xRo23KZZwFmWk2Ui79rBaVRRATCjLzNQlOFSiA=
|
||||||
|
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||||
|
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
|
||||||
|
github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
|
||||||
|
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
|
||||||
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
|
||||||
|
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
|
||||||
|
github.com/google/go-github/v24 v24.0.1 h1:KCt1LjMJEey1qvPXxa9SjaWxwTsCWSq6p2Ju57UR4Q4=
|
||||||
|
github.com/google/go-github/v24 v24.0.1/go.mod h1:CRqaW1Uns1TCkP0wqTpxYyRxRjxwvKU/XSS44u6X74M=
|
||||||
|
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
|
||||||
|
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||||
|
github.com/knq/sysutil v0.0.0-20191005231841-15668db23d08/go.mod h1:dFWs1zEqDjFtnBXsd1vPOZaLsESovai349994nHx3e0=
|
||||||
|
github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
|
||||||
|
golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
|
golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3 h1:n9HxLrNxWWtEb1cA950nuEEj3QnKbtsCJ6KjcgisNUs=
|
||||||
|
golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3/go.mod h1:NOZ3BPKG0ec/BKJQgnvsSFpcKLM5xXVWnvZS97DWHgE=
|
||||||
|
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||||
|
golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4=
|
||||||
|
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||||
|
golang.org/x/image v0.0.0-20200618115811-c13761719519 h1:1e2ufUJNM3lCHEY5jIgac/7UTjd6cgJNdatjPdFWf34=
|
||||||
|
golang.org/x/image v0.0.0-20200618115811-c13761719519/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||||
|
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
||||||
|
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
|
||||||
|
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
|
golang.org/x/oauth2 v0.0.0-20191122200657-5d9234df094c h1:HjRaKPaiWks0f5tA6ELVF7ZfqSppfPwOEEAvsrKUTO4=
|
||||||
|
golang.org/x/oauth2 v0.0.0-20191122200657-5d9234df094c/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
|
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20180824143301-4910a1d54f87/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ=
|
||||||
|
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20191113165036-4c7a9d0fe056/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 h1:1/DFK4b7JH8DmkqhUk48onnSfrPzImPoVxuomtbT2nk=
|
||||||
|
golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/tools v0.0.0-20190927191325-030b2cf1153e h1:1xWUkZQQ9Z9UuZgNaIR6OQOE7rUFglXUUBZlO+dGg6I=
|
||||||
|
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=
|
||||||
|
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||||
|
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
|
||||||
|
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||||
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
+509
@@ -0,0 +1,509 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.wow.st/gmp/ble"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
|
||||||
|
"gioui.org/app"
|
||||||
|
"gioui.org/io/system"
|
||||||
|
"gioui.org/layout"
|
||||||
|
"gioui.org/f32"
|
||||||
|
"gioui.org/op"
|
||||||
|
"gioui.org/op/clip"
|
||||||
|
"gioui.org/op/paint"
|
||||||
|
"gioui.org/text"
|
||||||
|
"gioui.org/unit"
|
||||||
|
"gioui.org/widget"
|
||||||
|
"gioui.org/widget/material"
|
||||||
|
|
||||||
|
"gioui.org/font/gofont"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
D = layout.Dimensions
|
||||||
|
C = layout.Context
|
||||||
|
)
|
||||||
|
|
||||||
|
type conf struct {
|
||||||
|
Autoconnect string
|
||||||
|
}
|
||||||
|
|
||||||
|
var Config conf
|
||||||
|
var conffile string
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
conffile = path.Join(getConfDir(), "config.yml")
|
||||||
|
if _, err := os.Stat(conffile); os.IsNotExist(err) {
|
||||||
|
fd, err := os.Create(conffile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Cannot create configuration file: ", err)
|
||||||
|
}
|
||||||
|
fd.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
confbytes, err := ioutil.ReadFile(conffile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Cannot read configuration file: ", err)
|
||||||
|
}
|
||||||
|
if err = yaml.UnmarshalStrict(confbytes, &Config); err != nil {
|
||||||
|
log.Fatal("Cannot parse configuration file: ", err)
|
||||||
|
}
|
||||||
|
go eventloop()
|
||||||
|
app.Main()
|
||||||
|
}
|
||||||
|
|
||||||
|
func saveConfig() {
|
||||||
|
confbytes, err := yaml.Marshal(&Config)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Cannot encode configuration: ", err)
|
||||||
|
}
|
||||||
|
err = ioutil.WriteFile(conffile, confbytes, 0700)
|
||||||
|
}
|
||||||
|
|
||||||
|
func hrDecode(x []byte) int {
|
||||||
|
if len(x) < 4 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
flags := x[0]
|
||||||
|
if flags&0x80 != 0 { // uint16 format
|
||||||
|
return int(binary.BigEndian.Uint16(x[1:3]))
|
||||||
|
} else {
|
||||||
|
return int(x[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Stopwatch struct {
|
||||||
|
lasttime time.Time
|
||||||
|
elapsed time.Time
|
||||||
|
running bool
|
||||||
|
startstopBtn *widget.Clickable
|
||||||
|
resetBtn *widget.Clickable
|
||||||
|
h, m, s int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewStopwatch() Stopwatch {
|
||||||
|
return Stopwatch{
|
||||||
|
startstopBtn: &widget.Clickable{},
|
||||||
|
resetBtn: &widget.Clickable{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func eventloop() {
|
||||||
|
w := app.NewWindow(
|
||||||
|
app.Size(unit.Dp(350), unit.Dp(600)),
|
||||||
|
app.Title("HRM"),
|
||||||
|
)
|
||||||
|
th := material.NewTheme(gofont.Collection())
|
||||||
|
th.TextSize = unit.Sp(fontSize)
|
||||||
|
var ops op.Ops
|
||||||
|
|
||||||
|
sysinset := &layout.Inset{}
|
||||||
|
resetSysinset := func(x system.Insets) {
|
||||||
|
sysinset.Top = x.Top
|
||||||
|
sysinset.Bottom = x.Bottom
|
||||||
|
sysinset.Left = x.Left
|
||||||
|
sysinset.Right = x.Right
|
||||||
|
}
|
||||||
|
margin := layout.UniformInset(unit.Dp(10))
|
||||||
|
|
||||||
|
b := ble.NewBLE()
|
||||||
|
|
||||||
|
state := "starting"
|
||||||
|
var hr int
|
||||||
|
var periph ble.Peripheral
|
||||||
|
var wide bool
|
||||||
|
periphs := make([]ble.Peripheral, 0)
|
||||||
|
btns := make([]*widget.Clickable, 0)
|
||||||
|
backBtn := &widget.Clickable{}
|
||||||
|
|
||||||
|
var page, offpage, scanpage, connpage, hrpage func(gtx C) D
|
||||||
|
|
||||||
|
f := &layout.Flex{Axis: layout.Vertical}
|
||||||
|
offpage = func(gtx C) D {
|
||||||
|
return f.Layout(gtx,
|
||||||
|
layout.Rigid(func(gtx C) D {
|
||||||
|
return material.Body1(th, "Heart Rate Monitor").Layout(gtx)
|
||||||
|
}),
|
||||||
|
layout.Rigid(func(gtx C) D {
|
||||||
|
return material.Body1(th, "Bluetooth is Powered Off").Layout(gtx)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
appname := func(gtx C) D {
|
||||||
|
return layout.Center.Layout(gtx, func(gtx C) D {
|
||||||
|
return material.Body1(th, "Heart Rate Monitor").Layout(gtx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
appstate := func(gtx C) D {
|
||||||
|
return layout.Center.Layout(gtx, func(gtx C) D {
|
||||||
|
return material.Body1(th, state).Layout(gtx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
periphname := func(gtx C) D {
|
||||||
|
return layout.Center.Layout(gtx, func(gtx C) D {
|
||||||
|
return material.Body1(th, periph.Name).Layout(gtx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
leftbar := func(gtx C) D {
|
||||||
|
f := &layout.Flex{Axis: layout.Vertical}
|
||||||
|
return f.Layout(gtx,
|
||||||
|
layout.Rigid(appname),
|
||||||
|
layout.Rigid(func(gtx C) D {
|
||||||
|
return material.Body1(th, "").Layout(gtx)
|
||||||
|
}),
|
||||||
|
layout.Rigid(appstate),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
scanlist := func(gtx C) D {
|
||||||
|
lst := &layout.List{Axis: layout.Vertical}
|
||||||
|
return lst.Layout(gtx, len(periphs), func(gtx C, i int) D {
|
||||||
|
gtx.Constraints.Min.X = gtx.Constraints.Max.X
|
||||||
|
ret := layout.UniformInset(unit.Dp(2)).Layout(gtx, func(gtx C) D {
|
||||||
|
return material.Button(th, btns[i], periphs[i].Name).Layout(gtx)
|
||||||
|
})
|
||||||
|
if btns[i].Clicked() {
|
||||||
|
b.StopScan()
|
||||||
|
periph = periphs[i]
|
||||||
|
b.Connect(periph)
|
||||||
|
state = "connecting"
|
||||||
|
page = connpage
|
||||||
|
w.Invalidate()
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
scanpage = func(gtx C) D {
|
||||||
|
if wide {
|
||||||
|
f2 := &layout.Flex{Axis: layout.Horizontal}
|
||||||
|
return f2.Layout(gtx,
|
||||||
|
layout.Rigid(leftbar),
|
||||||
|
layout.Flexed(1, scanlist),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
return f.Layout(gtx,
|
||||||
|
layout.Rigid(appname),
|
||||||
|
layout.Rigid(appstate),
|
||||||
|
layout.Rigid(scanlist),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
connpage = func(gtx C) D {
|
||||||
|
return f.Layout(gtx,
|
||||||
|
layout.Rigid(appname),
|
||||||
|
layout.Rigid(appstate),
|
||||||
|
layout.Rigid(periphname),
|
||||||
|
layout.Rigid(func(gtx C) D {
|
||||||
|
ret := material.Button(th, backBtn, "Cancel").Layout(gtx)
|
||||||
|
if backBtn.Clicked() {
|
||||||
|
ble.CancelConnection(periph)
|
||||||
|
periphs = periphs[:0]
|
||||||
|
Config.Autoconnect = ""
|
||||||
|
saveConfig()
|
||||||
|
b.Scan()
|
||||||
|
state = "scanning"
|
||||||
|
page = scanpage
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
hrcircle := func(gtx C) (int, D) {
|
||||||
|
var w, h1 float32
|
||||||
|
ret := layout.Center.Layout(gtx, func(gtx C) D {
|
||||||
|
blue := color.RGBA{0x3f, 0x51, 0xb5, 255}
|
||||||
|
white := color.RGBA{255, 255, 255, 255}
|
||||||
|
w, h1 = float32(gtx.Constraints.Max.X), float32(gtx.Constraints.Max.Y)
|
||||||
|
if w < h1 {
|
||||||
|
h1 = w
|
||||||
|
}
|
||||||
|
s2 := h1 * 0.9
|
||||||
|
r1 := f32.Rectangle{f32.Point{0, 0}, f32.Point{h1, h1}}
|
||||||
|
p2a := f32.Point{(h1-s2)/2, (h1-s2)/2}
|
||||||
|
p2b := f32.Point{s2 + (h1-s2)/2, s2 + (h1-s2)/2}
|
||||||
|
r2 := f32.Rectangle{p2a, p2b}
|
||||||
|
clip.RRect{ Rect: r1, NE: h1/2, NW: h1/2, SE: h1/2, SW: h1/2}.Add(gtx.Ops)
|
||||||
|
paint.ColorOp{Color: blue}.Add(gtx.Ops)
|
||||||
|
paint.PaintOp{Rect: r1}.Add(gtx.Ops)
|
||||||
|
clip.RRect{ Rect: r2, NE: s2/2, NW: s2/2, SE: s2/2, SW: s2/2}.Add(gtx.Ops)
|
||||||
|
paint.ColorOp{Color: white}.Add(gtx.Ops)
|
||||||
|
paint.PaintOp{Rect: r2}.Add(gtx.Ops)
|
||||||
|
op.Offset(p2a).Add(gtx.Ops)
|
||||||
|
gtx.Constraints.Max.X = int(s2)
|
||||||
|
gtx.Constraints.Max.Y = int(s2)
|
||||||
|
gtx.Constraints.Min.X = int(s2)
|
||||||
|
gtx.Constraints.Min.Y = int(s2)
|
||||||
|
l := material.H1(th, fmt.Sprintf("%d", hr))
|
||||||
|
l.Alignment = text.Middle
|
||||||
|
layout.Center.Layout(gtx, func(gtx C) D {
|
||||||
|
return l.Layout(gtx)
|
||||||
|
})
|
||||||
|
var ret D
|
||||||
|
ret.Size = image.Point{int(h1), int(h1)}
|
||||||
|
return ret
|
||||||
|
})
|
||||||
|
return int(h1), ret
|
||||||
|
}
|
||||||
|
|
||||||
|
sw := NewStopwatch()
|
||||||
|
|
||||||
|
stopwatch := func(gtx C) D {
|
||||||
|
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}
|
||||||
|
return f.Layout(gtx,
|
||||||
|
layout.Rigid(func(gtx C) D {
|
||||||
|
return layout.Center.Layout(gtx, func(gtx C) D {
|
||||||
|
gtx.Constraints.Max.X = 1e6
|
||||||
|
return material.H4(th, sw.elapsed.Format("15:04:05.00")).Layout(gtx)
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
layout.Rigid(func(gtx C) D {
|
||||||
|
f2 := layout.Flex{Axis: layout.Horizontal}
|
||||||
|
gtx.Constraints.Min.Y = 100
|
||||||
|
ret := f2.Layout(gtx,
|
||||||
|
layout.Flexed(0.5, func(gtx C) D {
|
||||||
|
return layout.UniformInset(unit.Dp(2)).Layout(gtx, func(gtx C) D {
|
||||||
|
return material.Button(th, sw.startstopBtn, startstoptxt).Layout(gtx)
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
layout.Flexed(0.5, func(gtx C) D {
|
||||||
|
return layout.UniformInset(unit.Dp(2)).Layout(gtx, func(gtx C) D {
|
||||||
|
return material.Button(th, sw.resetBtn, "reset").Layout(gtx)
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
if sw.startstopBtn.Clicked() {
|
||||||
|
if sw.running {
|
||||||
|
sw.running = false
|
||||||
|
} else {
|
||||||
|
sw.running = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sw.resetBtn.Clicked() {
|
||||||
|
sw.elapsed = time.Time{}
|
||||||
|
sw.running = false
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
swidth := new(int)
|
||||||
|
hrpage = func(gtx C) D {
|
||||||
|
var ret, ret2 D
|
||||||
|
stopbtn := func(gtx C) D {
|
||||||
|
gtx.Constraints.Min.Y = 100
|
||||||
|
return layout.UniformInset(unit.Dp(2)).Layout(gtx, func(gtx C) D {
|
||||||
|
return material.Button(th, backBtn, "Disconnect").Layout(gtx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if wide {
|
||||||
|
f2 := &layout.Flex{Axis: layout.Horizontal}
|
||||||
|
ret = f2.Layout(gtx,
|
||||||
|
layout.Flexed(0.4, func(gtx C) D {
|
||||||
|
f3 := &layout.Flex{Axis: layout.Vertical}
|
||||||
|
c1 := layout.Rigid(func(gtx C) D {
|
||||||
|
ret2 = appname(gtx)
|
||||||
|
*swidth = ret2.Size.X
|
||||||
|
return ret2
|
||||||
|
})
|
||||||
|
c2 := layout.Rigid(func(gtx C) D {
|
||||||
|
ret2 = periphname(gtx)
|
||||||
|
s2 := ret2.Size.X
|
||||||
|
if s2 > *swidth {
|
||||||
|
*swidth = s2
|
||||||
|
}
|
||||||
|
return ret2
|
||||||
|
})
|
||||||
|
var c3 layout.FlexChild
|
||||||
|
if gtx.Constraints.Max.X > 370 {
|
||||||
|
c3 = layout.Rigid(stopwatch)
|
||||||
|
} else {
|
||||||
|
c3 = layout.Rigid(func(gtx C) D {
|
||||||
|
return D{}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
c4 := layout.Rigid(stopbtn)
|
||||||
|
return f3.Layout(gtx,
|
||||||
|
c1,
|
||||||
|
layout.Rigid(appstate),
|
||||||
|
c2,
|
||||||
|
layout.Flexed(1.0, func(gtx C) D {
|
||||||
|
return material.Body1(th, "").Layout(gtx)
|
||||||
|
}),
|
||||||
|
c3,
|
||||||
|
c4,
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
layout.Flexed(0.6, func(gtx C) D {
|
||||||
|
_, ret := hrcircle(gtx)
|
||||||
|
return ret
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
} else { // !wide
|
||||||
|
c1 := layout.Rigid(func(gtx C) D {
|
||||||
|
return layout.Center.Layout(gtx, func(gtx C) D {
|
||||||
|
gtx.Constraints.Min.X = *swidth
|
||||||
|
gtx.Constraints.Max.X = *swidth
|
||||||
|
return stopwatch(gtx)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
//swheight := gtx.Dimensions.Size.Y
|
||||||
|
c2 := layout.Rigid(func(gtx C) D {
|
||||||
|
return layout.Center.Layout(gtx, func(gtx C) D {
|
||||||
|
gtx.Constraints.Min.X = *swidth
|
||||||
|
gtx.Constraints.Max.X = *swidth
|
||||||
|
return stopbtn(gtx)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
if gtx.Constraints.Max.Y < 775 {
|
||||||
|
//gtx.Constraints.Max.Y += swheight
|
||||||
|
ret = f.Layout(gtx,
|
||||||
|
layout.Rigid(appname),
|
||||||
|
layout.Rigid(appstate),
|
||||||
|
layout.Rigid(periphname),
|
||||||
|
layout.Flexed(1.0, func(gtx C) D {
|
||||||
|
*swidth, ret2 = hrcircle(gtx)
|
||||||
|
return ret2
|
||||||
|
}),
|
||||||
|
c2,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
ret = f.Layout(gtx,
|
||||||
|
layout.Rigid(appname),
|
||||||
|
layout.Rigid(appstate),
|
||||||
|
layout.Rigid(periphname),
|
||||||
|
layout.Flexed(1.0, func(gtx C) D {
|
||||||
|
*swidth, ret2 = hrcircle(gtx)
|
||||||
|
return ret2
|
||||||
|
}),
|
||||||
|
c1,
|
||||||
|
c2,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if backBtn.Clicked() {
|
||||||
|
ble.Disconnect(periph)
|
||||||
|
periphs = periphs[:0]
|
||||||
|
Config.Autoconnect = ""
|
||||||
|
saveConfig()
|
||||||
|
b.Scan()
|
||||||
|
state = "scanning"
|
||||||
|
page = scanpage
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
page = offpage
|
||||||
|
|
||||||
|
t := time.NewTicker(time.Second/30)
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-t.C:
|
||||||
|
w.Invalidate()
|
||||||
|
case e := <-b.Events():
|
||||||
|
switch e := e.(type) {
|
||||||
|
case ble.UpdateStateEvent:
|
||||||
|
fmt.Printf("UpdateState: %s\n", e.State)
|
||||||
|
state = e.State
|
||||||
|
if state != "powered on" {
|
||||||
|
periphs = periphs[:0]
|
||||||
|
page = offpage
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if Config.Autoconnect != "" && b.Connect(ble.Peripheral{Identifier: Config.Autoconnect}) {
|
||||||
|
state = "connecting"
|
||||||
|
page = connpage
|
||||||
|
} else {
|
||||||
|
periphs = periphs[:0]
|
||||||
|
state = "scanning"
|
||||||
|
page = scanpage
|
||||||
|
b.Scan()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case ble.DiscoverPeripheralEvent:
|
||||||
|
fmt.Printf("found %s (%s)\n", e.Peripheral.Name, e.Peripheral.Identifier)
|
||||||
|
periphs = append(periphs, e.Peripheral)
|
||||||
|
btns = append(btns, &widget.Clickable{})
|
||||||
|
if e.Peripheral.Identifier == Config.Autoconnect && b.Connect(e.Peripheral) {
|
||||||
|
state = "connecting"
|
||||||
|
page = connpage
|
||||||
|
}
|
||||||
|
case ble.ConnectEvent:
|
||||||
|
fmt.Printf("Connect event\n")
|
||||||
|
b.StopScan()
|
||||||
|
state = "connected"
|
||||||
|
periph = e.Peripheral
|
||||||
|
Config.Autoconnect = periph.Identifier
|
||||||
|
saveConfig()
|
||||||
|
e.Peripheral.DiscoverServices()
|
||||||
|
page = hrpage
|
||||||
|
case ble.ConnectTimeoutEvent:
|
||||||
|
fmt.Printf("Connect timeout\n")
|
||||||
|
state = "timeout"
|
||||||
|
periphs = periphs[:0]
|
||||||
|
page = scanpage
|
||||||
|
Config.Autoconnect = ""
|
||||||
|
saveConfig()
|
||||||
|
b.Scan()
|
||||||
|
case ble.DiscoverServiceEvent:
|
||||||
|
fmt.Printf("DiscoverService %s\n", e.Gatt.UUID)
|
||||||
|
//if e.Gatt.UUID == "180D" {
|
||||||
|
if e.Gatt.IsHRM() {
|
||||||
|
fmt.Printf("Found HRM Service\n")
|
||||||
|
e.Peripheral.DiscoverCharacteristics(e.Service)
|
||||||
|
}
|
||||||
|
case ble.DiscoverCharacteristicEvent:
|
||||||
|
fmt.Printf("DiscoverCharacteristic %s\n", e.Gatt.UUID)
|
||||||
|
//if e.Gatt.UUID == "2A37" {
|
||||||
|
if e.Gatt.IsHRV() {
|
||||||
|
fmt.Printf("Found heart rate value\n")
|
||||||
|
e.Peripheral.SetNotifyValue(e.Characteristic)
|
||||||
|
}
|
||||||
|
case ble.UpdateValueEvent:
|
||||||
|
hr = hrDecode(e.Data)
|
||||||
|
}
|
||||||
|
w.Invalidate() // refresh on any Bluetooth event
|
||||||
|
case e := <-w.Events():
|
||||||
|
switch e := e.(type) {
|
||||||
|
case system.DestroyEvent:
|
||||||
|
os.Exit(0)
|
||||||
|
case system.FrameEvent:
|
||||||
|
gtx := layout.NewContext(&ops, e)
|
||||||
|
if e.Size.X > e.Size.Y {
|
||||||
|
wide = true
|
||||||
|
} else {
|
||||||
|
wide = false
|
||||||
|
}
|
||||||
|
resetSysinset(e.Insets)
|
||||||
|
sysinset.Layout(gtx, func(gtx C) D {
|
||||||
|
return margin.Layout(gtx, page)
|
||||||
|
})
|
||||||
|
e.Frame(gtx.Ops)
|
||||||
|
default:
|
||||||
|
handleEvent(e, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,9 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
|
|
||||||
"gioui.org/app"
|
"gioui.org/app"
|
||||||
|
"gioui.org/io/event"
|
||||||
|
|
||||||
|
"git.wow.st/gmp/ble"
|
||||||
)
|
)
|
||||||
|
|
||||||
var confDir string
|
var confDir string
|
||||||
@@ -19,3 +22,10 @@ func getConfDir() string {
|
|||||||
}
|
}
|
||||||
return confDir
|
return confDir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleEvent(e event.Event, b *ble.BLE) {
|
||||||
|
switch e:= e.(type) {
|
||||||
|
case app.ViewEvent:
|
||||||
|
b.Enable(e.View)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
//+build !android
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gioui.org/io/event"
|
||||||
|
"git.wow.st/gmp/ble"
|
||||||
|
)
|
||||||
|
|
||||||
|
func handleEvent(e event.Event, b *ble.BLE) {
|
||||||
|
}
|
||||||
@@ -1,277 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/binary"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
|
|
||||||
"git.wow.st/gmp/ble"
|
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
|
|
||||||
"gioui.org/app"
|
|
||||||
"gioui.org/io/system"
|
|
||||||
"gioui.org/layout"
|
|
||||||
"gioui.org/text"
|
|
||||||
"gioui.org/unit"
|
|
||||||
"gioui.org/widget"
|
|
||||||
"gioui.org/widget/material"
|
|
||||||
|
|
||||||
"gioui.org/font/gofont"
|
|
||||||
)
|
|
||||||
|
|
||||||
type conf struct {
|
|
||||||
Autoconnect string
|
|
||||||
}
|
|
||||||
|
|
||||||
var Config conf
|
|
||||||
var conffile string
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
conffile = path.Join(getConfDir(), "config.yml")
|
|
||||||
if _, err := os.Stat(conffile); os.IsNotExist(err) {
|
|
||||||
fd, err := os.Create(conffile)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Cannot create configuration file: ", err)
|
|
||||||
}
|
|
||||||
fd.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
confbytes, err := ioutil.ReadFile(conffile)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Cannot read configuration file: ", err)
|
|
||||||
}
|
|
||||||
if err = yaml.UnmarshalStrict(confbytes, &Config); err != nil {
|
|
||||||
log.Fatal("Cannot parse configuration file: ", err)
|
|
||||||
}
|
|
||||||
go eventloop()
|
|
||||||
app.Main()
|
|
||||||
}
|
|
||||||
|
|
||||||
func saveConfig() {
|
|
||||||
confbytes, err := yaml.Marshal(&Config)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Cannot encode configuration: ", err)
|
|
||||||
}
|
|
||||||
err = ioutil.WriteFile(conffile, confbytes, 0700)
|
|
||||||
}
|
|
||||||
|
|
||||||
func hrDecode(x []byte) int {
|
|
||||||
if len(x) < 4 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
flags := x[0]
|
|
||||||
if flags&0x80 != 0 { // uint16 format
|
|
||||||
return int(binary.BigEndian.Uint16(x[1:3]))
|
|
||||||
} else {
|
|
||||||
return int(x[1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func eventloop() {
|
|
||||||
w := app.NewWindow(
|
|
||||||
app.Size(unit.Dp(400), unit.Dp(400)),
|
|
||||||
app.Title("HRM"),
|
|
||||||
)
|
|
||||||
gofont.Register()
|
|
||||||
th := material.NewTheme()
|
|
||||||
th.TextSize = unit.Sp(fontSize)
|
|
||||||
gtx := &layout.Context{Queue: w.Queue()}
|
|
||||||
|
|
||||||
sysinset := &layout.Inset{}
|
|
||||||
resetSysinset := func(x system.Insets) {
|
|
||||||
sysinset.Top = x.Top
|
|
||||||
sysinset.Bottom = x.Bottom
|
|
||||||
sysinset.Left = x.Left
|
|
||||||
sysinset.Right = x.Right
|
|
||||||
}
|
|
||||||
margin := layout.UniformInset(unit.Dp(10))
|
|
||||||
|
|
||||||
b := ble.NewBLE()
|
|
||||||
b.Enable(w)
|
|
||||||
|
|
||||||
state := "starting"
|
|
||||||
var hr int
|
|
||||||
var periph ble.Peripheral
|
|
||||||
periphs := make([]ble.Peripheral, 0)
|
|
||||||
btns := make([]*widget.Button, 0)
|
|
||||||
backBtn := &widget.Button{}
|
|
||||||
|
|
||||||
var page, offpage, scanpage, connpage, hrpage func()
|
|
||||||
|
|
||||||
f := &layout.Flex{Axis: layout.Vertical}
|
|
||||||
offpage = func() {
|
|
||||||
c1 := f.Rigid(gtx, func() {
|
|
||||||
th.Body1("Heart Rate Monitor").Layout(gtx)
|
|
||||||
})
|
|
||||||
c2 := f.Rigid(gtx, func() {
|
|
||||||
th.Body1("Bluetooth is Powered Off").Layout(gtx)
|
|
||||||
})
|
|
||||||
f.Layout(gtx, c1, c2)
|
|
||||||
}
|
|
||||||
scanpage = func() {
|
|
||||||
c1 := f.Rigid(gtx, func() {
|
|
||||||
th.Body1("Heart Rate Monitor").Layout(gtx)
|
|
||||||
})
|
|
||||||
c2 := f.Rigid(gtx, func() {
|
|
||||||
th.Body1(state).Layout(gtx)
|
|
||||||
})
|
|
||||||
c3 := f.Rigid(gtx, func() {
|
|
||||||
lst := &layout.List{Axis: layout.Vertical}
|
|
||||||
lst.Layout(gtx, len(periphs), func(i int) {
|
|
||||||
gtx.Constraints.Width.Min = gtx.Constraints.Width.Max
|
|
||||||
layout.UniformInset(unit.Dp(2)).Layout(gtx, func() {
|
|
||||||
th.Button(periphs[i].Name).Layout(gtx, btns[i])
|
|
||||||
})
|
|
||||||
if btns[i].Clicked(gtx) {
|
|
||||||
b.StopScan()
|
|
||||||
periph = periphs[i]
|
|
||||||
b.Connect(periph)
|
|
||||||
state = "connecting"
|
|
||||||
page = connpage
|
|
||||||
w.Invalidate()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
f.Layout(gtx, c1, c2, c3)
|
|
||||||
}
|
|
||||||
|
|
||||||
connpage = func() {
|
|
||||||
c1 := f.Rigid(gtx, func() {
|
|
||||||
th.Body1("Heart Rate Monitor").Layout(gtx)
|
|
||||||
})
|
|
||||||
c2 := f.Rigid(gtx, func() {
|
|
||||||
th.Body1("Connecting").Layout(gtx)
|
|
||||||
})
|
|
||||||
c3 := f.Rigid(gtx, func() {
|
|
||||||
th.Body1(periph.Name).Layout(gtx)
|
|
||||||
})
|
|
||||||
c4 := f.Rigid(gtx, func() {
|
|
||||||
th.Button("Cancel").Layout(gtx, backBtn)
|
|
||||||
if backBtn.Clicked(gtx) {
|
|
||||||
ble.CancelConnection(periph)
|
|
||||||
periphs = periphs[:0]
|
|
||||||
Config.Autoconnect = ""
|
|
||||||
saveConfig()
|
|
||||||
b.Scan()
|
|
||||||
state = "scanning"
|
|
||||||
page = scanpage
|
|
||||||
}
|
|
||||||
})
|
|
||||||
f.Layout(gtx, c1, c2, c3, c4)
|
|
||||||
}
|
|
||||||
|
|
||||||
hrpage = func() {
|
|
||||||
c1 := f.Rigid(gtx, func() {
|
|
||||||
th.Body1("Heart Rate Monitor").Layout(gtx)
|
|
||||||
})
|
|
||||||
c2 := f.Rigid(gtx, func() {
|
|
||||||
th.Body1(periph.Name).Layout(gtx)
|
|
||||||
})
|
|
||||||
c3 := f.Rigid(gtx, func() {
|
|
||||||
l := th.H1(fmt.Sprintf("%d", hr))
|
|
||||||
l.Alignment = text.Middle
|
|
||||||
l.Layout(gtx)
|
|
||||||
})
|
|
||||||
c4 := f.Rigid(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
|
|
||||||
}
|
|
||||||
})
|
|
||||||
f.Layout(gtx, c1, c2, c3, c4)
|
|
||||||
}
|
|
||||||
|
|
||||||
page = offpage
|
|
||||||
|
|
||||||
events := b.Events()
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case e := <-events:
|
|
||||||
switch e := e.(type) {
|
|
||||||
case ble.UpdateStateEvent:
|
|
||||||
fmt.Printf("UpdateState: %s\n", e.State)
|
|
||||||
state = e.State
|
|
||||||
if state != "powered on" {
|
|
||||||
periphs = periphs[:0]
|
|
||||||
page = offpage
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if Config.Autoconnect != "" && b.Connect(ble.Peripheral{Identifier: Config.Autoconnect}) {
|
|
||||||
state = "connecting"
|
|
||||||
page = connpage
|
|
||||||
} else {
|
|
||||||
periphs = periphs[:0]
|
|
||||||
state = "scanning"
|
|
||||||
page = scanpage
|
|
||||||
b.Scan()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case ble.DiscoverPeripheralEvent:
|
|
||||||
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 == Config.Autoconnect && b.Connect(e.Peripheral) {
|
|
||||||
state = "connecting"
|
|
||||||
page = connpage
|
|
||||||
}
|
|
||||||
case ble.ConnectEvent:
|
|
||||||
fmt.Printf("Connect event\n")
|
|
||||||
b.StopScan()
|
|
||||||
state = "connected"
|
|
||||||
periph = e.Peripheral
|
|
||||||
Config.Autoconnect = periph.Identifier
|
|
||||||
saveConfig()
|
|
||||||
e.Peripheral.DiscoverServices()
|
|
||||||
page = hrpage
|
|
||||||
case ble.ConnectTimeoutEvent:
|
|
||||||
fmt.Printf("Connect timeout\n")
|
|
||||||
state = "timeout"
|
|
||||||
periphs = periphs[:0]
|
|
||||||
page = scanpage
|
|
||||||
Config.Autoconnect = ""
|
|
||||||
saveConfig()
|
|
||||||
b.Scan()
|
|
||||||
case ble.DiscoverServiceEvent:
|
|
||||||
fmt.Printf("DiscoverService %s\n", e.Gatt.UUID)
|
|
||||||
//if e.Gatt.UUID == "180D" {
|
|
||||||
if e.Gatt.IsHRM() {
|
|
||||||
fmt.Printf("Found HRM Service\n")
|
|
||||||
e.Peripheral.DiscoverCharacteristics(e.Service)
|
|
||||||
}
|
|
||||||
case ble.DiscoverCharacteristicEvent:
|
|
||||||
fmt.Printf("DiscoverCharacteristic %s\n", e.Gatt.UUID)
|
|
||||||
//if e.Gatt.UUID == "2A37" {
|
|
||||||
if e.Gatt.IsHRV() {
|
|
||||||
fmt.Printf("Found heart rate value\n")
|
|
||||||
e.Peripheral.SetNotifyValue(e.Characteristic)
|
|
||||||
}
|
|
||||||
case ble.UpdateValueEvent:
|
|
||||||
hr = hrDecode(e.Data)
|
|
||||||
}
|
|
||||||
w.Invalidate() // refresh on any Bluetooth event
|
|
||||||
case e := <-w.Events():
|
|
||||||
switch e := e.(type) {
|
|
||||||
case system.DestroyEvent:
|
|
||||||
return
|
|
||||||
case system.FrameEvent:
|
|
||||||
gtx.Reset(e.Config, e.Size)
|
|
||||||
resetSysinset(e.Insets)
|
|
||||||
sysinset.Layout(gtx, func() {
|
|
||||||
margin.Layout(gtx, page)
|
|
||||||
})
|
|
||||||
e.Frame(gtx.Ops)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user