mirror of
https://github.com/hubaldv/bioz-host-rs.git
synced 2025-12-06 05:11:17 +00:00
Show periods per DFT in GUI.
This commit is contained in:
21
src/app.rs
21
src/app.rs
@@ -47,6 +47,7 @@ pub struct App {
|
|||||||
pub data_frequency: Arc<AtomicF32>,
|
pub data_frequency: Arc<AtomicF32>,
|
||||||
pub single_frequency: Arc<Mutex<u32>>,
|
pub single_frequency: Arc<Mutex<u32>>,
|
||||||
pub dft_num: Arc<Mutex<IcdDftNum>>,
|
pub dft_num: Arc<Mutex<IcdDftNum>>,
|
||||||
|
pub periods_per_dft: Arc<Mutex<Option<f32>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TabViewer {
|
struct TabViewer {
|
||||||
@@ -58,6 +59,7 @@ struct TabViewer {
|
|||||||
on: Arc<Mutex<bool>>,
|
on: Arc<Mutex<bool>>,
|
||||||
single_frequency: Arc<Mutex<u32>>,
|
single_frequency: Arc<Mutex<u32>>,
|
||||||
dft_num: Arc<Mutex<IcdDftNum>>,
|
dft_num: Arc<Mutex<IcdDftNum>>,
|
||||||
|
periods_per_dft: Arc<Mutex<Option<f32>>>,
|
||||||
show_settings: bool,
|
show_settings: bool,
|
||||||
show_settings_toggle: Option<bool>,
|
show_settings_toggle: Option<bool>,
|
||||||
}
|
}
|
||||||
@@ -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 bode_plot = Arc::new(Mutex::new(BodePlot::new()));
|
||||||
let single_frequency = Arc::new(Mutex::new(50000));
|
let single_frequency = Arc::new(Mutex::new(50000));
|
||||||
let dft_num = Arc::new(Mutex::new(IcdDftNum::Num2048));
|
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 on = Arc::new(Mutex::new(true));
|
||||||
let tab_active = TabActive::Single;
|
let tab_active = TabActive::Single;
|
||||||
|
|
||||||
@@ -349,6 +368,7 @@ impl App {
|
|||||||
bode_plot: bode_plot.clone(),
|
bode_plot: bode_plot.clone(),
|
||||||
single_frequency: single_frequency.clone(),
|
single_frequency: single_frequency.clone(),
|
||||||
dft_num: dft_num.clone(),
|
dft_num: dft_num.clone(),
|
||||||
|
periods_per_dft: periods_per_dft.clone(),
|
||||||
on: on.clone(),
|
on: on.clone(),
|
||||||
show_settings: false,
|
show_settings: false,
|
||||||
show_settings_toggle: None,
|
show_settings_toggle: None,
|
||||||
@@ -370,6 +390,7 @@ impl App {
|
|||||||
data_frequency: Arc::new(AtomicF32::new(0.0)),
|
data_frequency: Arc::new(AtomicF32::new(0.0)),
|
||||||
single_frequency,
|
single_frequency,
|
||||||
dft_num,
|
dft_num,
|
||||||
|
periods_per_dft,
|
||||||
};
|
};
|
||||||
|
|
||||||
// For testing purposes, populate the Bode plot with a sample low-pass filter response
|
// For testing purposes, populate the Bode plot with a sample low-pass filter response
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ fn main() {
|
|||||||
|
|
||||||
let data_frequency_clone = app.data_frequency.clone();
|
let data_frequency_clone = app.data_frequency.clone();
|
||||||
|
|
||||||
|
let periods_per_dft = app.periods_per_dft.clone();
|
||||||
|
|
||||||
// Execute the runtime in its own thread.
|
// Execute the runtime in its own thread.
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
rt.block_on(communicate_with_hardware(
|
rt.block_on(communicate_with_hardware(
|
||||||
@@ -45,6 +47,7 @@ fn main() {
|
|||||||
bode_clone,
|
bode_clone,
|
||||||
connected_clone,
|
connected_clone,
|
||||||
data_frequency_clone,
|
data_frequency_clone,
|
||||||
|
periods_per_dft,
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use postcard_rpc::{
|
|||||||
};
|
};
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use bioz_icd_rs::{
|
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};
|
use crate::icd::{IcdDftNum, NumberOfPoints};
|
||||||
@@ -66,11 +66,11 @@ impl WorkbookClient {
|
|||||||
&self,
|
&self,
|
||||||
frequency: u32,
|
frequency: u32,
|
||||||
dft_number: IcdDftNum,
|
dft_number: IcdDftNum,
|
||||||
) -> Result<(), WorkbookError<Infallible>> {
|
) -> Result<InitImpedanceResult, WorkbookError<Infallible>> {
|
||||||
self.client
|
let response = self.client
|
||||||
.send_resp::<StartSingleImpedanceEndpoint>(&StartSingleImpedance { update_frequency: 60, sinus_frequency: frequency, dft_number})
|
.send_resp::<StartSingleImpedanceEndpoint>(&StartSingleImpedance { update_frequency: 60, sinus_frequency: frequency, dft_number})
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start_impedancemeter_multi(
|
pub async fn start_impedancemeter_multi(
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ pub async fn communicate_with_hardware(
|
|||||||
bode_series: Arc<Mutex<BodePlot>>,
|
bode_series: Arc<Mutex<BodePlot>>,
|
||||||
connected: Arc<AtomicBool>,
|
connected: Arc<AtomicBool>,
|
||||||
data_frequency: Arc<AtomicF32>,
|
data_frequency: Arc<AtomicF32>,
|
||||||
|
periods_per_dft: Arc<Mutex<Option<f32>>>,
|
||||||
) {
|
) {
|
||||||
let data_counter = Arc::new(AtomicU32::new(0));
|
let data_counter = Arc::new(AtomicU32::new(0));
|
||||||
let data_counter_clone = data_counter.clone();
|
let data_counter_clone = data_counter.clone();
|
||||||
@@ -115,11 +116,20 @@ pub async fn communicate_with_hardware(
|
|||||||
Some(frequency) = run_impedancemeter_rx.recv() => {
|
Some(frequency) = run_impedancemeter_rx.recv() => {
|
||||||
match frequency {
|
match frequency {
|
||||||
StartStopSignal::StartSingle(freq, dft_num) => {
|
StartStopSignal::StartSingle(freq, dft_num) => {
|
||||||
if let Err(e) = workbook_client.start_impedancemeter_single(freq, dft_num).await {
|
match workbook_client.start_impedancemeter_single(freq, dft_num).await {
|
||||||
error!("Failed to start impedancemeter: {:?}", e);
|
Ok(Ok(periods)) => {
|
||||||
} else {
|
info!("Impedance meter started at frequency: {} with periods per DFT: {}", freq, periods);
|
||||||
settings.frequency = Some(StartStopSignal::StartSingle(freq, dft_num));
|
settings.frequency = Some(StartStopSignal::StartSingle(freq, dft_num));
|
||||||
info!("Impedancemeter started at frequency: {}", freq);
|
*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) => {
|
StartStopSignal::StartMulti(dft_num, num_points) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user