mirror of
https://github.com/hubaldv/bioz-host-rs.git
synced 2026-03-10 01:20:31 +00:00
Updated logging to be able to select output folder.
This commit is contained in:
70
src/app.rs
70
src/app.rs
@@ -12,11 +12,12 @@ use chrono::Local;
|
||||
use atomic_float::AtomicF32;
|
||||
use tokio::{sync::mpsc::{Sender}};
|
||||
|
||||
use eframe::egui::{self, Button, CollapsingHeader, Color32, ComboBox, DragValue, Id, Key, Label, Layout, Modifiers, TextEdit, Widget};
|
||||
use eframe::egui::{self, Button, CollapsingHeader, Color32, ComboBox, DragValue, Id, Key, Label, Layout, Modifiers, RichText, TextEdit, Widget};
|
||||
use egui_plot::{Corner, GridInput, GridMark, Legend, Line, Plot, PlotPoint, Points};
|
||||
use egui_dock::{DockArea, DockState, Style};
|
||||
use egui_extras::{TableBuilder, Column};
|
||||
|
||||
use crate::logging::LoggingStates;
|
||||
use crate::plot::{TimeSeriesPlot, BodePlot};
|
||||
|
||||
use crate::signals::{LoggingSignal, StartStopSignal};
|
||||
@@ -67,7 +68,7 @@ pub struct App {
|
||||
pub measurement_points: Arc<Mutex<MeasurementPointSet>>,
|
||||
pub periods_per_dft: Arc<Mutex<Option<f32>>>,
|
||||
pub periods_per_dft_sweep: Arc<Mutex<(Vec<u32>, Option<Vec<f32>>)>>,
|
||||
pub gui_logging_enabled: Arc<AtomicBool>,
|
||||
pub gui_logging_state: Arc<Mutex<LoggingStates>>,
|
||||
log_filename: String,
|
||||
}
|
||||
|
||||
@@ -540,7 +541,7 @@ impl App {
|
||||
measurement_points,
|
||||
periods_per_dft,
|
||||
periods_per_dft_sweep,
|
||||
gui_logging_enabled: Arc::new(AtomicBool::new(false)),
|
||||
gui_logging_state: Arc::new(Mutex::new(LoggingStates::Idle)),
|
||||
log_filename: format!("log_{}.csv", Local::now().format("%Y%m%d"))
|
||||
};
|
||||
|
||||
@@ -619,23 +620,31 @@ impl eframe::App for App {
|
||||
|
||||
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);
|
||||
if gui_logging_enabled {
|
||||
if let Err(e) = self.log_tx.try_send(LoggingSignal::StartFileLogging(self.log_filename.clone())) {
|
||||
error!("Failed to send logging signal: {:?}", e);
|
||||
}
|
||||
} else {
|
||||
if let Err(e) = self.log_tx.try_send(LoggingSignal::StopFileLogging) {
|
||||
error!("Failed to send logging signal: {:?}", e);
|
||||
}
|
||||
}
|
||||
let gui_logging_state = *self.gui_logging_state.lock().unwrap();
|
||||
|
||||
let (color, signal) = match gui_logging_state {
|
||||
LoggingStates::Idle => (Color32::DARK_RED, LoggingSignal::StartFileLogging(self.log_filename.clone())),
|
||||
LoggingStates::Starting => (Color32::from_rgb(204, 153, 0), LoggingSignal::StopFileLogging),
|
||||
LoggingStates::Logging => (Color32::DARK_GREEN, LoggingSignal::StopFileLogging),
|
||||
};
|
||||
|
||||
let button = Button::new(
|
||||
RichText::new("Logging")
|
||||
.strong()
|
||||
.color(Color32::WHITE)
|
||||
).fill(color)
|
||||
.corner_radius(5.0)
|
||||
.frame(true);
|
||||
|
||||
if ui.add(button).clicked() {
|
||||
self.log_tx.try_send(signal).unwrap_or_else(|e| {
|
||||
error!("Failed to send logging toggle signal: {:?}", e);
|
||||
});
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
ui.add_enabled_ui(!gui_logging_enabled, |ui| {
|
||||
ui.add_enabled_ui(gui_logging_state == LoggingStates::Idle, |ui| {
|
||||
ui.label("Log filename:");
|
||||
TextEdit::singleline(&mut self.log_filename).desired_width(125.0).id(Id::new("file_name_field")).ui(ui);
|
||||
});
|
||||
@@ -644,7 +653,7 @@ impl eframe::App for App {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
ui.scope(|ui| {
|
||||
let is_connected = self.connected.load(Ordering::Relaxed);
|
||||
let color = if is_connected { Color32::GREEN } else { Color32::RED };
|
||||
let color = if is_connected { Color32::DARK_GREEN } else { Color32::DARK_RED };
|
||||
let tooltip = if is_connected { "Connected" } else { "Disconnected" };
|
||||
|
||||
// Allocate a fixed-size rectangle for the LED
|
||||
@@ -739,17 +748,22 @@ impl eframe::App for App {
|
||||
|
||||
// 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);
|
||||
if gui_logging_enabled {
|
||||
if let Err(e) = self.log_tx.try_send(LoggingSignal::StartFileLogging(self.log_filename.clone())) {
|
||||
error!("Failed to send logging signal: {:?}", e);
|
||||
}
|
||||
} else {
|
||||
if let Err(e) = self.log_tx.try_send(LoggingSignal::StopFileLogging) {
|
||||
error!("Failed to send logging signal: {:?}", e);
|
||||
}
|
||||
let gui_logging_enabled = *self.gui_logging_state.lock().unwrap();
|
||||
match gui_logging_enabled {
|
||||
LoggingStates::Starting => {
|
||||
// If currently starting, do nothing
|
||||
return;
|
||||
},
|
||||
LoggingStates::Logging => {
|
||||
if let Err(e) = self.log_tx.try_send(LoggingSignal::StopFileLogging) {
|
||||
error!("Failed to send logging signal: {:?}", e);
|
||||
}
|
||||
},
|
||||
LoggingStates::Idle => {
|
||||
if let Err(e) = self.log_tx.try_send(LoggingSignal::StartFileLogging(self.log_filename.clone())) {
|
||||
error!("Failed to send logging signal: {:?}", e);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user