mirror of
https://github.com/hubaldv/bioz-host-rs.git
synced 2026-03-10 01:20:31 +00:00
Implement basic logging channels.
This commit is contained in:
49
src/app.rs
49
src/app.rs
@@ -56,6 +56,7 @@ pub struct App {
|
||||
pub measurement_points: Arc<Mutex<MeasurementPointSet>>,
|
||||
pub periods_per_dft: Arc<Mutex<Option<f32>>>,
|
||||
pub periods_per_dft_multi: Arc<Mutex<(Vec<f32>, Option<Vec<f32>>)>>,
|
||||
pub gui_logging_enabled: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
struct TabViewer {
|
||||
@@ -327,8 +328,9 @@ impl TabViewer {
|
||||
fn shortcuts(&mut self, ui: &mut egui::Ui) {
|
||||
ui.heading("Shortcuts");
|
||||
ui.label("Space: Start/Stop measurement");
|
||||
ui.label("C: Clear plots");
|
||||
ui.label("R: Reset view/plots");
|
||||
ui.label("S: Toggle settings");
|
||||
ui.label("L: Toggle logging");
|
||||
ui.label("CMD-W: Close window");
|
||||
}
|
||||
}
|
||||
@@ -462,25 +464,26 @@ impl App {
|
||||
measurement_points,
|
||||
periods_per_dft,
|
||||
periods_per_dft_multi,
|
||||
gui_logging_enabled: Arc::new(AtomicBool::new(false)),
|
||||
};
|
||||
|
||||
// For testing purposes, populate the Bode plot with a sample low-pass filter response
|
||||
let fc = 1000.0; // cutoff frequency in Hz
|
||||
// let fc = 1000.0; // cutoff frequency in Hz
|
||||
|
||||
let freqs = MeasurementPointSet::Eighteen.values().to_vec();
|
||||
let magnitudes = freqs.iter()
|
||||
.map(|&f| {
|
||||
1.0 / (1.0 + (f / fc).powi(2)).sqrt()
|
||||
})
|
||||
.collect::<Vec<f32>>();
|
||||
let phases = freqs.iter()
|
||||
.map(|&f| {
|
||||
-(f / fc).atan() * 180.0 / PI
|
||||
})
|
||||
.collect::<Vec<f32>>();
|
||||
// let freqs = MeasurementPointSet::Eighteen.values().to_vec();
|
||||
// let magnitudes = freqs.iter()
|
||||
// .map(|&f| {
|
||||
// 1.0 / (1.0 + (f / fc).powi(2)).sqrt()
|
||||
// })
|
||||
// .collect::<Vec<f32>>();
|
||||
// let phases = freqs.iter()
|
||||
// .map(|&f| {
|
||||
// -(f / fc).atan() * 180.0 / PI
|
||||
// })
|
||||
// .collect::<Vec<f32>>();
|
||||
|
||||
app.bode_plot.lock().unwrap().update_magnitudes(MeasurementPointSet::Eighteen, magnitudes);
|
||||
app.bode_plot.lock().unwrap().update_phases(MeasurementPointSet::Eighteen, phases);
|
||||
// app.bode_plot.lock().unwrap().update_magnitudes(MeasurementPointSet::Eighteen, magnitudes);
|
||||
// app.bode_plot.lock().unwrap().update_phases(MeasurementPointSet::Eighteen, phases);
|
||||
|
||||
app.update_start_stop();
|
||||
app
|
||||
@@ -537,6 +540,13 @@ impl eframe::App for App {
|
||||
self.reset_view();
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
let mut gui_logging_enabled = self.gui_logging_enabled.load(Ordering::Relaxed);
|
||||
if ui.add(egui::Checkbox::new(&mut gui_logging_enabled, "Logging")).changed() {
|
||||
self.gui_logging_enabled.store(gui_logging_enabled, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
// Spacer to push the LED to the right
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ui.scope(|ui| {
|
||||
@@ -625,10 +635,17 @@ impl eframe::App for App {
|
||||
}
|
||||
|
||||
// Reset view
|
||||
if ctx.input(|i| i.key_pressed(Key::C)) {
|
||||
if ctx.input(|i| i.key_pressed(Key::R)) {
|
||||
self.reset_view();
|
||||
}
|
||||
|
||||
// Enable/disable GUI logging
|
||||
if ctx.input(|i| i.key_pressed(egui::Key::L)) {
|
||||
let mut gui_logging_enabled = self.gui_logging_enabled.load(Ordering::Relaxed);
|
||||
gui_logging_enabled = !gui_logging_enabled;
|
||||
self.gui_logging_enabled.store(gui_logging_enabled, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
// Toggle setttings view
|
||||
if ctx.input(|i| i.key_pressed(egui::Key::S)) {
|
||||
self.tab_viewer.show_settings = !self.tab_viewer.show_settings;
|
||||
|
||||
Reference in New Issue
Block a user