mirror of
https://github.com/hubaldv/bioz-host-rs.git
synced 2026-03-10 01:20:31 +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 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_dock::{DockArea, DockState, Style};
|
||||
|
||||
@@ -14,6 +14,15 @@ use crate::plot::TimeSeriesPlot;
|
||||
|
||||
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)]
|
||||
enum TabActive {
|
||||
Single,
|
||||
@@ -33,7 +42,8 @@ pub struct App {
|
||||
pub on: Arc<Mutex<bool>>,
|
||||
tab_active: TabActive,
|
||||
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 {
|
||||
@@ -43,6 +53,7 @@ struct TabViewer {
|
||||
phase_series: Arc<Mutex<TimeSeriesPlot>>,
|
||||
on: Arc<Mutex<bool>>,
|
||||
single_frequency: Arc<Mutex<u32>>,
|
||||
dft_num: Arc<Mutex<IcdDftNum>>,
|
||||
show_settings: bool,
|
||||
show_settings_toggle: Option<bool>,
|
||||
}
|
||||
@@ -62,6 +73,21 @@ impl TabViewer {
|
||||
}
|
||||
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 phase_series = Arc::new(Mutex::new(TimeSeriesPlot::new()));
|
||||
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 tab_active = TabActive::Single;
|
||||
|
||||
@@ -165,6 +192,7 @@ impl App {
|
||||
magnitude_series: magnitude_series.clone(),
|
||||
phase_series: phase_series.clone(),
|
||||
single_frequency: single_frequency.clone(),
|
||||
dft_num: dft_num.clone(),
|
||||
on: on.clone(),
|
||||
show_settings: false,
|
||||
show_settings_toggle: None,
|
||||
@@ -184,6 +212,7 @@ impl App {
|
||||
tab_active,
|
||||
data_frequency: Arc::new(AtomicF32::new(0.0)),
|
||||
single_frequency,
|
||||
dft_num,
|
||||
};
|
||||
|
||||
app.update_start_stop();
|
||||
@@ -193,7 +222,7 @@ impl App {
|
||||
pub fn update_start_stop(&self) {
|
||||
match (self.tab_active, *self.on.lock().unwrap()) {
|
||||
(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);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user