mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-03 06:27:47 +00:00
0b6bfda8cf
This is in preparation of PR https://github.com/tinygo-org/tinygo/pull/1693, which makes machine.I2C0 and similar objects of pointer type, so they can be freely passed around.
51 lines
870 B
Go
51 lines
870 B
Go
package main
|
|
|
|
import (
|
|
"machine"
|
|
"time"
|
|
|
|
"tinygo.org/x/drivers/gps"
|
|
)
|
|
|
|
func main() {
|
|
println("GPS I2C Example")
|
|
machine.I2C0.Configure(machine.I2CConfig{})
|
|
ublox := gps.NewI2C(machine.I2C0)
|
|
parser := gps.NewParser()
|
|
var fix gps.Fix
|
|
for {
|
|
s, err := ublox.NextSentence()
|
|
if err != nil {
|
|
println(err)
|
|
continue
|
|
}
|
|
|
|
fix, err = parser.Parse(s)
|
|
if err != nil {
|
|
println(err)
|
|
continue
|
|
}
|
|
if fix.Valid {
|
|
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()
|
|
} else {
|
|
println("No fix")
|
|
}
|
|
time.Sleep(200 * time.Millisecond)
|
|
}
|
|
}
|