-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgps.go
48 lines (42 loc) · 824 Bytes
/
gps.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
package main
import (
"machine"
"time"
"tinygo.org/x/drivers/gps"
)
var fix gps.Fix
func startGPS() {
machine.UART0.Configure(machine.UARTConfig{BaudRate: 9600})
ublox := gps.NewUART(machine.UART0)
parser := gps.NewParser()
for {
s, err := ublox.NextSentence()
if err != nil {
continue
}
newfix, err := parser.Parse(s)
if err != nil {
continue
}
if newfix.Valid {
fix = newfix
print(fix.Time.Format("15:04:05"))
print(", lat=")
print(fix.Latitude)
print(", long=")
print(fix.Longitude)
print(", altitude=", fix.Altitude)
print(", satellites=", fix.Satellites)
if fix.Speed != 0 {
print(", speed=")
print(fix.Speed)
}
if fix.Heading != 0 {
print(", heading=")
print(fix.Heading)
}
println()
}
time.Sleep(200 * time.Millisecond)
}
}