From 60923af5e425b0dda8b336a2401077813f500166 Mon Sep 17 00:00:00 2001 From: Ashcon Mohseninia Date: Sun, 4 Dec 2022 11:34:55 +0000 Subject: [PATCH] Add shift time tables --- config_app/Cargo.toml | 13 +- config_app/src/ui/map_editor/help_view.rs | 19 ++ config_app/src/ui/map_editor/map_list.rs | 284 ++++++++++++++++++++++ config_app/src/ui/map_editor/mod.rs | 153 +----------- config_app/src/window.rs | 16 +- 5 files changed, 327 insertions(+), 158 deletions(-) create mode 100644 config_app/src/ui/map_editor/help_view.rs create mode 100644 config_app/src/ui/map_editor/map_list.rs diff --git a/config_app/Cargo.toml b/config_app/Cargo.toml index 8844ac7..b4c39bc 100644 --- a/config_app/Cargo.toml +++ b/config_app/Cargo.toml @@ -10,11 +10,10 @@ name = "config_app" path = "src/main.rs" [dependencies] -serde_json = { version = "1.0.79" } -serde = { version = "1.0.137", features = ["derive"] } -ecu_diagnostics="0.90.51" -#ecu_diagnostics = {path="../../ecu_diagnostics"} -image = "0.24.1" +serde_json = { version = "1.0.89" } +serde = { version = "1.0.148", features = ["derive"] } +ecu_diagnostics="0.90.52" +image = "0.24.5" serial-rs = {git="https://github.com/rnd-ash/serial-rs"} nfd="0.0.4" pollster = "0.2.5" @@ -22,7 +21,7 @@ eframe = {version="0.19.0", features=["wgpu"]} egui_extras = "0.19.0" modular-bitfield = "0.11.2" static_assertions = "1.1.0" -env_logger="0.9.0" -egui-toast="0.3.0" +env_logger="0.10.0" +egui-toast="0.4.0" chrono = "0.4.23" nom="7.1.1" \ No newline at end of file diff --git a/config_app/src/ui/map_editor/help_view.rs b/config_app/src/ui/map_editor/help_view.rs new file mode 100644 index 0000000..75c876a --- /dev/null +++ b/config_app/src/ui/map_editor/help_view.rs @@ -0,0 +1,19 @@ +use eframe::egui; + + +pub trait HelpView: Clone + Sized { + fn gen_ui(&self, meta: &super::MapData, raw_ui: &mut egui::Ui) -> bool where Self: Sized; +} + + +#[derive(Clone, Copy)] +pub struct FillingPressureHelp; + +impl HelpView for FillingPressureHelp { + fn gen_ui(&self, meta: &super::MapData, raw_ui: &mut egui::Ui) -> bool { + if raw_ui.button("Back").clicked() { + return true; + } + return false; + } +} \ No newline at end of file diff --git a/config_app/src/ui/map_editor/map_list.rs b/config_app/src/ui/map_editor/map_list.rs new file mode 100644 index 0000000..fd50844 --- /dev/null +++ b/config_app/src/ui/map_editor/map_list.rs @@ -0,0 +1,284 @@ +use super::MapData; + + +pub (crate) const MAP_ARRAY: &[MapData] = &[ + MapData::new( + 0x01, + "Upshift (A)", + "%", + "", + "Pedal position (%)", + "Gear shift", + "Upshift RPM threshold", + "RPM", + None, + Some(&["1->2", "2->3", "3->4", "4->5"]), + //None + ), + MapData::new( + 0x02, + "Upshift (C)", + "%", + "", + "Pedal position (%)", + "Gear shift", + "Upshift RPM threshold", + "RPM", + None, + Some(&["1->2", "2->3", "3->4", "4->5"]), + //None + ), + MapData::new( + 0x03, + "Upshift (S)", + "%", + "", + "Pedal position (%)", + "Gear shift", + "Upshift RPM threshold", + "RPM", + None, + Some(&["1->2", "2->3", "3->4", "4->5"]), + //None + ), + MapData::new( + 0x04, + "Downshift (A)", + "%", + "", + "Pedal position (%)", + "Gear shift", + "Downshift RPM threshold", + "RPM", + None, + Some(&["2->1", "3->2", "4->3", "5->4"]), + //None + ), + MapData::new( + 0x05, + "Downshift (C)", + "%", + "", + "Pedal position (%)", + "Gear shift", + "Downshift RPM threshold", + "RPM", + None, + Some(&["2->1", "3->2", "4->3", "5->4"]), + //None + ), + MapData::new( + 0x06, + "Downshift (S)", + "%", + "", + "Pedal position (%)", + "Gear shift", + "Downshift RPM threshold", + "RPM", + None, + Some(&["2->1", "3->2", "4->3", "5->4"]), + //None + ), + MapData::new( + 0x07, + "Working pressure", + "%", + "", + "Input torque (% of rated)", + "Gear", + "Downshift RPM threshold", + "mBar", + None, + Some(&["P/N", "R1/R2", "1", "2", "3", "4", "5"]), + //None + ), + MapData::new( + 0x08, + "Pressure solenoid current", + "mBar", + "C", + "Working pressure", + "ATF Temperature", + "Solenoid current (mA)", + "mA", + None, + None, + //None + ), + MapData::new( + 0x09, + "TCC solenoid Pwm", + "mBar", + "C", + "Converter pressure", + "ATF Temperature", + "Solenoid PWM duty (4096 = 100% on)", + "/4096", + None, + None, + //None + ), + MapData::new( + 0x0A, + "Clutch filling time", + "C", + "", + "ATF Temperature", + "Clutch", + "filling time in millseconds", + "ms", + None, + Some(&["K1", "K2", "K3", "B1", "B2"]), + //None + ), + MapData::new( + 0x0B, + "Clutch filling pressure", + "C", + "", + "", + "Clutch", + "filling pressure in millibar", + "mBar", + None, + Some(&["K1", "K2", "K3", "B1", "B2"]), + //None + ), + + MapData::new( + 0x10, + "Upshift overlap time (Agility)", + "%", + "RPM", + "", + "Pedal position", + "Input speed", + "ms", + None, + None, + //None + ), + + MapData::new( + 0x11, + "Downshift overlap time (Agility)", + "%", + "RPM", + "", + "Pedal position", + "Input speed", + "ms", + None, + None, + //None + ), + MapData::new( + 0x12, + "Upshift overlap time (Standard)", + "%", + "RPM", + "", + "Pedal position", + "Input speed", + "ms", + None, + None, + //None + ), + + MapData::new( + 0x13, + "Downshift overlap time (Standard)", + "%", + "RPM", + "", + "Pedal position", + "Input speed", + "ms", + None, + None, + //None + ), + MapData::new( + 0x14, + "Upshift overlap time (Comfort)", + "%", + "RPM", + "", + "Pedal position", + "Input speed", + "ms", + None, + None, + //None + ), + + MapData::new( + 0x15, + "Downshift overlap time (Comfort)", + "%", + "RPM", + "", + "Pedal position", + "Input speed", + "ms", + None, + None, + //None + ), + MapData::new( + 0x16, + "Upshift overlap time (Winter)", + "%", + "RPM", + "", + "Pedal position", + "Input speed", + "ms", + None, + None, + //None + ), + + MapData::new( + 0x17, + "Downshift overlap time (Winter)", + "%", + "RPM", + "", + "Pedal position", + "Input speed", + "ms", + None, + None, + //None + ), + MapData::new( + 0x18, + "Upshift overlap time (Manual)", + "%", + "RPM", + "", + "Pedal position", + "Input speed", + "ms", + None, + None, + //None + ), + + MapData::new( + 0x19, + "Downshift overlap time (Manual)", + "%", + "RPM", + "", + "Pedal position", + "Input speed", + "ms", + None, + None, + //None + ), +]; \ No newline at end of file diff --git a/config_app/src/ui/map_editor/mod.rs b/config_app/src/ui/map_editor/mod.rs index 42ce3fc..9f59829 100644 --- a/config_app/src/ui/map_editor/mod.rs +++ b/config_app/src/ui/map_editor/mod.rs @@ -23,10 +23,12 @@ use egui_extras::{Size, Table, TableBuilder}; use egui_toast::ToastKind; use nom::number::complete::le_u16; mod map_widget; - +mod help_view; +mod map_list; +use map_list::MAP_ARRAY; use crate::window::PageAction; -use self::map_widget::MapWidget; +use self::{map_widget::MapWidget, help_view::HelpView}; use super::{ configuration::{ @@ -329,7 +331,6 @@ impl Map { let mut value = format!("{}", copy.data_modify[map_idx]); if let Some((curr_edit_idx, current_edit_txt, resp)) = ©.curr_edit_cell { if *curr_edit_idx == map_idx { - println!("Editing current cell {}", current_edit_txt); value = current_edit_txt.clone(); } } @@ -343,7 +344,6 @@ impl Map { response = response.on_hover_text(format!("Current in EEPROM: {}", copy.data_eeprom[map_idx])); } if response.lost_focus() || cell.ctx().input().key_pressed(egui::Key::Enter) { - println!("Cell ({},{}) lost focus, editing done", row_id, x_pos); if let Ok(new_v) = i16::from_str_radix(&value, 10) { copy.data_modify[map_idx] = new_v; } @@ -455,7 +455,7 @@ impl Map { if raw_ui.button("Write changes (To EEPROM)").clicked() { return match self.save_to_eeprom() { Ok(_) => { - if let Ok(new_data) = Self::new(self.meta.id, self.ecu_ref.clone(), self.meta) { + if let Ok(new_data) = Self::new(self.meta.id, self.ecu_ref.clone(), self.meta.clone()) { *self = new_data; } Some(PageAction::SendNotification { text: format!("Map {} EEPROM save OK!", self.eeprom_key), kind: ToastKind::Success }) @@ -473,7 +473,7 @@ impl Map { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Clone)] pub struct MapData { id: u8, name: &'static str, @@ -485,6 +485,7 @@ pub struct MapData { value_unit: &'static str, x_replace: Option<&'static [&'static str]>, y_replace: Option<&'static [&'static str]>, + show_help: bool } impl MapData { @@ -498,7 +499,7 @@ impl MapData { v_desc: &'static str, value_unit: &'static str, x_replace: Option<&'static [&'static str]>, - y_replace: Option<&'static [&'static str]>, + y_replace: Option<&'static [&'static str]> ) -> Self { Self { id, @@ -511,145 +512,11 @@ impl MapData { value_unit, x_replace, y_replace, + show_help: false } } } -const MAP_ARRAY: [MapData; 11] = [ - MapData::new( - 0x01, - "Upshift (A)", - "%", - "", - "Pedal position (%)", - "Gear shift", - "Upshift RPM threshold", - "RPM", - None, - Some(&["1->2", "2->3", "3->4", "4->5"]), - ), - MapData::new( - 0x02, - "Upshift (C)", - "%", - "", - "Pedal position (%)", - "Gear shift", - "Upshift RPM threshold", - "RPM", - None, - Some(&["1->2", "2->3", "3->4", "4->5"]), - ), - MapData::new( - 0x03, - "Upshift (S)", - "%", - "", - "Pedal position (%)", - "Gear shift", - "Upshift RPM threshold", - "RPM", - None, - Some(&["1->2", "2->3", "3->4", "4->5"]), - ), - MapData::new( - 0x04, - "Downshift (A)", - "%", - "", - "Pedal position (%)", - "Gear shift", - "Downshift RPM threshold", - "RPM", - None, - Some(&["2->1", "3->2", "4->3", "5->4"]), - ), - MapData::new( - 0x05, - "Downshift (C)", - "%", - "", - "Pedal position (%)", - "Gear shift", - "Downshift RPM threshold", - "RPM", - None, - Some(&["2->1", "3->2", "4->3", "5->4"]), - ), - MapData::new( - 0x06, - "Downshift (S)", - "%", - "", - "Pedal position (%)", - "Gear shift", - "Downshift RPM threshold", - "RPM", - None, - Some(&["2->1", "3->2", "4->3", "5->4"]), - ), - MapData::new( - 0x07, - "Working pressure", - "%", - "", - "Input torque (% of rated)", - "Gear", - "Downshift RPM threshold", - "mBar", - None, - Some(&["P/N", "R1/R2", "1", "2", "3", "4", "5"]), - ), - MapData::new( - 0x08, - "Pressure solenoid current", - "mBar", - "C", - "Working pressure", - "ATF Temperature", - "Solenoid current (mA)", - "mA", - None, - None, - ), - MapData::new( - 0x09, - "TCC solenoid Pwm", - "mBar", - "C", - "Converter pressure", - "ATF Temperature", - "Solenoid PWM duty (4096 = 100% on)", - "/4096", - None, - None, - ), - MapData::new( - 0x0A, - "Clutch filling time", - "C", - "", - "ATF Temperature", - "Clutch", - "filling time in millseconds", - "ms", - None, - Some(&["K1", "K2", "K3", "B1", "B2"]), - ), - MapData::new( - 0x0B, - "Clutch filling pressure", - "C", - "", - "", - "Clutch", - "filling pressure in millibar", - "mBar", - None, - Some(&["K1", "K2", "K3", "B1", "B2"]), - ), -]; - pub struct MapEditor { bar: MainStatusBar, server: Arc>, @@ -675,7 +542,7 @@ impl super::InterfacePage for MapEditor { ui: &mut eframe::egui::Ui, frame: &eframe::Frame, ) -> crate::window::PageAction { - for map in &MAP_ARRAY { + for map in MAP_ARRAY { if ui.button(map.name).clicked() { self.error = None; match Map::new(map.id, self.server.clone(), map.clone()) { diff --git a/config_app/src/window.rs b/config_app/src/window.rs index bb71492..70d548f 100644 --- a/config_app/src/window.rs +++ b/config_app/src/window.rs @@ -10,7 +10,7 @@ use crate::ui::{ status_bar::{self}, }; use eframe::{ - egui::{self, Direction}, + egui::{self, Direction, WidgetText, RichText}, epaint::Pos2, }; use egui_toast::{Toast, ToastKind, ToastOptions, Toasts}; @@ -69,7 +69,7 @@ impl eframe::App for MainWindow { self.pop_page(); } - let mut toasts = Toasts::new(ctx) + let mut toasts = Toasts::new() .anchor(Pos2::new( 5.0, ctx.available_rect().height() - s_bar_height - 5.0, @@ -92,18 +92,18 @@ impl eframe::App for MainWindow { } PageAction::SendNotification { text, kind } => { println!("Pushing notification {}", text); - toasts.add( - text, + toasts.add(Toast { kind, - ToastOptions { + text: WidgetText::RichText(RichText::new(text)), + options: ToastOptions { show_icon: true, expires_at: Some(Instant::now().add(Duration::from_secs(5))), - }, - ); + } + }); } } }); - toasts.show(); + toasts.show(&ctx); } ctx.request_repaint(); }