diff --git a/board/safety.h b/board/safety.h index 4ec9c73aa..8760d1129 100644 --- a/board/safety.h +++ b/board/safety.h @@ -695,6 +695,20 @@ bool steer_angle_cmd_checks(int desired_angle, bool steer_control_enabled, const return violation; } +bool button_checks(bool resume_pressed, bool set_pressed, bool cancel_pressed, bool pcm_cruise) { + UNUSED(pcm_cruise); + UNUSED(set_pressed); // todo: this should never be sent + + bool allowed_cancel = cancel_pressed && cruise_engaged_prev; + bool allowed_resume = resume_pressed && controls_allowed; + + bool violation = false; + if (!(allowed_resume || allowed_cancel)) { + violation = true; + } + return violation; +} + void pcm_cruise_check(bool cruise_engaged) { // Enter controls on rising edge of stock ACC, exit controls if stock ACC disengages if (!cruise_engaged) { diff --git a/board/safety/safety_ford.h b/board/safety/safety_ford.h index 95b81e2cc..f4b953742 100644 --- a/board/safety/safety_ford.h +++ b/board/safety/safety_ford.h @@ -296,13 +296,11 @@ static bool ford_tx_hook(CANPacket_t *to_send) { if (addr == FORD_Steering_Data_FD1) { // Violation if resume button is pressed while controls not allowed, or // if cancel button is pressed when cruise isn't engaged. - bool allowed_cancel = (GET_BIT(to_send, 8U) == 1U) && cruise_engaged_prev; - bool allowed_resume = (GET_BIT(to_send, 25U) == 1U) && controls_allowed; - - if (!(allowed_resume || allowed_cancel)) { + if (button_checks((GET_BIT(to_send, 25U) == 1U), false, (GET_BIT(to_send, 8U) == 1U), true)) { tx = 0; } + // bool violation = false; // violation |= (GET_BIT(to_send, 8U) == 1U) && !cruise_engaged_prev; // Signal: CcAslButtnCnclPress (cancel) // violation |= (GET_BIT(to_send, 25U) == 1U) && !controls_allowed; // Signal: CcAsllButtnResPress (resume) diff --git a/board/safety_declarations.h b/board/safety_declarations.h index 6584d42d2..1a1e39561 100644 --- a/board/safety_declarations.h +++ b/board/safety_declarations.h @@ -185,8 +185,8 @@ bool longitudinal_gas_checks(int desired_gas, const LongitudinalLimits limits); bool longitudinal_transmission_rpm_checks(int desired_transmission_rpm, const LongitudinalLimits limits); bool longitudinal_brake_checks(int desired_brake, const LongitudinalLimits limits); bool longitudinal_interceptor_checks(CANPacket_t *to_send); +bool button_checks(bool resume_pressed, bool set_pressed, bool cancel_pressed, bool pcm_cruise); void pcm_cruise_check(bool cruise_engaged); -void buttons_check(bool resume_pressed, bool set_pressed, bool cancel_pressed); typedef safety_config (*safety_hook_init)(uint16_t param); typedef void (*rx_hook)(CANPacket_t *to_push);