From 26e9c4dcab9af9c6c54d87a3f19c54b6c8fc68c9 Mon Sep 17 00:00:00 2001 From: Hubald Verzijl Date: Tue, 7 Oct 2025 12:59:28 +0200 Subject: [PATCH] Show periods per DFT in GUI. --- src/app.rs | 21 +++++++++++++++++++++ src/bin/main_gui.rs | 3 +++ src/client.rs | 8 ++++---- src/communication.rs | 22 ++++++++++++++++------ 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/app.rs b/src/app.rs index f9967c4..0b0c7f2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -47,6 +47,7 @@ pub struct App { pub data_frequency: Arc, pub single_frequency: Arc>, pub dft_num: Arc>, + pub periods_per_dft: Arc>>, } struct TabViewer { @@ -58,6 +59,7 @@ struct TabViewer { on: Arc>, single_frequency: Arc>, dft_num: Arc>, + periods_per_dft: Arc>>, show_settings: bool, show_settings_toggle: Option, } @@ -93,6 +95,22 @@ impl TabViewer { }; }); }); + ui.add_enabled_ui(*on, |ui| { + ui.horizontal(|ui| { + ui.label("Periods per DFT:"); + match (*on, *self.periods_per_dft.lock().unwrap()) { + (true, Some(periods)) => { + ui.add(Label::new(format!("{:.2}", periods))); + }, + (true, None) => { + ui.add(Label::new("N/A")); + }, + (false, _) => { + ui.add(Label::new("Start to determine!")); + } + } + }); + }); } }); @@ -337,6 +355,7 @@ impl App { let bode_plot = Arc::new(Mutex::new(BodePlot::new())); let single_frequency = Arc::new(Mutex::new(50000)); let dft_num = Arc::new(Mutex::new(IcdDftNum::Num2048)); + let periods_per_dft = Arc::new(Mutex::new(None)); let on = Arc::new(Mutex::new(true)); let tab_active = TabActive::Single; @@ -349,6 +368,7 @@ impl App { bode_plot: bode_plot.clone(), single_frequency: single_frequency.clone(), dft_num: dft_num.clone(), + periods_per_dft: periods_per_dft.clone(), on: on.clone(), show_settings: false, show_settings_toggle: None, @@ -370,6 +390,7 @@ impl App { data_frequency: Arc::new(AtomicF32::new(0.0)), single_frequency, dft_num, + periods_per_dft, }; // For testing purposes, populate the Bode plot with a sample low-pass filter response diff --git a/src/bin/main_gui.rs b/src/bin/main_gui.rs index bd81d5c..3c589eb 100644 --- a/src/bin/main_gui.rs +++ b/src/bin/main_gui.rs @@ -33,6 +33,8 @@ fn main() { let data_frequency_clone = app.data_frequency.clone(); + let periods_per_dft = app.periods_per_dft.clone(); + // Execute the runtime in its own thread. std::thread::spawn(move || { rt.block_on(communicate_with_hardware( @@ -45,6 +47,7 @@ fn main() { bode_clone, connected_clone, data_frequency_clone, + periods_per_dft, )); }); diff --git a/src/client.rs b/src/client.rs index ef9577a..3181adc 100644 --- a/src/client.rs +++ b/src/client.rs @@ -5,7 +5,7 @@ use postcard_rpc::{ }; use std::convert::Infallible; use bioz_icd_rs::{ - GetUniqueIdEndpoint, PingEndpoint, SetGreenLedEndpoint, StartMultiImpedance, StartMultiImpedanceEndpoint, StartSingleImpedance, StartSingleImpedanceEndpoint, StopSingleImpedanceEndpoint + GetUniqueIdEndpoint, InitImpedanceResult, PingEndpoint, SetGreenLedEndpoint, StartMultiImpedance, StartMultiImpedanceEndpoint, StartSingleImpedance, StartSingleImpedanceEndpoint, StopSingleImpedanceEndpoint }; use crate::icd::{IcdDftNum, NumberOfPoints}; @@ -66,11 +66,11 @@ impl WorkbookClient { &self, frequency: u32, dft_number: IcdDftNum, - ) -> Result<(), WorkbookError> { - self.client + ) -> Result> { + let response = self.client .send_resp::(&StartSingleImpedance { update_frequency: 60, sinus_frequency: frequency, dft_number}) .await?; - Ok(()) + Ok(response) } pub async fn start_impedancemeter_multi( diff --git a/src/communication.rs b/src/communication.rs index 227091a..5b64a1c 100644 --- a/src/communication.rs +++ b/src/communication.rs @@ -25,6 +25,7 @@ pub async fn communicate_with_hardware( bode_series: Arc>, connected: Arc, data_frequency: Arc, + periods_per_dft: Arc>>, ) { let data_counter = Arc::new(AtomicU32::new(0)); let data_counter_clone = data_counter.clone(); @@ -113,13 +114,22 @@ pub async fn communicate_with_hardware( loop { select! { Some(frequency) = run_impedancemeter_rx.recv() => { - match frequency { + match frequency { StartStopSignal::StartSingle(freq, dft_num) => { - if let Err(e) = workbook_client.start_impedancemeter_single(freq, dft_num).await { - error!("Failed to start impedancemeter: {:?}", e); - } else { - settings.frequency = Some(StartStopSignal::StartSingle(freq, dft_num)); - info!("Impedancemeter started at frequency: {}", freq); + match workbook_client.start_impedancemeter_single(freq, dft_num).await { + Ok(Ok(periods)) => { + info!("Impedance meter started at frequency: {} with periods per DFT: {}", freq, periods); + settings.frequency = Some(StartStopSignal::StartSingle(freq, dft_num)); + *periods_per_dft.lock().unwrap() = Some(periods); + }, + Ok(Err(e)) => { + error!("Failed to init on hardware: {:?}", e); + *periods_per_dft.lock().unwrap() = None; + }, + Err(e) => { + error!("Communication error when starting impedancemeter: {:?}", e); + *periods_per_dft.lock().unwrap() = None; + } } }, StartStopSignal::StartMulti(dft_num, num_points) => {