Skip to content

Commit 67bf086

Browse files
authored
Merge pull request #104 from hacknus/sync_frame_update_to_data
sync the frame updates to data packets received (and parsed)
2 parents 25e5563 + 40e3c70 commit 67bf086

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/gui.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use std::sync::{Arc, RwLock};
66
use std::time::Duration;
77

88
use eframe::egui::panel::Side;
9-
use eframe::egui::{
10-
Align2, FontFamily, FontId, KeyboardShortcut, Pos2, Sense, Vec2, Visuals,
11-
};
9+
use eframe::egui::{Align2, FontFamily, FontId, KeyboardShortcut, Pos2, Sense, Vec2, Visuals};
1210
use eframe::{egui, Storage};
1311
use egui::ThemePreference;
1412
use egui_plot::{log_grid_spacer, GridMark, Legend, Line, Plot, PlotPoint, PlotPoints};
@@ -23,8 +21,6 @@ use crate::toggle::toggle;
2321
use crate::FileOptions;
2422
use crate::{APP_INFO, PREFS_KEY};
2523

26-
const MAX_FPS: f64 = 60.0;
27-
2824
const DEFAULT_FONT_ID: FontId = FontId::new(14.0, FontFamily::Monospace);
2925
pub const RIGHT_PANEL_WIDTH: f32 = 350.0;
3026
const BAUD_RATES: &[u32] = &[
@@ -471,8 +467,6 @@ impl MyApp {
471467
self.command = self.history[self.index].clone();
472468
}
473469
}
474-
475-
ctx.request_repaint()
476470
});
477471
ui.add_space(left_border);
478472
});
@@ -795,7 +789,6 @@ impl MyApp {
795789
if ui.add(ThemeSwitch::new(&mut self.gui_conf.theme_preference)).changed() {
796790
ui.ctx().set_theme(self.gui_conf.theme_preference);
797791
};
798-
799792
ui.add_space(25.0);
800793
self.gui_conf.dark_mode = ui.visuals() == &Visuals::dark();
801794
ui.horizontal( |ui| {
@@ -932,8 +925,6 @@ impl eframe::App for MyApp {
932925
eprintln!("Image saved to {path:?}.");
933926
}
934927
}
935-
936-
std::thread::sleep(Duration::from_millis((1000.0 / MAX_FPS) as u64));
937928
}
938929

939930
fn save(&mut self, _storage: &mut dyn Storage) {

src/main.rs

+13
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ fn split(payload: &str) -> Vec<f32> {
4646
}
4747

4848
fn main_thread(
49+
sync_tx: Sender<bool>,
4950
data_lock: Arc<RwLock<DataContainer>>,
5051
print_lock: Arc<RwLock<Vec<Print>>>,
5152
raw_data_rx: Receiver<Packet>,
@@ -70,6 +71,7 @@ fn main_thread(
7071

7172
if let Ok(packet) = raw_data_rx.recv_timeout(Duration::from_millis(1)) {
7273
if !packet.payload.is_empty() {
74+
sync_tx.send(true).expect("unable to send sync tx");
7375
data.raw_traffic.push(packet.clone());
7476
let split_data = split(&packet.payload);
7577
if data.dataset.is_empty() || failed_format_counter > 10 {
@@ -150,6 +152,7 @@ fn main() {
150152
let (clear_tx, clear_rx): (Sender<bool>, Receiver<bool>) = mpsc::channel();
151153
let (names_tx, names_rx): (Sender<Vec<String>>, Receiver<Vec<String>>) = mpsc::channel();
152154
let (raw_data_tx, raw_data_rx): (Sender<Packet>, Receiver<Packet>) = mpsc::channel();
155+
let (sync_tx, sync_rx): (Sender<bool>, Receiver<bool>) = mpsc::channel();
153156

154157
let serial_device_lock = device_lock.clone();
155158
let serial_devices_lock = devices_lock.clone();
@@ -174,6 +177,7 @@ fn main() {
174177
println!("starting main thread..");
175178
let _main_thread_handler = thread::spawn(|| {
176179
main_thread(
180+
sync_tx,
177181
main_data_lock,
178182
main_print_lock,
179183
raw_data_rx,
@@ -208,6 +212,15 @@ fn main() {
208212
egui_phosphor::add_to_fonts(&mut fonts, egui_phosphor::Variant::Regular);
209213
_cc.egui_ctx.set_fonts(fonts);
210214
_cc.egui_ctx.set_visuals(Visuals::dark());
215+
216+
let repaint_signal = _cc.egui_ctx.clone();
217+
thread::spawn(move || loop {
218+
if let Ok(_) = sync_rx.recv() {
219+
println!("requested repaint!");
220+
repaint_signal.request_repaint();
221+
}
222+
});
223+
211224
Ok(Box::new(MyApp::new(
212225
gui_print_lock,
213226
gui_data_lock,

0 commit comments

Comments
 (0)