tasks: gps: drop complicated usage of Backoff
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
use embassy_embedded_hal::shared_bus::asynch::i2c::I2cDevice;
|
use embassy_embedded_hal::shared_bus::{I2cDeviceError, asynch::i2c::I2cDevice};
|
||||||
use embassy_sync::{blocking_mutex::raw::NoopRawMutex, channel::DynamicSender};
|
use embassy_sync::{blocking_mutex::raw::NoopRawMutex, channel::DynamicSender};
|
||||||
use embassy_time::Timer;
|
use embassy_time::Timer;
|
||||||
use embedded_hal_async::i2c::I2c as _;
|
use embedded_hal_async::i2c::I2c as _;
|
||||||
@@ -8,14 +8,9 @@ use log::*;
|
|||||||
use nalgebra::Vector2;
|
use nalgebra::Vector2;
|
||||||
use nmea::{Nmea, sentences::FixType};
|
use nmea::{Nmea, sentences::FixType};
|
||||||
|
|
||||||
use crate::{backoff::Backoff, events::{Measurement, SensorSource, SensorState}};
|
use crate::{events::{Measurement, SensorSource, SensorState}};
|
||||||
|
|
||||||
// FIXME: We need a way to put the GPS to sleep when the system goes to sleep
|
async fn init_gps(i2c_bus: &mut I2cDevice<'static, NoopRawMutex, I2c<'static, Async>>) -> Result<(), I2cDeviceError<esp_hal::i2c::master::Error>> {
|
||||||
#[embassy_executor::task]
|
|
||||||
pub async fn gps_task(events: DynamicSender<'static, Measurement>, mut i2c_bus: I2cDevice<'static, NoopRawMutex, I2c<'static, Async>>) {
|
|
||||||
Backoff::from_secs(5).forever().attempt::<_, (), ()>(async || {
|
|
||||||
events.send(Measurement::SensorHardwareStatus(SensorSource::GPS, SensorState::Offline)).await;
|
|
||||||
Backoff::from_secs(5).forever().attempt(async || {
|
|
||||||
info!("Initializing GPS");
|
info!("Initializing GPS");
|
||||||
// Enable a bunch of data? idk
|
// Enable a bunch of data? idk
|
||||||
let bytes = "$PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n";
|
let bytes = "$PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n";
|
||||||
@@ -32,7 +27,16 @@ pub async fn gps_task(events: DynamicSender<'static, Measurement>, mut i2c_bus:
|
|||||||
// Antenna updates
|
// Antenna updates
|
||||||
let bytes = "$PGCMD,33,1*6C\r\n";
|
let bytes = "$PGCMD,33,1*6C\r\n";
|
||||||
i2c_bus.write(0x10, bytes.as_bytes()).await
|
i2c_bus.write(0x10, bytes.as_bytes()).await
|
||||||
}).await.unwrap();
|
}
|
||||||
|
|
||||||
|
// FIXME: We need a way to put the GPS to sleep when the system goes to sleep
|
||||||
|
#[embassy_executor::task]
|
||||||
|
pub async fn gps_task(events: DynamicSender<'static, Measurement>, mut i2c_bus: I2cDevice<'static, NoopRawMutex, I2c<'static, Async>>) {
|
||||||
|
events.send(Measurement::SensorHardwareStatus(SensorSource::GPS, SensorState::Offline)).await;
|
||||||
|
if let Err(e) = init_gps(&mut i2c_bus).await {
|
||||||
|
error!("Failed to initialize GPS: {e:?}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let mut strbuf = String::new();
|
let mut strbuf = String::new();
|
||||||
|
|
||||||
@@ -94,5 +98,4 @@ pub async fn gps_task(events: DynamicSender<'static, Measurement>, mut i2c_bus:
|
|||||||
Timer::after_millis(500).await;
|
Timer::after_millis(500).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).await.ok();
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user