Skip to content

Commit

Permalink
Add tasks.json and update main.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickdewid committed Mar 15, 2024
1 parent 05a29b6 commit 0be8293
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 31 deletions.
17 changes: 17 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cargo",
"command": "build",
"problemMatcher": [
"$rustc",
],
"group": {
"kind": "build",
"isDefault": true
},
"label": "rust: cargo build"
}
]
}
65 changes: 34 additions & 31 deletions m-ecu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ mod app {

let mut power2_enable = gpioe.pe2.into_push_pull_output();

let (_, (_, _, pwm1, pwm0)) = ctx
let (_, (_, _, mut pwm1, mut pwm0)) = ctx
.device
.TIM3
.pwm_advanced(
Expand All @@ -177,6 +177,12 @@ mod app {
.period(32_767)
.finalize();

pwm0.set_duty(0);
pwm0.enable();

pwm1.set_duty(0);
pwm1.enable();

// let mut in2 = gpiob.pb0.into_push_pull_output();
// let mut in1 = gpiob.pb1.into_push_pull_output();

Expand Down Expand Up @@ -381,44 +387,41 @@ mod app {
);

if let Some(rpm) = message.rpm {
if rpm < 700 {
ctx.local.pwm0.set_duty(0);
ctx.local.pwm0.enable();
// if rpm < 700 {
// ctx.local.pwm0.set_duty(0);
// ctx.local.pwm0.enable();

ctx.local.pwm1.set_duty(0);
ctx.local.pwm1.enable();
} else if rpm < 1050 {
let value = 24_500;
// ctx.local.pwm1.set_duty(0);
// ctx.local.pwm1.enable();
// } else

ctx.local.pwm0.set_duty(value);
ctx.local.pwm0.enable();
let duty = match rpm {
..=1049 => 24_500,
1050..=1549 => 22_500,
1550..=u16::MAX => 20_500,
};

ctx.local.pwm1.set_duty(0);
ctx.local.pwm1.enable();
} else if rpm < 1550 {
let value = 22_500;
ctx.local.pwm0.set_duty(duty);

ctx.local.pwm0.set_duty(value);
ctx.local.pwm0.enable();
// if rpm < 1050 {
// let value = 24_500;

ctx.local.pwm1.set_duty(0);
ctx.local.pwm1.enable();
}
}
}
// PGN::TorqueSpeedControl1 => {
// let rpm = u16::from_le_bytes([frame.pdu()[6], frame.pdu()[7]]);
// ctx.local.pwm0.set_duty(value);
// ctx.local.pwm0.enable();

// spn::TorqueSpeedControl1Message::from_pdu(frame.pdu()),
// ctx.local.pwm1.set_duty(0);
// ctx.local.pwm1.enable();
// } else if rpm < 1550 {
// let value = 22_500;

// let value = u16::from_le_bytes([frame.pdu()[0], frame.pdu()[1]]);
// ctx.local.pwm0.set_duty(value);
// ctx.local.pwm0.enable();

// ctx.local.pwm0.set_duty(value);
// ctx.local.pwm0.enable();

// ctx.local.pwm1.set_duty(0);
// ctx.local.pwm1.enable();
// }
// ctx.local.pwm1.set_duty(0);
// ctx.local.pwm1.enable();
// }
}
}
// PGN::TorqueSpeedControl1 => {
// // TODO: Filter on destination address until the CAN filter is implemented
// if frame.id().destination_address() == Some(crate::J1939_ADDRESS)
Expand Down

0 comments on commit 0be8293

Please sign in to comment.