Skip to content

Commit

Permalink
Support toggling TCC solenoid
Browse files Browse the repository at this point in the history
  • Loading branch information
rnd-ash committed Aug 2, 2023
1 parent cc98b53 commit 59ff97e
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 5 deletions.
33 changes: 33 additions & 0 deletions config_app/src/ui/routine_tests/adaptation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use backend::diag::Nag52Diag;

use crate::window::PageAction;



pub struct AdaptationViewerPage {
nag: Nag52Diag,

}

impl AdaptationViewerPage {
pub fn new(nag: Nag52Diag) -> Self {
Self {
nag,
}
}
}

impl crate::window::InterfacePage for AdaptationViewerPage {
fn make_ui(&mut self, ui: &mut eframe::egui::Ui, frame: &eframe::Frame) -> crate::window::PageAction {
ui.heading("Adaptation viewer");
PageAction::None
}

fn get_title(&self) -> &'static str {
"Adaptation viewer"
}

fn should_show_statusbar(&self) -> bool {
true
}
}
40 changes: 35 additions & 5 deletions config_app/src/ui/routine_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use backend::diag::Nag52Diag;

use crate::window::PageAction;

use self::solenoid_test::SolenoidTestPage;
use self::{solenoid_test::SolenoidTestPage, adaptation::AdaptationViewerPage, tcc_control::TccControlPage};

pub mod solenoid_test;

pub mod adaptation;
pub mod tcc_control;
pub struct RoutinePage {
nag: Nag52Diag,
}
Expand All @@ -28,18 +29,47 @@ impl crate::window::InterfacePage for RoutinePage {

ui.label(
"
Select test routine to run
Here you can run some diagnostics on your transmission and TCU, as well as reset adaptation data that the TCU has done.
NOTE: It is recommended to always reset your adaptation after changing ATF or doing any maintenence on the gearbox!
",
);

ui.separator();
let mut page_action = PageAction::None;

ui.label(
"
Run the solenoid test to test if any of gearbox's solenoids are bad
",
);
if ui.button("Solenoid test").clicked() {
page_action = PageAction::Add(Box::new(SolenoidTestPage::new(
self.nag.clone()
)));
}

ui.label(
"
Check or reset the TCUs adaptation
",
);
if ui.button("Adaptation view / reset").clicked() {
page_action = PageAction::Add(Box::new(AdaptationViewerPage::new(
self.nag.clone()
)));
}

ui.label(
"
Enable or disable the Torque converter (TCC) control solenoid in order to help
diagnosis of any vibrations in the vehicle
",
);
if ui.button("TCC solenoid toggler").clicked() {
page_action = PageAction::Add(Box::new(TccControlPage::new(
self.nag.clone()
)));
}

page_action
}

Expand Down
94 changes: 94 additions & 0 deletions config_app/src/ui/routine_tests/tcc_control.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
use std::sync::{Arc, RwLock, atomic::{AtomicBool, Ordering}};

use backend::{diag::Nag52Diag, ecu_diagnostics::kwp2000::KwpSessionType};
use eframe::egui::Context;

use crate::window::PageAction;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u8)]
enum TccCommand {
EnableTcc = 2,
DisableTcc = 0
}

pub struct TccControlPage {
nag: Nag52Diag,
status: Arc<RwLock<String>>,
running: Arc<AtomicBool>
}

impl TccControlPage {
pub fn new(nag: Nag52Diag) -> Self {
Self {
nag,
running: Arc::new(AtomicBool::new(false)),
status: Arc::new(RwLock::new(String::new()))
}
}
}

impl TccControlPage {
fn run_tcc_control(&mut self, mode: TccCommand, ctx: Context) {
let nag_c = self.nag.clone();
let status_c = self.status.clone();
let running_c = self.running.clone();
std::thread::spawn(move|| {
running_c.store(true, Ordering::Relaxed);
*status_c.write().unwrap() = String::new();
ctx.request_repaint();

let res = nag_c.with_kwp(|kwp| {
kwp.kwp_set_session(KwpSessionType::ExtendedDiagnostics.into())?;
kwp.send_byte_array_with_response(&[0x31, 0x33, mode as u8])?;
kwp.kwp_set_session(KwpSessionType::Normal.into())?;
Ok(())
});

*status_c.write().unwrap() = match res {
Ok(_) => "Operation completed successfully".into(),
Err(e) => format!("Operation failed. Error: {e:?}"),
};

running_c.store(false, Ordering::Relaxed);
ctx.request_repaint();
});
}
}

impl crate::window::InterfacePage for TccControlPage {
fn make_ui(&mut self, ui: &mut eframe::egui::Ui, frame: &eframe::Frame) -> crate::window::PageAction {
ui.heading("Torque converter solenoid control");
ui.label("
Here you can either enable or disable control of the Torque converter (TCC)
solenoid in order to diagnose any issues with vibrations in the vehicle.
NOTE: Disabling the TCC solenoid will only persist until ignition off. The next time
the vehicle is turned on, the TCC solenoid will be back to active again.
");

if !self.running.load(Ordering::Relaxed) {
ui.horizontal(|ui| {
if ui.button("Enable the TCC solenoid").clicked() {
self.run_tcc_control(TccCommand::EnableTcc, ui.ctx().clone())
}
if ui.button("Disable the TCC solenoid").clicked() {
self.run_tcc_control(TccCommand::DisableTcc, ui.ctx().clone())
}
});
} else {
ui.label("Routine running...");
}
ui.label(self.status.read().unwrap().clone());

PageAction::None
}

fn get_title(&self) -> &'static str {
"TCC control"
}

fn should_show_statusbar(&self) -> bool {
true
}
}

0 comments on commit 59ff97e

Please sign in to comment.