cargo: gate motion sim behind feature flag

This commit is contained in:
2025-09-24 08:53:15 +02:00
parent 0cd2cc94b9
commit 019d134022
4 changed files with 51 additions and 32 deletions

View File

@@ -8,6 +8,9 @@ version = "0.1.0"
name = "renderbug-embassy" name = "renderbug-embassy"
path = "./src/bin/main.rs" path = "./src/bin/main.rs"
[features]
simulation = ["dep:csv-core"]
[dependencies] [dependencies]
figments = { path = "../figments/figments/", features = ["alloc"] } figments = { path = "../figments/figments/", features = ["alloc"] }
esp-bootloader-esp-idf = { version = "0.2.0", features = ["esp32s3"] } esp-bootloader-esp-idf = { version = "0.2.0", features = ["esp32s3"] }
@@ -94,7 +97,7 @@ nalgebra = { version = "0.33.2", default-features = false }
esp-storage = { version = "0.7.0", features = ["esp32s3"] } esp-storage = { version = "0.7.0", features = ["esp32s3"] }
bleps = { git = "https://github.com/bjoernQ/bleps", package = "bleps", rev = "a5148d8ae679e021b78f53fd33afb8bb35d0b62e", features = [ "macros", "async"] } bleps = { git = "https://github.com/bjoernQ/bleps", package = "bleps", rev = "a5148d8ae679e021b78f53fd33afb8bb35d0b62e", features = [ "macros", "async"] }
serde_json = {version = "1.0.145", default-features = false, features = ["alloc"] } serde_json = {version = "1.0.145", default-features = false, features = ["alloc"] }
csv-core = "0.1.12" csv-core = {version = "0.1.12", optional = true }
kfilter = "0.4.0" kfilter = "0.4.0"
[profile.dev] [profile.dev]

View File

