GM: abstract PCM-related hw check (#1090)

abstract hw check to if pcm_cruise or not
This commit is contained in:
Shane Smiskol 2022-10-09 12:39:48 -07:00 committed by GitHub
parent 1303af2db2
commit ca11326bd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -51,6 +51,7 @@ enum {
};
enum {GM_ASCM, GM_CAM} gm_hw = GM_ASCM;
bool gm_pcm_cruise = false;
static int gm_rx_hook(CANPacket_t *to_push) {
@ -73,7 +74,7 @@ static int gm_rx_hook(CANPacket_t *to_push) {
}
// ACC steering wheel buttons (GM_CAM is tied to the PCM)
if ((addr == 481) && (gm_hw == GM_ASCM)) {
if ((addr == 481) && !gm_pcm_cruise) {
int button = (GET_BYTE(to_push, 5) & 0x70U) >> 4;
// exit controls on cancel press
@ -101,7 +102,7 @@ static int gm_rx_hook(CANPacket_t *to_push) {
gas_pressed = GET_BYTE(to_push, 5) != 0U;
// enter controls on rising edge of ACC, exit controls when ACC off
if (gm_hw == GM_CAM) {
if (gm_pcm_cruise) {
bool cruise_engaged = (GET_BYTE(to_push, 1) >> 5) != 0U;
pcm_cruise_check(cruise_engaged);
}
@ -234,7 +235,7 @@ static int gm_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {
}
// BUTTONS: used for resume spamming and cruise cancellation with stock longitudinal
if ((addr == 481) && (gm_hw == GM_CAM)) {
if ((addr == 481) && gm_pcm_cruise) {
int button = (GET_BYTE(to_send, 5) >> 4) & 0x7U;
bool allowed_cancel = (button == 6) && cruise_engaged_prev;
@ -271,6 +272,7 @@ static int gm_fwd_hook(int bus_num, CANPacket_t *to_fwd) {
static const addr_checks* gm_init(uint16_t param) {
gm_hw = GET_FLAG(param, GM_PARAM_HW_CAM) ? GM_CAM : GM_ASCM;
gm_pcm_cruise = gm_hw == GM_CAM;
return &gm_rx_checks;
}