Skip to content

Commit

Permalink
one big secoc/not-secoc block
Browse files Browse the repository at this point in the history
  • Loading branch information
jyoung8607 committed Oct 2, 2024
1 parent 4c43d25 commit 25e1fbc
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions board/safety/safety_toyota.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,33 @@ static void toyota_rx_hook(const CANPacket_t *to_push) {
}

// enter controls on rising edge of ACC, exit controls on ACC off
if (!toyota_secoc && (addr == 0x1D2)) {
bool cruise_engaged = GET_BIT(to_push, 5U);
pcm_cruise_check(cruise_engaged);
}
if (toyota_secoc && (addr == 0x176)) {
bool cruise_engaged = GET_BIT(to_push, 5U);
pcm_cruise_check(cruise_engaged);
}

// exit controls on rising edge of gas press
if (!toyota_secoc && (addr == 0x1D2)) {
gas_pressed = !GET_BIT(to_push, 4U); // GAS_PEDAL.GAS_RELEASED
}
if (toyota_secoc && (addr == 0x116)) {
gas_pressed = GET_BYTE(to_push, 1) != 0U; // GAS_PEDAL.GAS_PEDAL_USER
// exit controls on rising edge of gas press, if not alternative experience
// exit controls on rising edge of brake press
if (toyota_secoc) {
if (addr == 0x176) {
bool cruise_engaged = GET_BIT(to_push, 5U);
pcm_cruise_check(cruise_engaged);
}
if (addr == 0x116) {
gas_pressed = GET_BYTE(to_push, 1) != 0U; // GAS_PEDAL.GAS_PEDAL_USER
}
if (addr == 0x101) {
brake_pressed = GET_BIT(to_push, 3U);
}
} else {
if (addr == 0x1D2) {
bool cruise_engaged = GET_BIT(to_push, 5U);
pcm_cruise_check(cruise_engaged);
}
if (addr == 0x1D2) {
gas_pressed = !GET_BIT(to_push, 4U); // GAS_PEDAL.GAS_RELEASED
}
if (!toyota_alt_brake && (addr == 0x226)) {
brake_pressed = GET_BIT(to_push, 37U);
}
if (toyota_alt_brake && (addr == 0x224)) {
brake_pressed = GET_BIT(to_push, 5U);
}
}

// sample speed
Expand All @@ -129,17 +141,6 @@ static void toyota_rx_hook(const CANPacket_t *to_push) {
UPDATE_VEHICLE_SPEED(speed / 4.0 * 0.01 / 3.6);
}

// most cars have brake_pressed on 0x226, corolla and rav4 on 0x224, secoc on 0x101
if (!toyota_alt_brake && !toyota_secoc && (addr == 0x226)) {
brake_pressed = GET_BIT(to_push, 37U);
}
if (toyota_alt_brake && !toyota_secoc && (addr == 0x224)) {
brake_pressed = GET_BIT(to_push, 5U);
}
if (!toyota_alt_brake && toyota_secoc && (addr == 0x101)) {
brake_pressed = GET_BIT(to_push, 3U);
}

bool stock_ecu_detected = addr == 0x2E4; // STEERING_LKA
if (!toyota_stock_longitudinal && (addr == 0x343)) {
stock_ecu_detected = true; // ACC_CONTROL
Expand Down

0 comments on commit 25e1fbc

Please sign in to comment.