Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync the frame updates to data packets received (and parsed) #104

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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] = &[
Expand Down Expand Up @@ -471,8 +467,6 @@ impl MyApp {
self.command = self.history[self.index].clone();
}
}

ctx.request_repaint()
});
ui.add_space(left_border);
});
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ fn split(payload: &str) -> Vec<f32> {
}

fn main_thread(
sync_tx: Sender<bool>,
data_lock: Arc<RwLock<DataContainer>>,
print_lock: Arc<RwLock<Vec<Print>>>,
raw_data_rx: Receiver<Packet>,
Expand All @@ -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 {
Expand Down Expand Up @@ -150,6 +152,7 @@ fn main() {
let (clear_tx, clear_rx): (Sender<bool>, Receiver<bool>) = mpsc::channel();
let (names_tx, names_rx): (Sender<Vec<String>>, Receiver<Vec<String>>) = mpsc::channel();
let (raw_data_tx, raw_data_rx): (Sender<Packet>, Receiver<Packet>) = mpsc::channel();
let (sync_tx, sync_rx): (Sender<bool>, Receiver<bool>) = mpsc::channel();

let serial_device_lock = device_lock.clone();
let serial_devices_lock = devices_lock.clone();
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading