diff --git a/crates/cansat-stm32f4/src/tasks.rs b/crates/cansat-stm32f4/src/tasks.rs index a2dfe3c..135e0d9 100644 --- a/crates/cansat-stm32f4/src/tasks.rs +++ b/crates/cansat-stm32f4/src/tasks.rs @@ -15,10 +15,31 @@ pub fn idle(mut ctx: app::idle::Context) -> ! { .quote(b'\'') .build(); + let mut takeoff_detection_readings = 0; + loop { let measurements = read_measurements(&mut ctx); defmt::info!("{}", measurements); + let Some(acc) = measurements.acceleration else { + panic!("No acceleration data"); + }; + + if takeoff_detection_readings >= 0 { + if acc.x < 0 { + takeoff_detection_readings += 1; + } else { + takeoff_detection_readings = 0; + } + + if takeoff_detection_readings == 3 { + defmt::info!("Cansat has taken off."); + takeoff_detection_readings = -1; + } else { + defmt::info!("Cansat has not yet taken off."); + } + } + let csv_record = match serde_csv_core::to_vec(&mut writer, &measurements) { Ok(r) => r, Err(e) => {