From d8b1588937524eb54315456f02000082c2c42a7b Mon Sep 17 00:00:00 2001 From: rbiasini Date: Thu, 13 Jun 2019 17:51:12 -0700 Subject: [PATCH] Reconcile panda pedal cancel logic for Toyota with controls (#698) --- panda/VERSION | 2 +- panda/board/safety/safety_toyota.h | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/panda/VERSION b/panda/VERSION index 23c38c2411..bb8edae97f 100644 --- a/panda/VERSION +++ b/panda/VERSION @@ -1 +1 @@ -v1.3.1 \ No newline at end of file +v1.3.2 \ No newline at end of file diff --git a/panda/board/safety/safety_toyota.h b/panda/board/safety/safety_toyota.h index 2c9e062f79..d0fd907857 100644 --- a/panda/board/safety/safety_toyota.h +++ b/panda/board/safety/safety_toyota.h @@ -53,16 +53,12 @@ static void toyota_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { if ((to_push->RIR>>21) == 0x1D2) { // 5th bit is CRUISE_ACTIVE int cruise_engaged = to_push->RDLR & 0x20; - // 4th bit is GAS_RELEASED - int gas = !(to_push->RDLR & 0x10); - if (!cruise_engaged || - (gas && !toyota_gas_prev && !gas_interceptor_detected && long_controls_allowed)) { + if (!cruise_engaged) { controls_allowed = 0; } else if (cruise_engaged && !toyota_cruise_engaged_last) { controls_allowed = 1; } toyota_cruise_engaged_last = cruise_engaged; - toyota_gas_prev = gas; } // exit controls on rising edge of gas press if interceptor (0x201) @@ -77,6 +73,15 @@ static void toyota_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { gas_interceptor_prev = gas_interceptor; } + // exit controls on rising edge of gas press + if ((to_push->RIR>>21) == 0x2C1) { + int gas = (to_push->RDHR >> 16) & 0xFF; + if ((gas > 0) && (toyota_gas_prev == 0) && !gas_interceptor_detected && long_controls_allowed) { + controls_allowed = 0; + } + toyota_gas_prev = gas; + } + int bus = (to_push->RDTR >> 4) & 0xF; // msgs are only on bus 2 if panda is connected to frc if (bus == 2) {