diff --git a/panda/board/safety/safety_hyundai_canfd.h b/panda/board/safety/safety_hyundai_canfd.h index 1861714..e2cc658 100644 --- a/panda/board/safety/safety_hyundai_canfd.h +++ b/panda/board/safety/safety_hyundai_canfd.h @@ -21,12 +21,14 @@ const SteeringLimits HYUNDAI_CANFD_STEERING_LIMITS = { const CanMsg HYUNDAI_CANFD_HDA2_TX_MSGS[] = { {0x50, 0, 16}, // LKAS {0x1CF, 1, 8}, // CRUISE_BUTTON + {426, 1, 16}, // CRUISE_BUTTON_ALT (clearpilot) {0x2A4, 0, 24}, // CAM_0x2A4 }; const CanMsg HYUNDAI_CANFD_HDA2_ALT_STEERING_TX_MSGS[] = { {0x110, 0, 32}, // LKAS_ALT {0x1CF, 1, 8}, // CRUISE_BUTTON + {426, 1, 16}, // CRUISE_BUTTONS_ALT (clearpilot) {0x362, 0, 32}, // CAM_0x362 }; @@ -249,7 +251,7 @@ static bool hyundai_canfd_tx_hook(const CANPacket_t *to_send) { int button = GET_BYTE(to_send, 2) & 0x7U; bool is_cancel = (button == HYUNDAI_BTN_CANCEL); bool is_resume = (button == HYUNDAI_BTN_RESUME); - bool is_set_decel = (button == 2); + bool is_set_decel = (button == HYUNDAI_BTN_SET); // bool allowed = (is_cancel && cruise_engaged_prev) // Todo: allow is_cancel anytime speed > 0 on cruiseState @@ -262,6 +264,25 @@ static bool hyundai_canfd_tx_hook(const CANPacket_t *to_send) { } } + // CRUISE_BUTTONS_ALT + // if (addr == 426) { + // // this gets bit 16 we want bit 36 + // int button = GET_BYTE(to_send, 2) & 0x7byteU; + // bool is_cancel = (button == HYUNDAI_BTN_CANCEL); + // bool is_resume = (button == HYUNDAI_BTN_RESUME); + // bool is_set_decel = (button == HYUNDAI_BTN_SET); + // // Canfd doc says there is a value 4 button allowed for canfd too, which one is it? + // // bool allowed = (is_cancel && cruise_engaged_prev) + // // Todo: allow is_cancel anytime speed > 0 on cruiseState + // bool allowed = (is_cancel) + // || (is_resume && controls_allowed) + // || (is_set_decel && controls_allowed); + + // if (!allowed) { + // tx = false; + // } + // } + // CLEARPILOT - Allow DRIVE_MODE2 // if (addr == 1144) { // } diff --git a/selfdrive/car/hyundai/carcontroller.py b/selfdrive/car/hyundai/carcontroller.py index 5f5d2d7..e9e1fa2 100644 --- a/selfdrive/car/hyundai/carcontroller.py +++ b/selfdrive/car/hyundai/carcontroller.py @@ -198,7 +198,7 @@ class CarController(CarControllerBase): if (self.frame - self.last_button_frame) * DT_CTRL > 0.25: # cruise cancel if CC.cruiseControl.cancel: - if False and self.CP.flags & HyundaiFlags.CANFD_ALT_BUTTONS: + if self.CP.flags & HyundaiFlags.CANFD_ALT_BUTTONS: can_sends.append(hyundaicanfd.create_acc_cancel(self.packer, self.CP, self.CAN, CS.cruise_info)) self.last_button_frame = self.frame CS.lkas_trigger_result = 1 diff --git a/selfdrive/car/hyundai/hyundaicanfd.py b/selfdrive/car/hyundai/hyundaicanfd.py index ca43349..5af3a55 100644 --- a/selfdrive/car/hyundai/hyundaicanfd.py +++ b/selfdrive/car/hyundai/hyundaicanfd.py @@ -83,6 +83,16 @@ def create_buttons(packer, CP, CAN, cnt, btn): bus = CAN.ECAN if CP.flags & HyundaiFlags.CANFD_HDA2 else CAN.CAM return packer.make_can_msg("CRUISE_BUTTONS", bus, values) +# def create_buttons_alt(packer, CP, CAN, cnt, btn): +# values = { +# "COUNTER": cnt, +# "SET_ME_1": 1, +# "CRUISE_BUTTONS": btn, +# } + +# bus = CAN.ECAN if CP.flags & HyundaiFlags.CANFD_HDA2 else CAN.CAM +# return packer.make_can_msg("CRUISE_BUTTONS_ALT", bus, values) + def create_acc_cancel(packer, CP, CAN, cruise_info_copy): # TODO: why do we copy different values here? if CP.flags & HyundaiFlags.CANFD_CAMERA_SCC.value: