Updated logger as separate module.

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-30 10:15:36 +02:00
parent c35287c02f
commit cd80468f54
6 changed files with 98 additions and 97 deletions

View File

@@ -20,7 +20,7 @@ use egui_dock::{DockArea, DockState, Style, TabViewer};
use egui_extras::{TableBuilder, Column};
use crate::state::{AppState, ControlCommand, HardwareConnected, HardwareState, MeasurementDataState, Mode};
use crate::logging::LoggingStates;
use crate::logging::LoggingState;
use crate::signals::LoggingSignal;
use crate::icd::{BioImpedanceLeadMode, IcdDftNum, SweepPoints, ElectrodeOptionsWithMultiplexer};
@@ -52,15 +52,15 @@ pub struct App {
tree: DockState<String>,
tab_viewer: CustomTabs,
// tab_active: TabActive,
log_tx: mpsc::Sender<LoggingSignal>,
pub gui_logging_state: Arc<Mutex<LoggingStates>>,
log_filename: Arc<Mutex<String>>,
log_marker_modal: bool,
log_marker: String,
measurement_data: Arc<MeasurementDataState>,
control_tx: mpsc::Sender<ControlCommand>,
logging_control_tx: mpsc::Sender<LoggingSignal>,
app_state_rx: sync::watch::Receiver<AppState>,
hardware_state_rx: sync::watch::Receiver<HardwareState>
hardware_state_rx: sync::watch::Receiver<HardwareState>,
logging_state_rx: sync::watch::Receiver<LoggingState>,
}
struct CustomTabs {
@@ -616,11 +616,13 @@ impl TabViewer for CustomTabs {
}
impl App {
pub fn new(log_tx: mpsc::Sender<LoggingSignal>,
measurement_data: Arc<MeasurementDataState>,
pub fn new(measurement_data: Arc<MeasurementDataState>,
control_tx: mpsc::Sender<ControlCommand>,
logging_control_tx: mpsc::Sender<LoggingSignal>,
app_state_rx: watch::Receiver<AppState>,
hardware_state_rx: watch::Receiver<HardwareState>) -> Self {
hardware_state_rx: watch::Receiver<HardwareState>,
logging_state_rx: watch::Receiver<LoggingState>
) -> Self {
// Step 1: Initialize shared fields first
// let tab_active = app_state_rx.borrow().tab_active;
@@ -647,15 +649,15 @@ impl App {
tree: DockState::new(vec!["Single".to_string(), "Sweep".to_string(), "Shortcuts".to_string()]),
tab_viewer,
// tab_active,
log_tx,
gui_logging_state: Arc::new(Mutex::new(LoggingStates::Idle)),
log_filename,
log_marker_modal: false,
log_marker: String::new(),
measurement_data,
control_tx,
logging_control_tx,
app_state_rx,
hardware_state_rx,
logging_state_rx,
};
// For testing purposes, populate the Bode plot with a sample low-pass filter response
@@ -745,17 +747,17 @@ impl eframe::App for App {
ui.add_enabled(is_connected, Label::new("Logging:"));
let gui_logging_state = *self.gui_logging_state.lock().unwrap();
let gui_logging_state = *self.logging_state_rx.borrow();
let mut logging_enabled = !matches!(gui_logging_state, LoggingStates::Idle);
let mut logging_enabled = !matches!(gui_logging_state, LoggingState::Idle);
if ui.add_enabled(is_connected, custom_toggle_widget(&mut logging_enabled)).changed() {
let signal = match gui_logging_state {
LoggingStates::Idle => LoggingSignal::StartFileLogging(self.log_filename.lock().unwrap().clone()),
LoggingStates::Starting | LoggingStates::Logging => LoggingSignal::StopFileLogging,
LoggingState::Idle => LoggingSignal::StartFileLogging(self.log_filename.lock().unwrap().clone()),
LoggingState::Starting | LoggingState::Logging => LoggingSignal::StopFileLogging,
};
self.log_tx.try_send(signal).unwrap_or_else(|e| {
self.logging_control_tx.try_send(signal).unwrap_or_else(|e| {
error!("Failed to send logging toggle signal: {:?}", e);
});
};
@@ -796,8 +798,7 @@ impl eframe::App for App {
let enter_pressed = text_edit_response.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter));
if add_clicked || enter_pressed {
info!("Adding marker: {}", self.log_marker);
self.log_tx.try_send(LoggingSignal::AddMarker(self.log_marker.clone())).unwrap_or_else(|e| {
self.logging_control_tx.try_send(LoggingSignal::AddMarker(self.log_marker.clone())).unwrap_or_else(|e| {
error!("Failed to send logging marker signal: {:?}", e);
});
self.log_marker = String::new();
@@ -817,7 +818,7 @@ impl eframe::App for App {
ui.separator();
ui.add_enabled_ui(gui_logging_state == LoggingStates::Idle, |ui| {
ui.add_enabled_ui(gui_logging_state == LoggingState::Idle, |ui| {
ui.label("Log filename:");
TextEdit::singleline(&mut *self.log_filename.lock().unwrap()).desired_width(150.0).id(Id::new("file_name_field")).ui(ui);
});
@@ -894,25 +895,25 @@ impl eframe::App for App {
}
// Toggle marker modal
if ctx.input(|i| i.key_pressed(egui::Key::A)) && *self.gui_logging_state.lock().unwrap() == LoggingStates::Logging {
if ctx.input(|i| i.key_pressed(egui::Key::A)) && *self.logging_state_rx.borrow() == LoggingState::Logging {
self.log_marker_modal = !self.log_marker_modal;
}
// Enable/disable GUI logging
if ctx.input(|i| i.key_pressed(egui::Key::L)) {
let gui_logging_enabled = *self.gui_logging_state.lock().unwrap();
let gui_logging_enabled = *self.logging_state_rx.borrow();
match gui_logging_enabled {
LoggingStates::Starting => {
LoggingState::Starting => {
// If currently starting, do nothing
return;
},
LoggingStates::Logging => {
if let Err(e) = self.log_tx.try_send(LoggingSignal::StopFileLogging) {
LoggingState::Logging => {
if let Err(e) = self.logging_control_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.lock().unwrap().clone())) {
LoggingState::Idle => {
if let Err(e) = self.logging_control_tx.try_send(LoggingSignal::StartFileLogging(self.log_filename.lock().unwrap().clone())) {
error!("Failed to send logging signal: {:?}", e);
}
},