-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
59 lines (46 loc) · 1.2 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import "C"
import (
"gioui.org/app"
"github.com/tarm/serial"
"log"
"time"
"uSDX/ambEmuLcd"
"uSDX/controls"
)
const uSdxDev = "/dev/serial/by-id/usb-Arduino_LLC_Arduino_Nano_Every_ACB4982851514746334C2020FF0E2053-if00"
func main() {
lcdEvents := make(chan interface{}, 100)
go gui(loop, lcdEvents)
uSdxConfig := &serial.Config{Name: uSdxDev, Baud: 500000, ReadTimeout: 50 * time.Millisecond}
uSdxPort, uSdxErr := serial.OpenPort(uSdxConfig)
if uSdxErr != nil {
log.Fatal(uSdxErr)
}
controls.InitLowLevelControls(uSdxPort)
controls.InitHighLevelControls()
controls.ForceRefresh()
go ambEmuLcd.ProcessSerialLcdData(uSdxPort, lcdEvents)
// TODO: Use ProcessPtyCat where Pty is available (e.g. Linux/Mac), else ProcessSerialCat (e.g. Windows)
go controls.ProcessPtyCat()
app.Main()
}
func loop(w *app.Window, lcdEvents chan interface{}) error {
for {
select {
case lcdEvt := <-lcdEvents:
w.Invalidate()
switch e := lcdEvt.(type) {
case *ambEmuLcd.Settled:
controls.HandleSettledEvent(e)
case ambEmuLcd.Updated:
// Nothing yet. Might not use.
}
case e := <-w.Events():
stop, evtErr := handleWindowEvent(e)
if stop {
return evtErr
}
}
}
}