-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.go
54 lines (47 loc) · 1.01 KB
/
core.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
package gpsinfo
import (
"time"
"paepcke.de/gpsinfo/gpsfeed"
)
// const
const (
ecoSleep = time.Duration(90 * time.Millisecond)
displaySleep = time.Duration(ecoSleep / 2)
maxDiff = time.Duration(2 * time.Second)
)
// debug ...
func debug(dev *gpsfeed.GpsDevice) {
// setup
channelOut := make(chan string, 10)
channelGpsFrames := make(chan string, 50)
for {
// spin up background bufio sentence fetcher/filter process
go func() {
dev.Open()
for dev.Feed.Scan() {
sentence := dev.Feed.Text()
dev.Responsive.Store(true)
l := len(sentence)
if l > 15 && l < 256 {
if sentence[0] == '$' {
dev.DataValid.Store(true)
channelGpsFrames <- sentence
}
}
time.Sleep(ecoSleep)
}
close(channelGpsFrames)
}()
// spin up background Display outout handler
go func() {
for s := range channelOut {
out(s)
}
}()
// builder loop
build(dev, channelGpsFrames, channelOut, displaySleep)
close(channelGpsFrames)
close(channelOut)
dev.Close()
}
}