diff --git a/src/detector.rs b/src/detector.rs index ce140d6..0d6f141 100644 --- a/src/detector.rs +++ b/src/detector.rs @@ -18,9 +18,9 @@ use crate::{ adc::AdcDriver, pwm::PwmDriver, rtc::GlobalRtc, - state::{DEVICE_STATE, DeviceState}, - updates::{NET_CHANNEL, NetDataSender}, - utils::{static_alloc, try_buffer, try_static_timestamped_block_vecs}, + state::{DeviceState, DEVICE_STATE}, + updates::{NetDataSender, NET_CHANNEL}, + utils::{static_alloc, try_buffer, try_static_timestamped_block_vecs}, BLOCK_SIZE, }; #[embassy_executor::task] @@ -29,15 +29,15 @@ pub async fn detector_task( pwm: PwmDriver<'static>, rtc: GlobalRtc<'static>, ) { + info!("Waiting for RTC to start running"); while !rtc.is_running().await { - info!("Waiting for RTC to start running"); Timer::after_secs(2).await; } let net_data = NET_CHANNEL.sender(); info!("Allocating detector resources"); let blocks = unwrap!( - try_static_timestamped_block_vecs(4, 512), + try_static_timestamped_block_vecs(4, BLOCK_SIZE), "Couldn't allocate block buffers" ); @@ -51,7 +51,7 @@ pub async fn detector_task( let mut peaks = Vec::new(); unwrap!( - peaks.try_reserve_exact(512), + peaks.try_reserve_exact(BLOCK_SIZE), "Failed to allocate peaks buffer" ); diff --git a/src/detector/data.rs b/src/detector/data.rs index 77ae8b3..470a47b 100644 --- a/src/detector/data.rs +++ b/src/detector/data.rs @@ -20,7 +20,10 @@ pub(super) fn transmit_strike( .try_send(crate::updates::Update::Strike { timestamp, peaks: peaks.to_vec(), - samples: samples.to_vec(), + samples: samples + .iter() + .map(|&sample| (average as i16).saturating_sub_unsigned(sample)) + .collect(), average, }) .ok(); diff --git a/src/updates.rs b/src/updates.rs index 129d4d6..db8d2b9 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -17,7 +17,7 @@ pub enum Update { Strike { timestamp: i64, peaks: Vec, - samples: Vec, + samples: Vec, average: u16, }, }