78 lines
1.6 KiB
Go
78 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"adam-gui/comms"
|
|
"image/color"
|
|
|
|
"fyne.io/fyne/v2"
|
|
"fyne.io/fyne/v2/app"
|
|
"fyne.io/fyne/v2/canvas"
|
|
"fyne.io/fyne/v2/container"
|
|
"fyne.io/fyne/v2/widget"
|
|
"go.bug.st/serial"
|
|
)
|
|
|
|
func main() {
|
|
init := false
|
|
var port serial.Port
|
|
|
|
a := app.New()
|
|
w := a.NewWindow("ADAM GUI (fuck proprietary software.)")
|
|
w.Resize(fyne.NewSize(340, 200))
|
|
status := canvas.NewText("Waiting", color.White)
|
|
status.Alignment = fyne.TextAlignCenter
|
|
status.TextSize = 50
|
|
status.Color = color.NRGBA{255, 170, 50, 255}
|
|
|
|
w.SetContent(container.NewVBox(
|
|
status,
|
|
widget.NewButton("Establish communications", func() {
|
|
if !init {
|
|
if comms.SetDefaultSerialPort() {
|
|
port = comms.EstablishComms()
|
|
init = true
|
|
status.Text = "Connected"
|
|
status.TextSize = 50
|
|
status.Color = color.NRGBA{255, 255, 255, 255}
|
|
status.Refresh()
|
|
} else {
|
|
status.Text = "Cannot detect a device with the given name."
|
|
status.TextSize = 25
|
|
status.Color = color.NRGBA{255, 50, 50, 255}
|
|
status.Refresh()
|
|
}
|
|
}
|
|
}),
|
|
widget.NewButton("Tare", func() {
|
|
if init {
|
|
comms.Tare(port)
|
|
}
|
|
}),
|
|
widget.NewButton("Hold", func() {
|
|
if init {
|
|
comms.Hold(port)
|
|
}
|
|
}),
|
|
widget.NewButton("Measure (net)", func() {
|
|
if init {
|
|
status.Text = comms.Measure(port, "N")
|
|
status.Refresh()
|
|
}
|
|
}),
|
|
widget.NewButton("Measure (gross)", func() {
|
|
if init {
|
|
status.Text = comms.Measure(port, "G")
|
|
status.Refresh()
|
|
}
|
|
}),
|
|
widget.NewButton("Measure (tare)", func() {
|
|
if init {
|
|
status.Text = comms.Measure(port, "T")
|
|
status.Refresh()
|
|
}
|
|
}),
|
|
))
|
|
|
|
w.ShowAndRun()
|
|
}
|