mirror of
https://github.com/hubaldv/bioz-host-rs.git
synced 2025-12-06 05:11:17 +00:00
Added in seperate plots.
This commit is contained in:
@@ -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.");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user