src: implement simulation data sources

This commit is contained in:
2025-09-24 08:32:34 +02:00
parent 19875f6ae5
commit 0cd2cc94b9
32 changed files with 389785 additions and 284 deletions

View File

@@ -1,7 +1,8 @@
use core::sync::atomic::{AtomicBool, AtomicU8};
use embassy_sync::{blocking_mutex::raw::{CriticalSectionRawMutex, NoopRawMutex}, channel::Channel};
use embassy_sync::{blocking_mutex::raw::{CriticalSectionRawMutex, NoopRawMutex}, channel::Channel, signal::Signal};
use figments::hardware::Brightness;
use nalgebra::{Vector2, Vector3};
#[derive(Clone, Copy, Default, Debug)]
@@ -18,9 +19,22 @@ pub enum Scene {
#[derive(Clone, Copy, Debug)]
pub enum Measurement {
// GPS coordinates
GPS(Vector2<f64>),
GPS(Option<Vector2<f64>>),
// Accelerometer values in body frame where x=forwards
IMU(Vector3<f32>)
IMU { accel: Vector3<f32>, gyro: Vector3<f32> },
}
#[derive(Clone, Copy, Debug)]
pub enum Prediction {
Location(Vector2<f32>),
Velocity(Vector2<f32>)
}
#[derive(Clone, Copy, Debug)]
pub enum Telemetry {
Prediction(Prediction),
Measurement(Measurement),
Notification(Notification)
}
#[derive(Clone, Copy, Debug)]
@@ -35,25 +49,53 @@ pub enum Notification {
SetBrakelight(bool)
}
#[derive(Debug)]
// TODO: Make this clone() able, so multiple threads can point to the same underlying atomics for the hardware controls
pub struct DisplayControls {
pub on: AtomicBool,
pub brightness: AtomicU8
pub brightness: AtomicU8,
pub render_is_running: Signal<CriticalSectionRawMutex, bool>
}
impl Brightness for DisplayControls {
fn set_brightness(&mut self, brightness: u8) {
self.brightness.store(brightness, core::sync::atomic::Ordering::Relaxed);
}
fn set_on(&mut self, is_on: bool) {
self.on.store(is_on, core::sync::atomic::Ordering::Relaxed);
}
// TODO: Split gamma out from brightness controls
fn set_gamma(&mut self, _gamma: f32) {
unimplemented!()
}
}
impl core::fmt::Debug for DisplayControls {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
f.debug_struct("DisplayControls")
.field("on", &self.on)
.field("brightness", &self.brightness)
.field("render_is_running", &self.render_is_running.signaled())
.finish()
}
}
impl Default for DisplayControls {
fn default() -> Self {
Self {
on: AtomicBool::new(true),
brightness: AtomicU8::new(255)
brightness: AtomicU8::new(255),
render_is_running: Signal::new()
}
}
}
#[derive(Debug)]
pub struct BusGarage {
pub motion: Channel<NoopRawMutex, Measurement, 4>,
pub scenes: Channel<CriticalSectionRawMutex, Notification, 4>,
pub motion: Channel<NoopRawMutex, Measurement, 5>,
pub scenes: Channel<CriticalSectionRawMutex, Notification, 5>,
pub telemetry: Channel<CriticalSectionRawMutex, Telemetry, 15>,
pub display: DisplayControls
}
@@ -62,6 +104,7 @@ impl Default for BusGarage {
Self {
motion: Channel::new(),
scenes: Channel::new(),
telemetry: Channel::new(),
display: Default::default()
}
}