generated from luke-else/esp32-std-template
Added GPS and display logic to event loop
This commit is contained in:
@@ -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> {
|
||||
|
18
src/main.rs
18
src/main.rs
@@ -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");
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user