diff --git a/board/safety/safety_gm.h b/board/safety/safety_gm.h index ad3a958eb..b703f4721 100644 --- a/board/safety/safety_gm.h +++ b/board/safety/safety_gm.h @@ -105,9 +105,9 @@ static int gm_rx_hook(CANPacket_t *to_push) { if ((addr == 481) && !gm_pcm_cruise) { int button = (GET_BYTE(to_push, 5) & 0x70U) >> 4; - // enter controls on falling edge of set or resume + // enter controls on falling edge of set or rising edge of resume (avoids fault) bool set = (button != GM_BTN_SET) && (cruise_button_prev == GM_BTN_SET); - bool res = (button != GM_BTN_RESUME) && (cruise_button_prev == GM_BTN_RESUME); + bool res = (button == GM_BTN_RESUME) && (cruise_button_prev != GM_BTN_RESUME); if (set || res) { controls_allowed = 1; } diff --git a/tests/safety/test_gm.py b/tests/safety/test_gm.py index 5ee94d801..983b1670e 100755 --- a/tests/safety/test_gm.py +++ b/tests/safety/test_gm.py @@ -21,23 +21,20 @@ class GmLongitudinalBase(common.PandaSafetyTest): def test_set_resume_buttons(self): """ - SET and RESUME enter controls allowed on their falling edge. + SET and RESUME enter controls allowed on their falling and rising edges, respectively. """ for btn_prev in range(8): for btn_cur in range(8): - self._rx(self._button_msg(Buttons.UNPRESS)) - self.safety.set_controls_allowed(0) - for _ in range(10): + with self.subTest(btn_prev=btn_prev, btn_cur=btn_cur): self._rx(self._button_msg(btn_prev)) - self.assertFalse(self.safety.get_controls_allowed()) + self.safety.set_controls_allowed(0) + for _ in range(10): + self._rx(self._button_msg(btn_cur)) - # should enter controls allowed on falling edge and not transitioning to cancel - should_enable = btn_cur != btn_prev and \ - btn_cur != Buttons.CANCEL and \ - btn_prev in (Buttons.RES_ACCEL, Buttons.DECEL_SET) - - self._rx(self._button_msg(btn_cur)) - self.assertEqual(should_enable, self.safety.get_controls_allowed()) + should_enable = btn_cur != Buttons.DECEL_SET and btn_prev == Buttons.DECEL_SET + should_enable = should_enable or (btn_cur == Buttons.RES_ACCEL and btn_prev != Buttons.RES_ACCEL) + should_enable = should_enable and btn_cur != Buttons.CANCEL + self.assertEqual(should_enable, self.safety.get_controls_allowed()) def test_cancel_button(self): self.safety.set_controls_allowed(1)