Created basic sinus output via postcard rpc.

This commit is contained in:
2025-08-06 18:26:28 +02:00
parent 3f9f3fedf5
commit 6b15a77cb5
2 changed files with 5 additions and 5 deletions

View File

@@ -163,7 +163,7 @@ static STOP: Mutex<ThreadModeRawMutex, bool> = Mutex::new(false);
#[embassy_executor::task] #[embassy_executor::task]
pub async fn start_impedance_handler(context: SpawnCtx, header: VarHeader, rqst: StartImpedance, sender: Sender<AppTx>) { pub async fn start_impedance_handler(context: SpawnCtx, header: VarHeader, rqst: StartImpedance, sender: Sender<AppTx>) {
info!("Start impedance measurement with interval {:?} ms.", rqst.interval_ms); info!("Start impedance measurement with rate {:?} Hz.", rqst.update_frequency);
let mut impedance = context.impedance.lock().await; let mut impedance = context.impedance.lock().await;
@@ -176,12 +176,12 @@ pub async fn start_impedance_handler(context: SpawnCtx, header: VarHeader, rqst:
return; return;
} }
let mut ticker = Ticker::every(Duration::from_millis(rqst.interval_ms.into())); let mut ticker = Ticker::every(Duration::from_hz(rqst.update_frequency.into()));
let mut seq: u8 = 0; let mut seq: u8 = 0;
while !*STOP.lock().await { while !*STOP.lock().await {
ticker.next().await; ticker.next().await;
impedance.update(); impedance.update(rqst.sinus_frequency);
let msg = Impedance { let msg = Impedance {
magnitude: impedance.magnitude, magnitude: impedance.magnitude,

View File

@@ -23,8 +23,8 @@ impl ImpedanceTest {
} }
} }
pub fn update(&mut self) { pub fn update(&mut self, frequency: f32) {
let frequency = 1.0; // Hz, adjust as needed // let frequency = 1.0; // Hz, adjust as needed
let current_time = self.time.elapsed().as_millis() as f32 / 1000.0; // Convert to seconds let current_time = self.time.elapsed().as_millis() as f32 / 1000.0; // Convert to seconds
self.magnitude = cosf(2.0 * PI * frequency * current_time); self.magnitude = cosf(2.0 * PI * frequency * current_time);