@@ -12,38 +12,48 @@ use core::ptr::addr_of_mut;
use bleps::ad_structure::{create_advertising_data, AdStructure, BR_EDR_NOT_SUPPORTED, LE_GENERAL_DISCOVERABLE}; use bleps::ad_structure::{create_advertising_data, AdStructure, BR_EDR_NOT_SUPPORTED, LE_GENERAL_DISCOVERABLE};
use bleps::attribute_server::{AttributeServer, NotificationData}; use bleps::attribute_server::{AttributeServer, NotificationData};
use bleps::{gatt, Ble, HciConnector}; use bleps::{gatt, Ble, HciConnector};
use embassy_embedded_hal::shared_bus::asynch::i2c::I2cDevice;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
use embassy_sync::channel::DynamicReceiver; use embassy_sync::channel::DynamicReceiver;
use embassy_sync::mutex::Mutex;
use embassy_time::{Instant, Timer}; use embassy_time::{Instant, Timer};
use esp_backtrace as _; use esp_backtrace as _;
use esp_hal::gpio::Pin; use esp_hal::{
use esp_hal::i2c::master::{Config, I2c}; gpio::Pin,
use esp_hal::interrupt::software::SoftwareInterruptControl; interrupt::software::SoftwareInterruptControl,
use esp_hal::system::{AppCoreGuard, CpuControl, Stack}; clock::CpuClock,
use esp_hal::timer::AnyTimer; system::{AppCoreGuard, CpuControl, Stack},
use esp_hal::Async; timer::{AnyTimer, systimer::SystemTimer, timg::TimerGroup}
use esp_hal::clock::CpuClock; };
use esp_hal::time::Rate;
use esp_hal::timer::systimer::SystemTimer;
use esp_hal::timer::timg::TimerGroup;
use esp_hal_embassy::{Executor, InterruptExecutor}; use esp_hal_embassy::{Executor, InterruptExecutor};
use esp_wifi::ble::controller::BleConnector; use esp_wifi::ble::controller::BleConnector;
use figments::surface::BufferedSurfacePool; use figments::surface::BufferedSurfacePool;
use log::info; use log::info;
use renderbug_embassy::events::{BusGarage, Measurement, Telemetry}; use renderbug_embassy::events::{BusGarage, Measurement, Telemetry};
use renderbug_embassy::tasks::simulation::{motion_simulation_task, location_simulation_task};
use renderbug_embassy::tasks::ui::{Ui, ui_main};
use renderbug_embassy::tasks::gps::gps_task;
use renderbug_embassy::tasks::motion::motion_task;
use serde_json::json; use serde_json::json;
use static_cell::StaticCell; use static_cell::StaticCell;
use renderbug_embassy::{ #[cfg(feature="simulation")]
tasks::mpu::*, use renderbug_embassy::tasks::simulation::{motion_simulation_task, location_simulation_task};
tasks::render::render #[cfg(not(feature="simulation"))]
use renderbug_embassy::tasks::{gps::gps_task, mpu::mpu_task};
#[cfg(not(feature="simulation"))]
use embassy_embedded_hal::shared_bus::asynch::i2c::I2cDevice;
#[cfg(not(feature="simulation"))]
use esp_hal::{
time::Rate,
i2c::master::{Config, I2c},
Async,
};
#[cfg(not(feature="simulation"))]
use embassy_sync::{
mutex::Mutex,
blocking_mutex::raw::CriticalSectionRawMutex
};
use renderbug_embassy::tasks::{
render::render,
motion::motion_task,
ui::{Ui, ui_main}
}; };
extern crate alloc; extern crate alloc;
@@ -51,7 +61,9 @@ extern crate alloc;
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description> // For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
esp_bootloader_esp_idf::esp_app_desc!(); esp_bootloader_esp_idf::esp_app_desc!();
#[cfg(not(feature="simulation"))]
static I2C_BUS: StaticCell<Mutex<CriticalSectionRawMutex, I2c<'static, Async>>> = StaticCell::new(); static I2C_BUS: StaticCell<Mutex<CriticalSectionRawMutex, I2c<'static, Async>>> = StaticCell::new();
static BUS_GARAGE: StaticCell<BusGarage> = StaticCell::new(); static BUS_GARAGE: StaticCell<BusGarage> = StaticCell::new();
static mut CORE2_STACK: Stack<8192> = Stack::new(); static mut CORE2_STACK: Stack<8192> = Stack::new();
static CORE_HANDLE: StaticCell<AppCoreGuard> = StaticCell::new(); static CORE_HANDLE: StaticCell<AppCoreGuard> = StaticCell::new();
@@ -81,16 +93,20 @@ async fn main(spawner: Spawner) {
let hi_spawn = hi_exec.start(esp_hal::interrupt::Priority::Priority1); let hi_spawn = hi_exec.start(esp_hal::interrupt::Priority::Priority1);
hi_spawn.must_spawn(render(peripherals.RMT, peripherals.GPIO5.degrade(), surfaces, &garage.display)); hi_spawn.must_spawn(render(peripherals.RMT, peripherals.GPIO5.degrade(), surfaces, &garage.display));
info!("Launching i2c sensor tasks"); #[cfg(not(feature="simulation"))]
let i2c = I2c::new(peripherals.I2C1, Config::default().with_frequency(Rate::from_khz(400)).with_timeout(esp_hal::i2c::master::BusTimeout::Maximum)).unwrap().with_scl(peripherals.GPIO4).with_sda(peripherals.GPIO3).into_async(); {
let i2c_bus = I2C_BUS.init(Mutex::new(i2c)); info!("Launching i2c sensor tasks");
let i2c = I2c::new(peripherals.I2C1, Config::default().with_frequency(Rate::from_khz(400)).with_timeout(esp_hal::i2c::master::BusTimeout::Maximum)).unwrap().with_scl(peripherals.GPIO4).with_sda(peripherals.GPIO3).into_async();
let i2c_bus = I2C_BUS.init(Mutex::new(i2c));
spawner.must_spawn(mpu_task(garage.motion.dyn_sender(), I2cDevice::new(i2c_bus)));
spawner.must_spawn(gps_task(garage.motion.dyn_sender(), I2cDevice::new(i2c_bus)));
}
spawner.must_spawn(mpu_task(garage.motion.dyn_sender(), I2cDevice::new(i2c_bus))); #[cfg(feature="simulation")]
spawner.must_spawn(gps_task(garage.motion.dyn_sender(), I2cDevice::new(i2c_bus))); {
spawner.must_spawn(motion_simulation_task(garage.motion.dyn_sender()));
// TODO: Only run the motion sim sources with cfg(simulation) spawner.must_spawn(location_simulation_task(garage.motion.dyn_sender()));
spawner.must_spawn(motion_simulation_task(garage.motion.dyn_sender())); }
spawner.must_spawn(location_simulation_task(garage.motion.dyn_sender()));
info!("Launching motion engine"); info!("Launching motion engine");
spawner.must_spawn(motion_task(garage.motion.dyn_receiver(), garage.scenes.dyn_sender(), garage.telemetry.dyn_sender())); spawner.must_spawn(motion_task(garage.motion.dyn_receiver(), garage.scenes.dyn_sender(), garage.telemetry.dyn_sender()));

View File

@@ -3,4 +3,5 @@ pub mod render;
pub mod motion; pub mod motion;
pub mod gps; pub mod gps;
pub mod ui; pub mod ui;
#[cfg(feature="simulation")]
pub mod simulation; pub mod simulation;

View File

@@ -1,8 +1,7 @@
use embassy_sync::channel::DynamicSender; use embassy_sync::channel::DynamicSender;
use csv_core::{ReadFieldResult, Reader};
use embassy_time::{Duration, Timer}; use embassy_time::{Duration, Timer};
use nalgebra::{Vector2, Vector3}; use nalgebra::{Vector2, Vector3};
use csv_core::{ReadFieldResult, Reader};
use crate::events::Measurement; use crate::events::Measurement;