tasks: gps: emit sensor statuses during init

This commit is contained in:
2025-12-07 12:53:29 +01:00
parent 567cc0d6e5
commit b98ca91f24

View File

@@ -8,14 +8,16 @@ use log::*;
use nalgebra::Vector2; use nalgebra::Vector2;
use nmea::Nmea; use nmea::Nmea;
use crate::{backoff::Backoff, events::Measurement}; use crate::{backoff::Backoff, events::{Measurement, SensorSource, SensorState}};
// FIXME: We need a way to put the GPS to sleep when the system goes to sleep // FIXME: We need a way to put the GPS to sleep when the system goes to sleep
#[embassy_executor::task] #[embassy_executor::task]
pub async fn gps_task(events: DynamicSender<'static, Measurement>, mut i2c_bus: I2cDevice<'static, CriticalSectionRawMutex, I2c<'static, Async>>) { pub async fn gps_task(events: DynamicSender<'static, Measurement>, mut i2c_bus: I2cDevice<'static, CriticalSectionRawMutex, I2c<'static, Async>>) {
Backoff::from_secs(5).forever().attempt::<_, (), ()>(async || { Backoff::from_secs(5).forever().attempt::<_, (), ()>(async || {
events.send(Measurement::SensorHardwareStatus(SensorSource::GPS, SensorState::Offline)).await;
Backoff::from_secs(5).forever().attempt(async || { Backoff::from_secs(5).forever().attempt(async || {
info!("Initializing GPS"); info!("Initializing GPS");
events.send(Measurement::SensorHardwareStatus(SensorSource::GPS, SensorState::AcquiringFix)).await;
// 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";
i2c_bus.write(0x10, bytes.as_bytes()).await?; i2c_bus.write(0x10, bytes.as_bytes()).await?;
@@ -38,6 +40,8 @@ pub async fn gps_task(events: DynamicSender<'static, Measurement>, mut i2c_bus:
let mut parser = Nmea::default(); let mut parser = Nmea::default();
let mut parsing = false; let mut parsing = false;
let mut has_lock = false; let mut has_lock = false;
events.send(Measurement::SensorHardwareStatus(SensorSource::GPS, SensorState::Online)).await;
events.send(Measurement::SensorHardwareStatus(SensorSource::Location, SensorState::AcquiringFix)).await;
info!("GPS is ready!"); info!("GPS is ready!");
loop { loop {
let mut buf = [0; 1]; let mut buf = [0; 1];