Update EGUI to 0.19.0

This commit is contained in:
Ashcon Mohseninia 2022-09-10 21:27:57 +01:00
parent c63294e628
commit 755963bd1a
5 changed files with 107 additions and 114 deletions

View File

@ -13,13 +13,9 @@ ecu_diagnostics="0.90.51"
image = "0.24.1"
serial-rs = {git="https://github.com/rnd-ash/serial-rs"}
nfd="0.0.4"
#egui_winit_platform = "0.14.0"
pollster = "0.2.5"
eframe = {git = "https://github.com/emilk/egui", features=["wgpu"], rev="cf591da1a0bdb57c9495a3dcf0448b3c0d8e64e0" }
#wgpu = "0.12"
#winit = "0.26.1"
#egui-wgpu = "0.18.0"
#egui-winit = "0.18.0"
eframe = "0.19.0"
egui_extras = "0.19.0"
modular-bitfield = "0.11.2"
static_assertions = "1.1.0"
env_logger="0.9.0"

View File

@ -4,7 +4,7 @@ use std::hash::{Hash, Hasher};
use std::sync::{Arc, Mutex};
use std::time::Instant;
use ecu_diagnostics::kwp2000::Kwp2000DiagnosticServer;
use eframe::egui::plot::{Plot, Line, Legend, Values, Value};
use eframe::egui::plot::{Plot, Line, Legend};
use eframe::egui::{Ui, RichText, Color32};
use crate::ui::status_bar::MainStatusBar;
use crate::window::{PageAction, StatusBar};
@ -25,7 +25,6 @@ pub enum CommandStatus {
pub struct DiagnosticsPage{
bar: MainStatusBar,
server: Arc<Mutex<Kwp2000DiagnosticServer>>,
last_req_time: Instant,
text: CommandStatus,
record_data: Option<LocalRecordData>,
record_to_query: Option<RecordIdents>,
@ -40,7 +39,6 @@ impl DiagnosticsPage {
Self {
server,
bar,
last_req_time: Instant::now(),
text: CommandStatus::Ok("".into()),
record_data: None,
record_to_query: None,
@ -54,7 +52,7 @@ impl DiagnosticsPage {
impl crate::window::InterfacePage for DiagnosticsPage {
fn make_ui(&mut self, ui: &mut Ui, frame: &eframe::Frame) -> PageAction {
fn make_ui(&mut self, ui: &mut Ui, _frame: &eframe::Frame) -> PageAction {
let mut pending = false;
ui.heading("This is experimental, use with MOST up-to-date firmware");
@ -151,19 +149,19 @@ impl crate::window::InterfacePage for DiagnosticsPage {
if let Some(data) = &self.record_data {
data.to_table(ui);
if let LocalRecordData::Dma(dma) = data {
let mut points: Vec<Value> = Vec::new();
let mut points: Vec<[f64; 2]> = Vec::new();
for (idx, y) in dma.dma_buffer.clone().iter().enumerate() {
points.push(Value::new(idx as f64, *y));
points.push([idx as f64, *y as f64]);
}
let avg = dma.adc_detect;
let avg = dma.adc_detect as f64;
Plot::new("I2S DMA")
.allow_drag(false)
.include_x(0)
.include_x(1000)
.include_y(3300)
.show(ui, |plot_ui| {
plot_ui.line(Line::new(Values::from_values(points)));
plot_ui.line(Line::new(Values::from_values(vec![Value::new(0, avg), Value::new(1000, avg) ])).highlight(true))
plot_ui.line(Line::new(points));
plot_ui.line(Line::new(vec![[0.0, avg], [1000.0, avg]]).highlight(true))
});
} else {
@ -184,17 +182,17 @@ impl crate::window::InterfacePage for DiagnosticsPage {
// Can guarantee everything in `self.charting_data` will have the SAME length
// as `d`
let mut lines = Vec::new();
let mut legend = Legend::default();
let legend = Legend::default();
for (idx, (key, _, _)) in d.data.iter().enumerate() {
let mut points: Vec<Value> = Vec::new();
let mut points: Vec<[f64; 2]> = Vec::new();
for (timestamp, point) in &self.charting_data {
points.push(Value::new(*timestamp as f64, point.data[idx].1))
points.push([*timestamp as f64, point.data[idx].1 as f64])
}
let mut key_hasher = DefaultHasher::default();
key.hash(&mut key_hasher);
let r = key_hasher.finish();
lines.push(Line::new(Values::from_values(points)).name(key.clone()).color(Color32::from_rgb((r & 0xFF) as u8, ((r >> 8) & 0xFF) as u8, ((r >> 16) & 0xFF) as u8)))
lines.push(Line::new(points).name(key.clone()).color(Color32::from_rgb((r & 0xFF) as u8, ((r >> 8) & 0xFF) as u8, ((r >> 16) & 0xFF) as u8)))
}
let mut plot = Plot::new(d.group_name.clone())

View File

@ -1,8 +1,7 @@
use std::{sync::{Arc, atomic::{AtomicBool, Ordering}, RwLock, Mutex}, thread, time::Duration};
use std::{sync::{Arc, Mutex}};
use ecu_diagnostics::{kwp2000::{Kwp2000DiagnosticServer, SessionType, KWP2000Error}, DiagnosticServer};
use eframe::{egui::{plot::{Plot, Points, Line, LinkedAxisGroup, VLine, Text, LineStyle, PlotUi, Corner, Value, Values}, RichText}, epaint::{Stroke, Color32}};
use modular_bitfield::bitfield;
use ecu_diagnostics::{kwp2000::{Kwp2000DiagnosticServer, SessionType}, DiagnosticServer};
use eframe::{egui::{plot::{Plot, Line, LinkedAxisGroup, VLine, Text, LineStyle, PlotUi, Corner, PlotPoint}, RichText}, epaint::{Stroke, Color32}};
use serde::{Serialize, Deserialize};
use crate::{ui::status_bar::MainStatusBar, window::PageAction};
@ -283,58 +282,58 @@ impl crate::window::InterfacePage for ShiftReportPage {
let time_axis: Vec<u16> = (0..=report.total_ms).step_by(report.interval_points as usize).collect();
let mut time = 0;
let mut time: f64 = 0.0;
// Add pressure line (Static)
let mut pressure_spc_points: Vec<Value> = Vec::new();
let mut pressure_mpc_points: Vec<Value> = Vec::new();
let mut engine_rpm_points: Vec<Value> = Vec::new();
let mut input_rpm_points: Vec<Value> = Vec::new();
let mut output_rpm_points: Vec<Value> = Vec::new();
let mut torque_points: Vec<Value> = Vec::new();
pressure_spc_points.push(Value::new(0, 0)); // Always
pressure_mpc_points.push(Value::new(0, report.initial_mpc_pressure));
let mut pressure_spc_points: Vec<[f64; 2]> = Vec::new();
let mut pressure_mpc_points: Vec<[f64; 2]> = Vec::new();
let mut engine_rpm_points: Vec<[f64; 2]> = Vec::new();
let mut input_rpm_points: Vec<[f64; 2]> = Vec::new();
let mut output_rpm_points: Vec<[f64; 2]> = Vec::new();
let mut torque_points: Vec<[f64; 2]> = Vec::new();
pressure_spc_points.push([0.0, 0.0]); // Always
pressure_mpc_points.push([0.0, report.initial_mpc_pressure as f64]);
time += report.hold1_data.ramp_time;
pressure_spc_points.push(Value::new(time, report.hold1_data.spc_pressure));
pressure_mpc_points.push(Value::new(time, report.hold1_data.mpc_pressure));
time += report.hold1_data.hold_time;
pressure_spc_points.push(Value::new(time, report.hold1_data.spc_pressure));
pressure_mpc_points.push(Value::new(time, report.hold1_data.mpc_pressure));
time += report.hold1_data.ramp_time as f64;
pressure_spc_points.push([time, report.hold1_data.spc_pressure as f64]);
pressure_mpc_points.push([time, report.hold1_data.mpc_pressure as f64]);
time += report.hold1_data.hold_time as f64;
pressure_spc_points.push([time, report.hold1_data.spc_pressure as f64]);
pressure_mpc_points.push([time, report.hold1_data.mpc_pressure as f64]);
time += report.hold2_data.ramp_time;
pressure_spc_points.push(Value::new(time, report.hold2_data.spc_pressure));
pressure_mpc_points.push(Value::new(time, report.hold2_data.mpc_pressure));
time += report.hold2_data.hold_time;
pressure_spc_points.push(Value::new(time, report.hold2_data.spc_pressure));
pressure_mpc_points.push(Value::new(time, report.hold2_data.mpc_pressure));
time += report.hold2_data.ramp_time as f64;
pressure_spc_points.push([time, report.hold2_data.spc_pressure as f64]);
pressure_mpc_points.push([time, report.hold2_data.mpc_pressure as f64]);
time += report.hold2_data.hold_time as f64;
pressure_spc_points.push([time, report.hold2_data.spc_pressure as f64]);
pressure_mpc_points.push([time, report.hold2_data.mpc_pressure as f64]);
time += report.hold3_data.ramp_time;
pressure_spc_points.push(Value::new(time, report.hold3_data.spc_pressure));
pressure_mpc_points.push(Value::new(time, report.hold3_data.mpc_pressure));
time += report.hold3_data.hold_time;
pressure_spc_points.push(Value::new(time, report.hold3_data.spc_pressure));
pressure_mpc_points.push(Value::new(time, report.hold3_data.mpc_pressure));
time += report.hold3_data.ramp_time as f64;
pressure_spc_points.push([time, report.hold3_data.spc_pressure as f64]);
pressure_mpc_points.push([time, report.hold3_data.mpc_pressure as f64]);
time += report.hold3_data.hold_time as f64;
pressure_spc_points.push([time, report.hold3_data.spc_pressure as f64]);
pressure_mpc_points.push([time, report.hold3_data.mpc_pressure as f64]);
time += report.torque_data.ramp_time;
pressure_spc_points.push(Value::new(time, report.torque_data.spc_pressure));
pressure_mpc_points.push(Value::new(time, report.torque_data.mpc_pressure));
time += report.torque_data.hold_time;
pressure_spc_points.push(Value::new(time, report.torque_data.spc_pressure));
pressure_mpc_points.push(Value::new(time, report.torque_data.mpc_pressure));
time += report.torque_data.ramp_time as f64;
pressure_spc_points.push([time, report.torque_data.spc_pressure as f64]);
pressure_mpc_points.push([time, report.torque_data.mpc_pressure as f64]);
time += report.torque_data.hold_time as f64;
pressure_spc_points.push([time, report.torque_data.spc_pressure as f64]);
pressure_mpc_points.push([time, report.torque_data.mpc_pressure as f64]);
time += report.overlap_data.ramp_time;
pressure_spc_points.push(Value::new(time, report.overlap_data.spc_pressure));
pressure_mpc_points.push(Value::new(time, report.overlap_data.mpc_pressure));
time += report.overlap_data.hold_time;
pressure_spc_points.push(Value::new(time, report.overlap_data.spc_pressure));
pressure_mpc_points.push(Value::new(time, report.overlap_data.mpc_pressure));
time += report.overlap_data.ramp_time as f64;
pressure_spc_points.push([time, report.overlap_data.spc_pressure as f64]);
pressure_mpc_points.push([time, report.overlap_data.mpc_pressure as f64]);
time += report.overlap_data.hold_time as f64;
pressure_spc_points.push([time, report.overlap_data.spc_pressure as f64]);
pressure_mpc_points.push([time, report.overlap_data.mpc_pressure as f64]);
time += report.max_pressure_data.ramp_time;
pressure_spc_points.push(Value::new(time, report.max_pressure_data.spc_pressure));
pressure_mpc_points.push(Value::new(time, report.max_pressure_data.mpc_pressure));
time = report.total_ms;
pressure_spc_points.push(Value::new(time, report.max_pressure_data.spc_pressure));
pressure_mpc_points.push(Value::new(time, report.max_pressure_data.mpc_pressure));
time += report.max_pressure_data.ramp_time as f64;
pressure_spc_points.push([time, report.max_pressure_data.spc_pressure as f64]);
pressure_mpc_points.push([time, report.max_pressure_data.mpc_pressure as f64]);
time = report.total_ms as f64;
pressure_spc_points.push([time, report.max_pressure_data.spc_pressure as f64]);
pressure_mpc_points.push([time, report.max_pressure_data.mpc_pressure as f64]);
let mut rpm_max = *std::cmp::max(unsafe { report.engine_rpm }.iter().max().unwrap(), unsafe { report.input_rpm }.iter().max().unwrap()) as f64;
@ -343,35 +342,35 @@ impl crate::window::InterfacePage for ShiftReportPage {
for x in 0..report.report_len as usize {
engine_rpm_points.push(Value::new(time_axis[x], report.engine_rpm[x]));
input_rpm_points.push(Value::new(time_axis[x], report.input_rpm[x]));
output_rpm_points.push(Value::new(time_axis[x], report.output_rpm[x]));
torque_points.push(Value::new(time_axis[x], report.engine_torque[x]));
engine_rpm_points.push([time_axis[x] as f64, report.engine_rpm[x] as f64]);
input_rpm_points.push([time_axis[x] as f64, report.input_rpm[x] as f64]);
output_rpm_points.push([time_axis[x] as f64, report.output_rpm[x] as f64]);
torque_points.push([time_axis[x] as f64, report.engine_torque[x] as f64]);
}
// Add phase indication lines
let spc_pressure_line = Line::new(Values::from_values(pressure_spc_points)).name("SPC Pressure (mBar)");
let mpc_pressure_line = Line::new(Values::from_values(pressure_mpc_points)).name("MPC Pressure (mBar)");
let engine_line = Line::new(Values::from_values(engine_rpm_points)).name("Engine (RPM)");
let output_line = Line::new(Values::from_values(output_rpm_points)).name("Output shaft (RPM)");
let input_line = Line::new(Values::from_values(input_rpm_points)).name("Input shaft (RPM)");
let torque_line = Line::new(Values::from_values(torque_points)).name("Engine torque (Nm)");
let spc_pressure_line = Line::new(pressure_spc_points).name("SPC Pressure (mBar)");
let mpc_pressure_line = Line::new(pressure_mpc_points).name("MPC Pressure (mBar)");
let engine_line = Line::new(engine_rpm_points).name("Engine (RPM)");
let output_line = Line::new(output_rpm_points).name("Output shaft (RPM)");
let input_line = Line::new(input_rpm_points).name("Input shaft (RPM)");
let torque_line = Line::new(torque_points).name("Engine torque (Nm)");
time = 0;
time += report.hold1_data.hold_time+report.hold1_data.ramp_time;
time = 0.0;
time += (report.hold1_data.hold_time+report.hold1_data.ramp_time) as f64;
let hold1_end_time = time;
time += report.hold2_data.hold_time+report.hold2_data.ramp_time;
time += (report.hold2_data.hold_time+report.hold2_data.ramp_time) as f64;
let hold2_end_time = time;
time += report.hold3_data.hold_time+report.hold3_data.ramp_time;
time += (report.hold3_data.hold_time+report.hold3_data.ramp_time) as f64;
let hold3_end_time = time;
time += report.torque_data.hold_time+report.torque_data.ramp_time;
time += (report.torque_data.hold_time+report.torque_data.ramp_time) as f64;
let torque_end_time = time;
time += report.overlap_data.hold_time+report.overlap_data.ramp_time;
time += (report.overlap_data.hold_time+report.overlap_data.ramp_time) as f64;
let overlap_end_time = time;
time += report.max_pressure_data.hold_time+report.max_pressure_data.ramp_time;
time += (report.max_pressure_data.hold_time+report.max_pressure_data.ramp_time) as f64;
let max_p_end_time = time;
// #27ae60
let phase_colour = Color32::from_rgb(0x27, 0xae, 0x60);
@ -403,12 +402,12 @@ impl crate::window::InterfacePage for ShiftReportPage {
plot_ui.line(spc_pressure_line);
plot_ui.line(mpc_pressure_line);
add_shift_regions(plot_ui);
plot_ui.text(Text::new(Value::new((0+hold1_end_time)/2, 7700), "Bleed"));
plot_ui.text(Text::new(Value::new((hold1_end_time+hold2_end_time)/2, 7700), "Fill"));
plot_ui.text(Text::new(Value::new((hold2_end_time+hold3_end_time)/2, 7700), "Lock"));
plot_ui.text(Text::new(Value::new((hold3_end_time+torque_end_time)/2, 7700), "Torque"));
plot_ui.text(Text::new(Value::new((torque_end_time+overlap_end_time)/2, 7700), "Overlap"));
plot_ui.text(Text::new(Value::new((overlap_end_time+max_p_end_time)/2, 7700), "Max P"));
plot_ui.text(Text::new(PlotPoint::new((hold1_end_time)/2.0, 7700), "Bleed"));
plot_ui.text(Text::new(PlotPoint::new((hold1_end_time+hold2_end_time)/2.0, 7700), "Fill"));
plot_ui.text(Text::new(PlotPoint::new((hold2_end_time+hold3_end_time)/2.0, 7700), "Lock"));
plot_ui.text(Text::new(PlotPoint::new((hold3_end_time+torque_end_time)/2.0, 7700), "Torque"));
plot_ui.text(Text::new(PlotPoint::new((torque_end_time+overlap_end_time)/2.0, 7700), "Overlap"));
plot_ui.text(Text::new(PlotPoint::new((overlap_end_time+max_p_end_time)/2.0, 7700), "Max P"));
});
let mut plot_rpm = Plot::new("Input/Engine RPM")
@ -427,7 +426,7 @@ impl crate::window::InterfacePage for ShiftReportPage {
if report.timeout == 0 {
plot_ui.vline(VLine::new(report.transition_start).style(LineStyle::dashed_loose()).color(Color32::from_rgb(255, 192, 203)));
plot_ui.vline(VLine::new(report.transition_end).style(LineStyle::dashed_loose()).color(Color32::from_rgb(255, 192, 203)));
plot_ui.text(Text::new(Value::new((report.transition_start+report.transition_end)/2, rpm_max * 0.9), "SHIFT"));
plot_ui.text(Text::new(PlotPoint::new((report.transition_start+report.transition_end)/2, rpm_max * 0.9), "SHIFT"));
}
add_shift_regions(plot_ui)
});

View File

@ -1,7 +1,7 @@
use std::{sync::{Arc, Mutex, atomic::{AtomicBool, Ordering, AtomicU64}, RwLock}, thread, time::{Duration, Instant}, char::MAX};
use std::{sync::{Arc, Mutex, atomic::{AtomicBool, Ordering, AtomicU64}, RwLock}, thread, time::{Duration, Instant}};
use ecu_diagnostics::kwp2000::{Kwp2000DiagnosticServer, SessionType};
use eframe::egui::plot::{Plot, Legend, Line, Values, Value};
use eframe::egui::plot::{Plot, Legend, Line, PlotPoints};
use crate::{ui::status_bar::MainStatusBar, window::PageAction};
@ -66,46 +66,46 @@ impl SolenoidPage {
}
}
const GRAPH_TIME_MS: u16 = 100;
const GRAPH_TIME_MS: f64 = 100.0;
const MAX_DUTY: u16 = 0xFFF; // 12bit pwm (4096)
const VOLTAGE_HIGH: u16 = 12;
const VOLTAGE_LOW: u16 = 0;
const VOLTAGE_HIGH: f64 = 12.0;
const VOLTAGE_LOW: f64 = 0.0;
fn make_line_duty_pwm(duty: f32, freq: u16, x_off: f64, y_off: f64) -> Values {
fn make_line_duty_pwm(duty: f32, freq: u16, x_off: f64, y_off: f64) -> PlotPoints {
let num_pulses = freq / GRAPH_TIME_MS as u16;
let pulse_width = GRAPH_TIME_MS as f32 / num_pulses as f32;
let pulse_on_width = (duty as f32/4096f32) * pulse_width;
let pulse_width = GRAPH_TIME_MS as f64 / num_pulses as f64;
let pulse_on_width = (duty as f64/4096.0) * pulse_width;
let pulse_off_width = pulse_width - pulse_on_width;
let mut points: Vec<Value> = Vec::new();
let mut curr_x_pos = 0f32;
let mut points: Vec<[f64; 2]> = Vec::new();
let mut curr_x_pos = 0f64;
// Shortcut
if duty as u16 == MAX_DUTY {
points.push(Value::new(0, VOLTAGE_LOW));
points.push(Value::new(GRAPH_TIME_MS, VOLTAGE_LOW));
points.push([0.0, VOLTAGE_LOW]);
points.push([GRAPH_TIME_MS, VOLTAGE_LOW]);
} else if duty as u16 == 0 {
points.push(Value::new(0, VOLTAGE_HIGH));
points.push(Value::new(GRAPH_TIME_MS, VOLTAGE_HIGH));
points.push([0.0, VOLTAGE_HIGH]);
points.push([GRAPH_TIME_MS, VOLTAGE_HIGH]);
} else {
for i in 0..num_pulses {
// Start at 12V (High - Solenoid off)
points.push(Value::new(curr_x_pos, VOLTAGE_HIGH)); // High, left
points.push([curr_x_pos, VOLTAGE_HIGH]); // High, left
curr_x_pos += pulse_off_width;
points.push(Value::new(curr_x_pos, VOLTAGE_HIGH)); // High, right
points.push([curr_x_pos, VOLTAGE_HIGH]); // High, right
// Now vertical line
points.push(Value::new(curr_x_pos, VOLTAGE_LOW));
points.push([curr_x_pos, VOLTAGE_LOW]);
curr_x_pos += pulse_on_width;
points.push(Value::new(curr_x_pos, VOLTAGE_LOW));
points.push([curr_x_pos, VOLTAGE_LOW]);
// Now draw at 0V (Low - Solenoid on)
}
}
for p in points.iter_mut() {
p.x += x_off;
p.y += y_off;
p[0] += x_off;
p[1] += y_off;
}
Values::from_values(points)
points.into()
}

View File

@ -65,7 +65,7 @@ impl StatusBar for MainStatusBar {
egui::containers::ScrollArea::new([false, true])
.max_height(300f32)
.auto_shrink([false, false])
.stick_to_bottom()
.stick_to_bottom(true)
.show(l_view, |scroll| {
for msg in &self.msgs {
scroll.label(