mirror of
https://github.com/hubaldv/bioz-host-rs.git
synced 2026-07-24 00:57:44 +00:00
Pass electrode config from GUI to hardware.
This commit is contained in:
@@ -5,12 +5,12 @@ use log::{error, info};
|
||||
use tokio::select;
|
||||
use tokio::sync::mpsc::{Receiver, Sender};
|
||||
|
||||
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
use atomic_float::AtomicF32;
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use bioz_icd_rs::MeasurementPointSet;
|
||||
use bioz_icd_rs::{MeasurementPointSet, MultiplexerCapability};
|
||||
|
||||
use crate::icd;
|
||||
use crate::client::WorkbookClient;
|
||||
@@ -20,6 +20,8 @@ use crate::plot::{TimeSeriesPlot, BodePlot};
|
||||
|
||||
use crate::signals::{LoggingSignal, StartStopSignal};
|
||||
|
||||
use crate::app::HardwareConnected;
|
||||
|
||||
pub async fn communicate_with_hardware(
|
||||
mut run_impedancemeter_rx: Receiver<StartStopSignal>,
|
||||
run_impedancemeter_tx: Sender<StartStopSignal>,
|
||||
@@ -28,7 +30,7 @@ pub async fn communicate_with_hardware(
|
||||
magnitude_series: Arc<Mutex<TimeSeriesPlot>>,
|
||||
phase_series: Arc<Mutex<TimeSeriesPlot>>,
|
||||
bode_series: Arc<Mutex<BodePlot>>,
|
||||
connected: Arc<AtomicBool>,
|
||||
connected: Arc<Mutex<HardwareConnected>>,
|
||||
data_frequency: Arc<AtomicF32>,
|
||||
periods_per_dft: Arc<Mutex<Option<f32>>>,
|
||||
periods_per_dft_sweep: Arc<Mutex<(Vec<u32>, Option<Vec<f32>>)>>,
|
||||
@@ -58,7 +60,16 @@ pub async fn communicate_with_hardware(
|
||||
if let Some(frequency) = settings.lock().unwrap().frequency {
|
||||
run_impedancemeter_tx.send(frequency).await.unwrap();
|
||||
}
|
||||
connected.store(true, Ordering::Relaxed);
|
||||
match client.get_device_info().await.unwrap() {
|
||||
MultiplexerCapability::Absent => {
|
||||
*connected.lock().unwrap() = HardwareConnected::WithoutMultiplexer;
|
||||
info!("Connected device: Without Multiplexer");
|
||||
},
|
||||
MultiplexerCapability::Present => {
|
||||
*connected.lock().unwrap() = HardwareConnected::WithMultiplexer;
|
||||
info!("Connected device: With Multiplexer");
|
||||
},
|
||||
}
|
||||
client
|
||||
},
|
||||
Err(e) => {
|
||||
@@ -104,7 +115,7 @@ pub async fn communicate_with_hardware(
|
||||
if *gui_logging_state_clone.lock().unwrap() == LoggingStates::Logging {
|
||||
let settings = *settings_clone.lock().unwrap();
|
||||
match settings.frequency {
|
||||
Some(StartStopSignal::StartSingle(freq, _, _)) => {
|
||||
Some(StartStopSignal::StartSingle(freq, _, _, _)) => {
|
||||
if let Err(e) = log_tx_clone.try_send(LoggingSignal::SingleImpedance(SystemTime::now(), freq, val.magnitude, val.phase)) {
|
||||
error!("Failed to send logging signal: {:?}", e);
|
||||
}
|
||||
@@ -178,11 +189,11 @@ pub async fn communicate_with_hardware(
|
||||
select! {
|
||||
Some(frequency) = run_impedancemeter_rx.recv() => {
|
||||
match frequency {
|
||||
StartStopSignal::StartSingle(freq, lead_mode, dft_num) => {
|
||||
match workbook_client.start_impedancemeter_single(freq, lead_mode, dft_num).await {
|
||||
StartStopSignal::StartSingle(freq, lead_mode, electrode_config, dft_num) => {
|
||||
match workbook_client.start_impedancemeter_single(freq, lead_mode, electrode_config, dft_num).await {
|
||||
Ok(Ok(periods)) => {
|
||||
info!("Impedance meter started at frequency: {} with periods per DFT: {}", freq, periods);
|
||||
settings.lock().unwrap().frequency = Some(StartStopSignal::StartSingle(freq, lead_mode, dft_num));
|
||||
settings.lock().unwrap().frequency = Some(StartStopSignal::StartSingle(freq, lead_mode, electrode_config, dft_num));
|
||||
*periods_per_dft.lock().unwrap() = Some(periods);
|
||||
},
|
||||
Ok(Err(e)) => {
|
||||
@@ -195,10 +206,10 @@ pub async fn communicate_with_hardware(
|
||||
}
|
||||
}
|
||||
},
|
||||
StartStopSignal::StartSweep(lead_mode, num_points) => {
|
||||
match workbook_client.start_impedancemeter_sweep(lead_mode, num_points).await {
|
||||
StartStopSignal::StartSweep(lead_mode, electrode_config, num_points) => {
|
||||
match workbook_client.start_impedancemeter_sweep(lead_mode, electrode_config, num_points).await {
|
||||
Ok(Ok(periods)) => {
|
||||
settings.lock().unwrap().frequency = Some(StartStopSignal::StartSweep(lead_mode, num_points));
|
||||
settings.lock().unwrap().frequency = Some(StartStopSignal::StartSweep(lead_mode, electrode_config, num_points));
|
||||
info!("Sweep Impedancemeter started.");
|
||||
match num_points {
|
||||
MeasurementPointSet::Eight => {
|
||||
@@ -246,7 +257,7 @@ pub async fn communicate_with_hardware(
|
||||
}
|
||||
}
|
||||
info!("Communication with hardware ended.");
|
||||
connected.store(false, Ordering::Relaxed);
|
||||
*connected.lock().unwrap() = HardwareConnected::None;
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user