mirror of
https://github.com/hubaldv/bioz-host-rs.git
synced 2025-12-06 05:11:17 +00:00
Included setting dft number from gui.
This commit is contained in:
35
src/app.rs
35
src/app.rs
@@ -6,7 +6,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
|||||||
use atomic_float::AtomicF32;
|
use atomic_float::AtomicF32;
|
||||||
use tokio::{sync::mpsc::{Sender}};
|
use tokio::{sync::mpsc::{Sender}};
|
||||||
|
|
||||||
use eframe::egui::{self, Button, CollapsingHeader, Color32, DragValue, Key, Label, Layout, Modifiers};
|
use eframe::egui::{self, Button, CollapsingHeader, Color32, ComboBox, DragValue, Key, Label, Layout, Modifiers};
|
||||||
use egui_plot::{Corner, Legend, Line, Plot, PlotPoints, Points, PlotBounds};
|
use egui_plot::{Corner, Legend, Line, Plot, PlotPoints, Points, PlotBounds};
|
||||||
use egui_dock::{DockArea, DockState, Style};
|
use egui_dock::{DockArea, DockState, Style};
|
||||||
|
|
||||||
@@ -14,6 +14,15 @@ use crate::plot::TimeSeriesPlot;
|
|||||||
|
|
||||||
use crate::signals::SingleFrequencySignal;
|
use crate::signals::SingleFrequencySignal;
|
||||||
|
|
||||||
|
use crate::icd::IcdDftNum;
|
||||||
|
|
||||||
|
const DFTNUM_VARIANTS: [IcdDftNum; 13] = [
|
||||||
|
IcdDftNum::Num4, IcdDftNum::Num8, IcdDftNum::Num16, IcdDftNum::Num32,
|
||||||
|
IcdDftNum::Num64, IcdDftNum::Num128, IcdDftNum::Num256, IcdDftNum::Num512,
|
||||||
|
IcdDftNum::Num1024, IcdDftNum::Num2048, IcdDftNum::Num4096,
|
||||||
|
IcdDftNum::Num8192, IcdDftNum::Num16384,
|
||||||
|
];
|
||||||
|
|
||||||
#[derive(Clone, Copy,Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy,Debug, PartialEq, Eq)]
|
||||||
enum TabActive {
|
enum TabActive {
|
||||||
Single,
|
Single,
|
||||||
@@ -33,7 +42,8 @@ pub struct App {
|
|||||||
pub on: Arc<Mutex<bool>>,
|
pub on: Arc<Mutex<bool>>,
|
||||||
tab_active: TabActive,
|
tab_active: TabActive,
|
||||||
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>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TabViewer {
|
struct TabViewer {
|
||||||
@@ -43,6 +53,7 @@ struct TabViewer {
|
|||||||
phase_series: Arc<Mutex<TimeSeriesPlot>>,
|
phase_series: Arc<Mutex<TimeSeriesPlot>>,
|
||||||
on: Arc<Mutex<bool>>,
|
on: Arc<Mutex<bool>>,
|
||||||
single_frequency: Arc<Mutex<u32>>,
|
single_frequency: Arc<Mutex<u32>>,
|
||||||
|
dft_num: Arc<Mutex<IcdDftNum>>,
|
||||||
show_settings: bool,
|
show_settings: bool,
|
||||||
show_settings_toggle: Option<bool>,
|
show_settings_toggle: Option<bool>,
|
||||||
}
|
}
|
||||||
@@ -62,6 +73,21 @@ impl TabViewer {
|
|||||||
}
|
}
|
||||||
ui.label("Hz");
|
ui.label("Hz");
|
||||||
});
|
});
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.label("ADC samples per DFT:");
|
||||||
|
let mut dft_num = self.dft_num.lock().unwrap();
|
||||||
|
let mut index = DFTNUM_VARIANTS.iter().position(|&x| x == *dft_num).unwrap_or(0);
|
||||||
|
ComboBox::from_id_salt("Dftnum")
|
||||||
|
.width(75.0)
|
||||||
|
.show_index(ui, &mut index, DFTNUM_VARIANTS.len(), |i| {
|
||||||
|
format!("{}", 1 << (2 + i)) // 2^2 = 4, 2^3 = 8, ..., 2^14 = 16384
|
||||||
|
});
|
||||||
|
let new_value = DFTNUM_VARIANTS[index];
|
||||||
|
if *dft_num != new_value {
|
||||||
|
*dft_num = new_value;
|
||||||
|
info!("DFTNUM setting changed!");
|
||||||
|
};
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -155,6 +181,7 @@ impl App {
|
|||||||
let magnitude_series = Arc::new(Mutex::new(TimeSeriesPlot::new()));
|
let magnitude_series = Arc::new(Mutex::new(TimeSeriesPlot::new()));
|
||||||
let phase_series = Arc::new(Mutex::new(TimeSeriesPlot::new()));
|
let phase_series = Arc::new(Mutex::new(TimeSeriesPlot::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 on = Arc::new(Mutex::new(true));
|
let on = Arc::new(Mutex::new(true));
|
||||||
let tab_active = TabActive::Single;
|
let tab_active = TabActive::Single;
|
||||||
|
|
||||||
@@ -165,6 +192,7 @@ impl App {
|
|||||||
magnitude_series: magnitude_series.clone(),
|
magnitude_series: magnitude_series.clone(),
|
||||||
phase_series: phase_series.clone(),
|
phase_series: phase_series.clone(),
|
||||||
single_frequency: single_frequency.clone(),
|
single_frequency: single_frequency.clone(),
|
||||||
|
dft_num: dft_num.clone(),
|
||||||
on: on.clone(),
|
on: on.clone(),
|
||||||
show_settings: false,
|
show_settings: false,
|
||||||
show_settings_toggle: None,
|
show_settings_toggle: None,
|
||||||
@@ -184,6 +212,7 @@ impl App {
|
|||||||
tab_active,
|
tab_active,
|
||||||
data_frequency: Arc::new(AtomicF32::new(0.0)),
|
data_frequency: Arc::new(AtomicF32::new(0.0)),
|
||||||
single_frequency,
|
single_frequency,
|
||||||
|
dft_num,
|
||||||
};
|
};
|
||||||
|
|
||||||
app.update_start_stop();
|
app.update_start_stop();
|
||||||
@@ -193,7 +222,7 @@ impl App {
|
|||||||
pub fn update_start_stop(&self) {
|
pub fn update_start_stop(&self) {
|
||||||
match (self.tab_active, *self.on.lock().unwrap()) {
|
match (self.tab_active, *self.on.lock().unwrap()) {
|
||||||
(TabActive::Single, true) => {
|
(TabActive::Single, true) => {
|
||||||
if let Err(e) = self.run_impedancemeter_tx.try_send(SingleFrequencySignal::Start(*self.single_frequency.lock().unwrap())) {
|
if let Err(e) = self.run_impedancemeter_tx.try_send(SingleFrequencySignal::Start(*self.single_frequency.lock().unwrap(), *self.dft_num.lock().unwrap())) {
|
||||||
eprintln!("Failed to send start command: {:?}", e);
|
eprintln!("Failed to send start command: {:?}", e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -78,8 +78,8 @@ async fn main() {
|
|||||||
.subscribe_multi::<icd::ImpedanceOutputTopic>(8)
|
.subscribe_multi::<icd::ImpedanceOutputTopic>(8)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
client.start_impedancemeter(freq).await.unwrap();
|
client.start_impedancemeter(freq, bioz_icd_rs::IcdDftNum::Num2048).await.unwrap();
|
||||||
println!("Started!");
|
println!("Started with dft_num 2048!");
|
||||||
let dur = Duration::from_millis(dur.into());
|
let dur = Duration::from_millis(dur.into());
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
@@ -97,8 +97,8 @@ async fn main() {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match client.start_impedancemeter(freq).await {
|
match client.start_impedancemeter(freq, bioz_icd_rs::IcdDftNum::Num2048).await {
|
||||||
Ok(_) => println!("Started!"),
|
Ok(_) => println!("Started with dft_num 2048!"),
|
||||||
Err(e) => println!("Error starting impedancemeter: {:?}", e),
|
Err(e) => println!("Error starting impedancemeter: {:?}", e),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ use bioz_icd_rs::{
|
|||||||
StopImpedanceEndpoint,
|
StopImpedanceEndpoint,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::icd::IcdDftNum;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct WorkbookClient {
|
pub struct WorkbookClient {
|
||||||
pub client: HostClient<WireError>,
|
pub client: HostClient<WireError>,
|
||||||
@@ -64,9 +66,10 @@ impl WorkbookClient {
|
|||||||
pub async fn start_impedancemeter(
|
pub async fn start_impedancemeter(
|
||||||
&self,
|
&self,
|
||||||
frequency: u32,
|
frequency: u32,
|
||||||
|
dft_number: IcdDftNum,
|
||||||
) -> Result<(), WorkbookError<Infallible>> {
|
) -> Result<(), WorkbookError<Infallible>> {
|
||||||
self.client
|
self.client
|
||||||
.send_resp::<StartImpedanceEndpoint>(&StartImpedance { update_frequency: 60, sinus_frequency: frequency })
|
.send_resp::<StartImpedanceEndpoint>(&StartImpedance { update_frequency: 60, sinus_frequency: frequency, dft_number})
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,11 +90,11 @@ pub async fn communicate_with_hardware(
|
|||||||
select! {
|
select! {
|
||||||
Some(frequency) = run_impedancemeter_rx.recv() => {
|
Some(frequency) = run_impedancemeter_rx.recv() => {
|
||||||
match frequency {
|
match frequency {
|
||||||
SingleFrequencySignal::Start(freq) => {
|
SingleFrequencySignal::Start(freq, dft_num) => {
|
||||||
if let Err(e) = workbook_client.start_impedancemeter(freq).await {
|
if let Err(e) = workbook_client.start_impedancemeter(freq, dft_num).await {
|
||||||
error!("Failed to start impedancemeter: {:?}", e);
|
error!("Failed to start impedancemeter: {:?}", e);
|
||||||
} else {
|
} else {
|
||||||
settings.frequency = Some(SingleFrequencySignal::Start(freq));
|
settings.frequency = Some(SingleFrequencySignal::Start(freq, dft_num));
|
||||||
info!("Impedancemeter started at frequency: {}", freq);
|
info!("Impedancemeter started at frequency: {}", freq);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
use crate::icd::IcdDftNum;
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub enum SingleFrequencySignal {
|
pub enum SingleFrequencySignal {
|
||||||
Start(u32),
|
Start(u32, IcdDftNum), // frequency in Hz, DFT number
|
||||||
Stop,
|
Stop,
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user