40 lines
1.3 KiB
Rust
40 lines
1.3 KiB
Rust
use nmea0183::{ParseResult, Parser};
|
|
use stm32f1xx_hal::{
|
|
delay::Delay,
|
|
prelude::*,
|
|
serial::{Config, Serial},
|
|
stm32,
|
|
};
|
|
|
|
use crate::application::App;
|
|
use crate::loc;
|
|
use crate::time;
|
|
|
|
impl App {
|
|
pub fn poll_gps(&mut self) -> () {
|
|
match self.serial.read() {
|
|
Ok(byte) => {
|
|
self.board_led.toggle().unwrap();
|
|
if let Some(result) = self.gps_parser.parse_from_byte(byte) {
|
|
match result {
|
|
Ok(ParseResult::GGA(Some(gga))) => {
|
|
if !self.transmitting {
|
|
time::set(&gga.time);
|
|
self.locator = loc::locator_from_coordinates(
|
|
gga.latitude.as_f64(),
|
|
gga.longitude.as_f64(),
|
|
);
|
|
defmt::info!("Got GGA. New locator: {}", self.locator.as_str());
|
|
}
|
|
}
|
|
Ok(_) => {} // Some other sentences..
|
|
Err(_) => {} // Got parse error
|
|
}
|
|
}
|
|
}
|
|
Err(nb::Error::WouldBlock) => {}
|
|
Err(nb::Error::Other(_)) => {}
|
|
}
|
|
}
|
|
}
|