Added GPS and display logic to event loop

This commit is contained in:
2023-11-13 15:03:30 +00:00
parent d64dd4b0fa
commit 7f35146eea
3 changed files with 81 additions and 6 deletions

View File

@@ -22,7 +22,8 @@ pub enum GpsError {
pub struct GPS<'a> {
uart: uart::UartRxDriver<'a>,
latest: gpsdata::GpsData
latest: gpsdata::GpsData,
current: gpsdata::GpsData
}
impl<'a> GPS<'a> {
@@ -42,7 +43,12 @@ impl<'a> GPS<'a> {
&config
).map_err(|err| Error::EspError(err))?;
Ok(GPS { uart, latest: gpsdata::GpsData::default() })
// Create GPS struct
Ok(GPS {
uart,
latest: gpsdata::GpsData::default(),
current: gpsdata::GpsData::default()
})
}
pub fn poll(self: &mut GPS<'a>) -> Result<&gpsdata::GpsData, Error> {

View File

@@ -46,10 +46,20 @@ fn main() -> Result<(), Error> {
&config
).map_err(|err| Error::EspError(err))?;
let gps: GPS = GPS::new(peripherals.uart0, gps_rx)?;
let display: Display<DisplaySize128x64> = Display::new(i2c, DisplaySize128x64, DisplayRotation::Rotate0)?;
let mut gps: GPS = GPS::new(peripherals.uart0, gps_rx)?;
let mut display: Display<DisplaySize128x64> = Display::new(i2c, DisplaySize128x64, DisplayRotation::Rotate0)?;
let mut app_state = appstate::AppState::default();
let mut latest_data = gpsdata::GpsData::default();
Err(error::Error::DisplayError(DisplayError::DrawingError))
loop {
let text: &str;
// Get the latest data from GPS module and flush to Display
match gps.poll() {
Ok(res) => {display.draw(&res.get_speed().as_str())?},
Err(e) => {
display.draw("NO\nGPS\nDATA");
},
}
}
}