GM: enable on rising edge of resume (#1157)

* rising edge of resume

* fix test

* comment

* todo fix tests

* fix test

* we want to test the transition from btn prev to btn cur, not unpressed to x to y

* range
This commit is contained in:
Shane Smiskol
2022-11-13 19:10:45 -08:00
committed by GitHub
parent 0096d0c4fc
commit c0632cd32b
2 changed files with 11 additions and 14 deletions

View File

@@ -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;
}

View File

@@ -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)