From 40e3c70ac57ff5f72b0d957fcc69bc7dae790f87 Mon Sep 17 00:00:00 2001 From: hacknus Date: Tue, 8 Oct 2024 01:04:10 +0200 Subject: [PATCH] sync the frame updates to data packets received (and parsed) --- src/gui.rs | 11 +---------- src/main.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/gui.rs b/src/gui.rs index ba4ac8a..584ca7f 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -6,9 +6,7 @@ use std::sync::{Arc, RwLock}; use std::time::Duration; use eframe::egui::panel::Side; -use eframe::egui::{ - Align2, FontFamily, FontId, KeyboardShortcut, Pos2, Sense, Vec2, Visuals, -}; +use eframe::egui::{Align2, FontFamily, FontId, KeyboardShortcut, Pos2, Sense, Vec2, Visuals}; use eframe::{egui, Storage}; use egui::ThemePreference; use egui_plot::{log_grid_spacer, GridMark, Legend, Line, Plot, PlotPoint, PlotPoints}; @@ -23,8 +21,6 @@ use crate::toggle::toggle; use crate::FileOptions; use crate::{APP_INFO, PREFS_KEY}; -const MAX_FPS: f64 = 60.0; - const DEFAULT_FONT_ID: FontId = FontId::new(14.0, FontFamily::Monospace); pub const RIGHT_PANEL_WIDTH: f32 = 350.0; const BAUD_RATES: &[u32] = &[ @@ -471,8 +467,6 @@ impl MyApp { self.command = self.history[self.index].clone(); } } - - ctx.request_repaint() }); ui.add_space(left_border); }); @@ -795,7 +789,6 @@ impl MyApp { if ui.add(ThemeSwitch::new(&mut self.gui_conf.theme_preference)).changed() { ui.ctx().set_theme(self.gui_conf.theme_preference); }; - ui.add_space(25.0); self.gui_conf.dark_mode = ui.visuals() == &Visuals::dark(); ui.horizontal( |ui| { @@ -932,8 +925,6 @@ impl eframe::App for MyApp { eprintln!("Image saved to {path:?}."); } } - - std::thread::sleep(Duration::from_millis((1000.0 / MAX_FPS) as u64)); } fn save(&mut self, _storage: &mut dyn Storage) { diff --git a/src/main.rs b/src/main.rs index ca47a20..d5c953c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,6 +46,7 @@ fn split(payload: &str) -> Vec { } fn main_thread( + sync_tx: Sender, data_lock: Arc>, print_lock: Arc>>, raw_data_rx: Receiver, @@ -70,6 +71,7 @@ fn main_thread( if let Ok(packet) = raw_data_rx.recv_timeout(Duration::from_millis(1)) { if !packet.payload.is_empty() { + sync_tx.send(true).expect("unable to send sync tx"); data.raw_traffic.push(packet.clone()); let split_data = split(&packet.payload); if data.dataset.is_empty() || failed_format_counter > 10 { @@ -150,6 +152,7 @@ fn main() { let (clear_tx, clear_rx): (Sender, Receiver) = mpsc::channel(); let (names_tx, names_rx): (Sender>, Receiver>) = mpsc::channel(); let (raw_data_tx, raw_data_rx): (Sender, Receiver) = mpsc::channel(); + let (sync_tx, sync_rx): (Sender, Receiver) = mpsc::channel(); let serial_device_lock = device_lock.clone(); let serial_devices_lock = devices_lock.clone(); @@ -174,6 +177,7 @@ fn main() { println!("starting main thread.."); let _main_thread_handler = thread::spawn(|| { main_thread( + sync_tx, main_data_lock, main_print_lock, raw_data_rx, @@ -208,6 +212,15 @@ fn main() { egui_phosphor::add_to_fonts(&mut fonts, egui_phosphor::Variant::Regular); _cc.egui_ctx.set_fonts(fonts); _cc.egui_ctx.set_visuals(Visuals::dark()); + + let repaint_signal = _cc.egui_ctx.clone(); + thread::spawn(move || loop { + if let Ok(_) = sync_rx.recv() { + println!("requested repaint!"); + repaint_signal.request_repaint(); + } + }); + Ok(Box::new(MyApp::new( gui_print_lock, gui_data_lock,