2021-08-26 04:18:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"image/color"
|
|
|
|
|
|
|
|
"fyne.io/fyne/v2"
|
|
|
|
"fyne.io/fyne/v2/canvas"
|
|
|
|
"fyne.io/fyne/v2/container"
|
|
|
|
"fyne.io/fyne/v2/theme"
|
2021-10-24 20:27:14 +00:00
|
|
|
"go.arsenm.dev/itd/api"
|
2021-08-26 04:18:24 +00:00
|
|
|
)
|
|
|
|
|
2021-10-24 20:27:14 +00:00
|
|
|
func infoTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
2021-08-26 04:18:24 +00:00
|
|
|
infoLayout := container.NewVBox(
|
|
|
|
// Add rectangle for a bit of padding
|
|
|
|
canvas.NewRectangle(color.Transparent),
|
|
|
|
)
|
|
|
|
|
2021-08-26 15:47:17 +00:00
|
|
|
// Create label for heart rate
|
2021-08-26 04:18:24 +00:00
|
|
|
heartRateLbl := newText("0 BPM", 24)
|
2021-08-26 15:47:17 +00:00
|
|
|
// Creae container to store heart rate section
|
2021-10-25 07:11:41 +00:00
|
|
|
heartRateSect := container.NewVBox(
|
2021-08-26 04:18:24 +00:00
|
|
|
newText("Heart Rate", 12),
|
|
|
|
heartRateLbl,
|
|
|
|
canvas.NewLine(theme.ShadowColor()),
|
|
|
|
)
|
2021-10-25 07:11:41 +00:00
|
|
|
infoLayout.Add(heartRateSect)
|
2021-08-26 04:18:24 +00:00
|
|
|
|
2021-10-24 20:27:14 +00:00
|
|
|
heartRateCh, cancel, err := client.WatchHeartRate()
|
2021-10-25 07:11:41 +00:00
|
|
|
if err != nil {
|
|
|
|
guiErr(err, "Error getting heart rate channel", true, parent)
|
|
|
|
}
|
2021-10-24 20:27:14 +00:00
|
|
|
onClose = append(onClose, cancel)
|
|
|
|
go func() {
|
|
|
|
for heartRate := range heartRateCh {
|
|
|
|
// Change text of heart rate label
|
|
|
|
heartRateLbl.Text = fmt.Sprintf("%d BPM", heartRate)
|
|
|
|
// Refresh label
|
|
|
|
heartRateLbl.Refresh()
|
|
|
|
}
|
|
|
|
}()
|
2021-10-25 07:11:41 +00:00
|
|
|
|
|
|
|
// Create label for heart rate
|
|
|
|
stepCountLbl := newText("0 Steps", 24)
|
|
|
|
// Creae container to store heart rate section
|
|
|
|
stepCountSect := container.NewVBox(
|
|
|
|
newText("Step Count", 12),
|
|
|
|
stepCountLbl,
|
|
|
|
canvas.NewLine(theme.ShadowColor()),
|
|
|
|
)
|
|
|
|
infoLayout.Add(stepCountSect)
|
|
|
|
|
|
|
|
stepCountCh, cancel, err := client.WatchStepCount()
|
|
|
|
if err != nil {
|
|
|
|
guiErr(err, "Error getting step count channel", true, parent)
|
|
|
|
}
|
|
|
|
onClose = append(onClose, cancel)
|
|
|
|
go func() {
|
|
|
|
for stepCount := range stepCountCh {
|
|
|
|
// Change text of heart rate label
|
|
|
|
stepCountLbl.Text = fmt.Sprintf("%d Steps", stepCount)
|
|
|
|
// Refresh label
|
|
|
|
stepCountLbl.Refresh()
|
|
|
|
}
|
|
|
|
}()
|
2021-08-26 04:18:24 +00:00
|
|
|
|
2021-08-26 15:47:17 +00:00
|
|
|
// Create label for battery level
|
2021-08-26 04:18:24 +00:00
|
|
|
battLevelLbl := newText("0%", 24)
|
2021-08-26 15:47:17 +00:00
|
|
|
// Create container to store battery level section
|
2021-08-26 04:18:24 +00:00
|
|
|
battLevel := container.NewVBox(
|
|
|
|
newText("Battery Level", 12),
|
|
|
|
battLevelLbl,
|
|
|
|
canvas.NewLine(theme.ShadowColor()),
|
|
|
|
)
|
|
|
|
infoLayout.Add(battLevel)
|
|
|
|
|
2021-10-24 20:27:14 +00:00
|
|
|
battLevelCh, cancel, err := client.WatchBatteryLevel()
|
2021-10-25 07:11:41 +00:00
|
|
|
if err != nil {
|
|
|
|
guiErr(err, "Error getting battery level channel", true, parent)
|
|
|
|
}
|
2021-10-24 20:27:14 +00:00
|
|
|
onClose = append(onClose, cancel)
|
|
|
|
go func() {
|
|
|
|
for battLevel := range battLevelCh {
|
|
|
|
// Change text of battery level label
|
|
|
|
battLevelLbl.Text = fmt.Sprintf("%d%%", battLevel)
|
|
|
|
// Refresh label
|
|
|
|
battLevelLbl.Refresh()
|
|
|
|
}
|
|
|
|
}()
|
2021-08-26 04:18:24 +00:00
|
|
|
|
2021-10-24 20:27:14 +00:00
|
|
|
fwVerString, err := client.Version()
|
2021-08-26 04:18:24 +00:00
|
|
|
if err != nil {
|
2021-08-27 15:47:24 +00:00
|
|
|
guiErr(err, "Error getting firmware string", true, parent)
|
2021-08-26 04:18:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fwVer := container.NewVBox(
|
|
|
|
newText("Firmware Version", 12),
|
2021-10-24 20:27:14 +00:00
|
|
|
newText(fwVerString, 24),
|
2021-08-26 04:18:24 +00:00
|
|
|
canvas.NewLine(theme.ShadowColor()),
|
|
|
|
)
|
|
|
|
infoLayout.Add(fwVer)
|
|
|
|
|
2021-10-24 20:27:14 +00:00
|
|
|
btAddrString, err := client.Address()
|
2021-08-26 04:18:24 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
btAddr := container.NewVBox(
|
|
|
|
newText("Bluetooth Address", 12),
|
2021-10-24 20:27:14 +00:00
|
|
|
newText(btAddrString, 24),
|
2021-08-26 04:18:24 +00:00
|
|
|
canvas.NewLine(theme.ShadowColor()),
|
|
|
|
)
|
|
|
|
infoLayout.Add(btAddr)
|
|
|
|
|
|
|
|
return infoLayout
|
|
|
|
}
|
|
|
|
|
|
|
|
func newText(t string, size float32) *canvas.Text {
|
|
|
|
text := canvas.NewText(t, theme.ForegroundColor())
|
|
|
|
text.TextSize = size
|
|
|
|
return text
|
|
|
|
}
|