events: rewrite the eventing system to reduce mutex usage to just the measurement bus
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
|
||||
use embassy_sync::{blocking_mutex::raw::{CriticalSectionRawMutex, NoopRawMutex}, channel::Channel, pubsub::PubSubChannel};
|
||||
use embassy_sync::{blocking_mutex::raw::NoopRawMutex, pubsub::PubSubChannel};
|
||||
use embassy_time::Duration;
|
||||
use enum_map::Enum;
|
||||
use enumset::EnumSetType;
|
||||
use nalgebra::{Vector2, Vector3};
|
||||
|
||||
use crate::{graphics::display::DisplayControls, ego::engine::MotionState};
|
||||
use crate::ego::engine::MotionState;
|
||||
|
||||
#[derive(Clone, Copy, Default, Debug)]
|
||||
pub enum Scene {
|
||||
@@ -47,14 +47,24 @@ pub enum Measurement {
|
||||
Annotation
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum Personality {
|
||||
Sleeping, // System should be using as low power as possible, displays off, etc
|
||||
#[default]
|
||||
Waking, // System is resuming from sleep, or it is the first boot. A transient state that quickly turns into Active.
|
||||
Parked, // System should be acting like an art piece with some idle animations, maybe it can search for some wifi/bluetooth
|
||||
Active // System is almost likely on the road and must provide lighting
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum Prediction {
|
||||
Motion(MotionState),
|
||||
Motion { prev: MotionState, next: MotionState },
|
||||
Velocity(f32),
|
||||
Location(Vector2<f64>),
|
||||
WakeRequested,
|
||||
// States of external connections to the world
|
||||
SensorStatus(SensorSource, SensorState),
|
||||
// The system should enter into one of the four personalities
|
||||
SetPersonality(Personality)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@@ -77,12 +87,6 @@ pub enum Notification {
|
||||
Beat,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum Telemetry {
|
||||
Notification(Notification),
|
||||
Prediction(Prediction),
|
||||
}
|
||||
|
||||
// GPS data = 2, motion data = 1
|
||||
#[derive(Debug, EnumSetType, Enum)]
|
||||
pub enum SensorSource {
|
||||
@@ -117,16 +121,14 @@ impl TryFrom<i8> for SensorSource {
|
||||
#[derive(Debug)]
|
||||
pub struct BusGarage {
|
||||
pub notify: PubSubChannel<NoopRawMutex, Notification, 5, 2, 4>,
|
||||
pub predict: Channel<NoopRawMutex, Prediction, 15>,
|
||||
pub telemetry: PubSubChannel<NoopRawMutex, Telemetry, 15, 2, 4>
|
||||
pub predict: PubSubChannel<NoopRawMutex, Prediction, 15, 3, 3>,
|
||||
}
|
||||
|
||||
impl Default for BusGarage {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
notify: PubSubChannel::new(),
|
||||
predict: Channel::new(),
|
||||
telemetry: PubSubChannel::new()
|
||||
predict: PubSubChannel::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user