events: rewrite some event buses to use multi-consumer pubsub instead of single-consumer channels
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use embassy_sync::channel::DynamicSender;
|
||||
use embassy_sync::{channel::DynamicSender, pubsub::DynPublisher};
|
||||
use embassy_time::{Duration, Instant};
|
||||
use nalgebra::{Rotation3, Vector2, Vector3};
|
||||
use log::*;
|
||||
@@ -7,7 +7,7 @@ use nalgebra::{ComplexField, RealField};
|
||||
|
||||
use core::fmt::Debug;
|
||||
|
||||
use crate::{ego::{heading::HeadingEstimator, kalman::Ekf2D, orientation::OrientationEstimator}, events::{Notification, Prediction}, Breaker, CircularBuffer, idle::IdleClock};
|
||||
use crate::{ego::{heading::HeadingEstimator, kalman::Ekf2D, orientation::OrientationEstimator}, events::{Notification, Prediction, Telemetry}, idle::IdleClock, Breaker, CircularBuffer};
|
||||
|
||||
#[derive(PartialEq, Debug, Default, Clone, Copy)]
|
||||
pub enum MotionState {
|
||||
@@ -104,15 +104,15 @@ impl BikeStates {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn commit(&mut self, predictions: &DynamicSender<'static, Prediction>, notifications: &DynamicSender<'static, Notification>) {
|
||||
pub async fn commit(&mut self, predictions: &DynamicSender<'static, Prediction>, notifications: &DynPublisher<'static, Notification>) {
|
||||
if let Some(true) = self.is_calibrated.read_tripped() {
|
||||
notifications.send(Notification::SensorOnline(crate::events::SensorSource::IMU)).await
|
||||
notifications.publish(Notification::SensorOnline(crate::events::SensorSource::IMU)).await
|
||||
}
|
||||
|
||||
match self.has_gps_fix.read_tripped() {
|
||||
None => (),
|
||||
Some(true) => notifications.send(Notification::SensorOnline(crate::events::SensorSource::GPS)).await,
|
||||
Some(false) => notifications.send(Notification::SensorOffline(crate::events::SensorSource::GPS)).await,
|
||||
Some(true) => notifications.publish(Notification::SensorOnline(crate::events::SensorSource::GPS)).await,
|
||||
Some(false) => notifications.publish(Notification::SensorOffline(crate::events::SensorSource::GPS)).await,
|
||||
}
|
||||
|
||||
let est = self.kf.x;
|
||||
@@ -167,7 +167,7 @@ impl BikeStates {
|
||||
// And if the motion status has changed, send it out
|
||||
if let Some(state) = self.motion_state.read_tripped() {
|
||||
debug!("state={state:?} trend={trend} mean={mean} v={v}");
|
||||
predictions.send(Prediction::Motion(state)).await
|
||||
predictions.send(Prediction::Motion(state)).await;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user