Added in seperate plots.

This commit is contained in:
2025-08-15 22:48:37 +02:00
parent 5537a991d3
commit 57ca3e313f
4 changed files with 57 additions and 25 deletions

View File

@@ -3,7 +3,9 @@ use log::{error, info};
use tokio::select;
use tokio::sync::mpsc::{Sender, Receiver};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
use atomic_float::AtomicF32;
use std::sync::{Arc, Mutex};
use crate::icd;
@@ -21,7 +23,18 @@ pub async fn communicate_with_hardware(
magnitude_series: Arc<Mutex<TimeSeriesPlot>>,
phase_series: Arc<Mutex<TimeSeriesPlot>>,
connected: Arc<AtomicBool>,
data_frequency: Arc<AtomicF32>,
) {
let data_counter = Arc::new(AtomicU32::new(0));
let data_counter_clone = data_counter.clone();
tokio::spawn(async move {
loop {
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
data_frequency.store(data_counter.load(Ordering::Relaxed) as f32, Ordering::Relaxed);
data_counter.store(0, Ordering::Relaxed);
}
});
#[derive(Default)]
struct Settings {
frequency: Option<FrequencySignal>,
@@ -52,6 +65,7 @@ pub async fn communicate_with_hardware(
.unwrap();
let data = (magnitude_series.clone(), phase_series.clone(), magnitude.clone(), phase.clone());
let data_counter_clone = data_counter_clone.clone();
tokio::spawn(async move {
while let Ok(val) = sub.recv().await {
@@ -65,6 +79,8 @@ pub async fn communicate_with_hardware(
mag_plot.add(val.magnitude as f64);
phase_plot.add(val.phase as f64);
data_counter_clone.fetch_add(1, Ordering::Relaxed);
}
info!("ImpedanceTopic subscription ended.");