Implement basic logging channels.

This commit is contained in:
2025-10-09 21:51:35 +02:00
parent 73f1c9633c
commit cb7bc2f025
5 changed files with 136 additions and 40 deletions

View File

@@ -2,7 +2,7 @@ use simple_logger::SimpleLogger;
use log::info;
use tokio::runtime::Runtime;
use bioz_host_rs::app::App;
use bioz_host_rs::{app::App, signals::LoggingSignal};
use bioz_host_rs::communication::communicate_with_hardware;
@@ -10,7 +10,8 @@ use tokio::sync::mpsc::{self};
use bioz_host_rs::signals::StartStopSignal;
fn main() {
#[tokio::main]
async fn main() {
SimpleLogger::new().init().expect("Failed to initialize logger");
log::set_max_level(log::LevelFilter::Info);
info!("Starting Bioz Impedance Visualizer...");
@@ -20,9 +21,13 @@ fn main() {
// Enter the runtime so that `tokio::spawn` is available immediately.
// let _enter = rt.enter();
// Channel to communicate with the communication task.
let (run_impedancemeter_tx, run_impedancemeter_rx) = mpsc::channel::<StartStopSignal>(2);
let run_impedancemeter_tx_clone = run_impedancemeter_tx.clone();
// Logging
let (log_tx, mut log_rx) = mpsc::channel::<LoggingSignal>(10);
let app = App::new(run_impedancemeter_tx);
let magnitude_clone = app.magnitude.clone();
let phase_clone = app.phase.clone();
@@ -36,6 +41,30 @@ fn main() {
let periods_per_dft = app.periods_per_dft.clone();
let periods_per_dft_multi = app.periods_per_dft_multi.clone();
let gui_logging_enabled = app.gui_logging_enabled.clone();
// Log thread
tokio::spawn(async move {
loop {
match log_rx.recv().await {
Some(signal) => {
match signal {
LoggingSignal::SingleImpedance(magnitude, phase) => {
info!("Single Impedance - Magnitude: {:.3}, Phase: {:.3}", magnitude, phase);
}
LoggingSignal::MultiImpedance(magnitudes, phases) => {
info!("Multi Impedance - Magnitudes: {:?}, Phases: {:?}", magnitudes, phases);
}
}
}
None => {
// Channel closed
break;
}
}
}
});
// Execute the runtime in its own thread.
std::thread::spawn(move || {
rt.block_on(communicate_with_hardware(
@@ -50,6 +79,8 @@ fn main() {
data_frequency_clone,
periods_per_dft,
periods_per_dft_multi,
gui_logging_enabled,
log_tx,
));
});