Skip to content

Commit

Permalink
Make graph pages update continuously
Browse files Browse the repository at this point in the history
  • Loading branch information
rnd-ash committed Jul 19, 2023
1 parent 81c0649 commit 7f76a09
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
5 changes: 3 additions & 2 deletions config_app/src/ui/diagnostics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::window::{PageAction, StatusBar};
use crate::window::{PageAction, StatusBar, get_context};
use backend::diag::Nag52Diag;
use backend::ecu_diagnostics::kwp2000::{KwpSessionTypeByte, KwpSessionType};
use eframe::egui::plot::{Legend, Line, Plot};
use eframe::egui::{Color32, RichText, Ui};
use eframe::egui::{Color32, RichText, Ui, Context};
use eframe::epaint::Stroke;
use std::borrow::Borrow;
use std::collections::hash_map::DefaultHasher;
Expand Down Expand Up @@ -143,6 +143,7 @@ impl DiagnosticsPage {
drop(lck);
}
}
get_context().request_repaint();
let taken = start.elapsed().as_millis() as u64;
if taken < RLI_PLOT_INTERVAL {
std::thread::sleep(Duration::from_millis(RLI_PLOT_INTERVAL - taken));
Expand Down
13 changes: 11 additions & 2 deletions config_app/src/ui/diagnostics/solenoids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use std::{
time::{Duration, Instant},
};

use crate::{window::PageAction};
use crate::{window::{PageAction, get_context}};

use super::rli::{DataSolenoids, LocalRecordData, RecordIdents};
use super::{rli::{DataSolenoids, LocalRecordData, RecordIdents, RLI_PLOT_INTERVAL}, RLI_CHART_DISPLAY_TIME};

const UPDATE_DELAY_MS: u64 = 100;

Expand All @@ -35,6 +35,7 @@ impl SolenoidPage {
pub fn new(mut nag: Nag52Diag) -> Self {
let run = Arc::new(AtomicBool::new(true));
let run_t = run.clone();
let run_tt = run.clone();

let store = Arc::new(RwLock::new(None));
let store_t = store.clone();
Expand All @@ -47,6 +48,14 @@ impl SolenoidPage {

let last_update = Arc::new(AtomicU64::new(0));
let last_update_t = last_update.clone();

let _ = thread::spawn(move || {
while run_tt.load(Ordering::Relaxed) {
get_context().request_repaint();
std::thread::sleep(Duration::from_millis(RLI_PLOT_INTERVAL));
};
});

let _ = thread::spawn(move || {
nag.with_kwp(|server| {
server.kwp_set_session(KwpSessionTypeByte::Standard(KwpSessionType::Normal))
Expand Down
7 changes: 6 additions & 1 deletion config_app/src/ui/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use eframe::egui::{self, ScrollArea};
use octocrab::{models::repos::Release, repos::releases::ListReleasesBuilder};
use tokio::runtime::Runtime;

use crate::window::{InterfacePage, PageAction};
use crate::window::{InterfacePage, PageAction, get_context};

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum CurrentFlashState {
Expand Down Expand Up @@ -313,6 +313,7 @@ impl InterfacePage for UpdatePage {
let fw_c = c_fw.clone().unwrap();
let state_c = self.status.clone();
std::thread::spawn(move || {
get_context().request_repaint();
*state_c.write().unwrap() = CurrentFlashState::Prepare;
let (start_addr, bs) = match ng.begin_ota(fw_c.raw.len() as u32) {
Ok((a, b)) => (a, b),
Expand All @@ -321,6 +322,7 @@ impl InterfacePage for UpdatePage {
return;
},
};
get_context().request_repaint();
let mut written = 0;
for (bid, block) in fw_c.raw.chunks(bs as usize).enumerate() {
match ng.transfer_data(((bid + 1) & 0xFF) as u8, block) {
Expand All @@ -333,6 +335,7 @@ impl InterfacePage for UpdatePage {
return;
}
}
get_context().request_repaint();
}
*state_c.write().unwrap() = CurrentFlashState::Verify;
match ng.end_ota(true) {
Expand All @@ -341,6 +344,7 @@ impl InterfacePage for UpdatePage {
*state_c.write().unwrap() = CurrentFlashState::Failed(format!("Error verification: {}", e));
}
}
get_context().request_repaint();
});
}
}
Expand Down Expand Up @@ -384,6 +388,7 @@ impl InterfacePage for UpdatePage {
return;
}
}
get_context().request_repaint();
}
match ng.end_ota(false) {
Ok(_) => *state_c.write().unwrap() = {
Expand Down
17 changes: 15 additions & 2 deletions config_app/src/window.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
use std::{
collections::VecDeque,
ops::Add,
time::{Duration, Instant}, sync::Arc,
time::{Duration, Instant}, sync::Arc, borrow::BorrowMut,
};

use backend::{diag::Nag52Diag, ecu_diagnostics::DiagError, hw::usb::{EspLogMessage, EspLogLevel}};
use eframe::{
egui::{self, Direction, RichText, WidgetText, Sense, Button, ScrollArea},
egui::{self, Direction, RichText, WidgetText, Sense, Button, ScrollArea, Context},
epaint::{Pos2, Vec2, Color32, Rect, Rounding, FontId}, emath::Align2,
};
use egui_extras::{TableBuilder, Column};
use egui_toast::{Toast, ToastKind, ToastOptions, Toasts, ERROR_COLOR, SUCCESS_COLOR};

static mut GLOBAL_EGUI_CONTEXT: Option<Context> = None;

pub fn get_context() -> &'static Context {
unsafe {
GLOBAL_EGUI_CONTEXT.as_ref().unwrap()
}
}

#[derive(Debug, Clone)]
pub enum PageLoadState {
Ok,
Expand Down Expand Up @@ -75,6 +83,11 @@ pub const MAX_BANDWIDTH: f32 = 155200.0 / 4.0;

impl eframe::App for MainWindow {
fn update(&mut self, ctx: &eframe::egui::Context, frame: &mut eframe::Frame) {

if unsafe { GLOBAL_EGUI_CONTEXT.is_none() } {
unsafe { GLOBAL_EGUI_CONTEXT = Some(ctx.clone()) };
}

let stack_size = self.pages.len();
let mut s_bar_height = 0.0;
if stack_size > 0 {
Expand Down

0 comments on commit 7f76a09

Please sign in to comment.