diff --git a/board/safety/safety_toyota.h b/board/safety/safety_toyota.h index 7841ab71e2..0ce40bbde1 100644 --- a/board/safety/safety_toyota.h +++ b/board/safety/safety_toyota.h @@ -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 @@ -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