Added log and automatic reconnect.

This commit is contained in:
2025-08-12 11:59:10 +02:00
parent 0b55cdf8b8
commit 961e6cc34a
7 changed files with 193 additions and 84 deletions

View File

@@ -1,16 +1,16 @@
use std::sync::{Arc, Mutex, RwLock};
use std::sync::{Arc, Mutex};
use std::ops::RangeInclusive;
use tokio::{sync::mpsc::{self, Receiver, Sender}, time::Timeout};
use tokio::{sync::mpsc::{Sender}};
use eframe::egui::{self, Button, Checkbox, Color32, DragValue, Key, Layout, Modifiers, RichText, Rounding, };
use eframe::egui::{self, Color32, DragValue, Key, Layout, Modifiers};
use egui_plot::{Corner, Legend, Line, Plot, PlotPoints, Points, PlotBounds};
use crate::plot::TimeSeriesPlot;
pub struct App {
interval_ms: u32,
frequency: u32,
run_impedancemeter_tx: Sender<u32>,
pub magnitude: Arc<Mutex<f32>>,
pub phase: Arc<Mutex<f32>>,
@@ -21,7 +21,7 @@ pub struct App {
impl App {
pub fn new(run_impedancemeter_tx: Sender<u32>) -> Self {
App {
interval_ms: 10, // Default interval
frequency: 2, // Default frequency
run_impedancemeter_tx,
magnitude: Arc::new(Mutex::new(0.0)),
phase: Arc::new(Mutex::new(0.0)),
@@ -39,18 +39,20 @@ impl eframe::App for App {
egui::widgets::global_theme_preference_switch(ui);
ui.separator();
if ui.add(DragValue::new(&mut self.interval_ms).speed(0.1).range(RangeInclusive::new(0, 50)).update_while_editing(false)).changed() {
if ui.add(DragValue::new(&mut self.frequency).speed(0.1).range(RangeInclusive::new(0, 50)).update_while_editing(false)).changed() {
if let Err(e) = self.run_impedancemeter_tx.try_send(0) {
eprintln!("Failed to send stop command: {:?}", e);
}
// Delay
if let Err(e) = self.run_impedancemeter_tx.try_send(self.interval_ms) {
eprintln!("Failed to send interval update: {:?}", e);
if let Err(e) = self.run_impedancemeter_tx.try_send(self.frequency) {
eprintln!("Failed to send frequency update: {:?}", e);
}
};
ui.separator();
if ui.button("Start").clicked() {
if let Err(e) = self.run_impedancemeter_tx.try_send(self.interval_ms) {
if let Err(e) = self.run_impedancemeter_tx.try_send(self.frequency) {
eprintln!("Failed to send start command: {:?}", e);
}
}
@@ -67,7 +69,7 @@ impl eframe::App for App {
egui::CentralPanel::default().show(ctx, |ui| {
let available_height = ui.available_height();
let mut half_height = available_height / 4.0;
let half_height = available_height / 4.0;
let point_pos = vec![[*self.magnitude.lock().unwrap() as f64, *self.phase.lock().unwrap() as f64]];