208 lines
7.0 KiB
Python
208 lines
7.0 KiB
Python
"""
|
|
Copyright © IQ.Lvbs, apart of Project Teal Lvbs, All Rights Reserved, licensed under https://konn3kt.com/tos/
|
|
"""
|
|
|
|
def create_hca_steering_control(packer, bus, apply_torque, HCA_Status):
|
|
values = {
|
|
"LM_Offset": abs(apply_torque),
|
|
"LM_OffSign": 1 if apply_torque < 0 else 0,
|
|
"HCA_Status": HCA_Status,
|
|
"Vib_Freq": 16,
|
|
}
|
|
|
|
return packer.make_can_msg("HCA_1", bus, values)
|
|
|
|
def create_lka_hud_control(packer, bus, ldw_stock_values, lat_active, steering_pressed, hud_alert, hud_control, entering, special_mode, special_active):
|
|
values = {}
|
|
if len(ldw_stock_values):
|
|
values = {s: ldw_stock_values[s] for s in [
|
|
"LDW_SW_Warnung_links", # Blind spot in warning mode on left side due to lane departure
|
|
"LDW_SW_Warnung_rechts", # Blind spot in warning mode on right side due to lane departure
|
|
"LDW_Seite_DLCTLC", # Direction of most likely lane departure (left or right)
|
|
"LDW_DLC", # Lane departure, distance to line crossing
|
|
"LDW_TLC", # Lane departure, time to line crossing
|
|
]}
|
|
|
|
if entering:
|
|
yellow_led = int(steering_pressed)
|
|
green_led = int(not steering_pressed)
|
|
elif special_mode:
|
|
yellow_led = 1 if (lat_active and (steering_pressed or not special_active)) or not lat_active else 0
|
|
green_led = 1 if lat_active and special_active and not steering_pressed else 0
|
|
else:
|
|
yellow_led = 1 if (lat_active and steering_pressed) or not lat_active else 0
|
|
green_led = 1 if lat_active and not steering_pressed else 0
|
|
|
|
values.update({
|
|
"LDW_Kameratyp": 1,
|
|
"LDW_Lampe_gelb": yellow_led,
|
|
"LDW_Lampe_gruen": green_led,
|
|
"LDW_Lernmodus_links": 3 if hud_control.leftLaneDepart else 1 + hud_control.leftLaneVisible,
|
|
"LDW_Lernmodus_rechts": 3 if hud_control.rightLaneDepart else 1 + hud_control.rightLaneVisible,
|
|
"LDW_Textbits": hud_alert,
|
|
})
|
|
|
|
return packer.make_can_msg("LDW_Status", bus, values)
|
|
|
|
|
|
def create_acc_buttons_control(packer, bus, gra_stock_values, cancel=False, resume=False, set_button=False):
|
|
values = {s: gra_stock_values[s] for s in [
|
|
"GRA_Hauptschalt", # ACC button, on/off
|
|
"GRA_Typ_Hauptschalt", # ACC button, momentary vs latching
|
|
"GRA_Kodierinfo", # ACC button, configuration
|
|
"GRA_Sender", # ACC button, CAN message originator
|
|
]}
|
|
|
|
values.update({
|
|
"COUNTER": (gra_stock_values["COUNTER"] + 1) % 16,
|
|
"GRA_Abbrechen": cancel,
|
|
"GRA_Recall": resume,
|
|
"GRA_Neu_Setzen": set_button,
|
|
})
|
|
|
|
return packer.make_can_msg("GRA_Neu", bus, values)
|
|
|
|
def create_gra_neu(packer, bus, gra_stock, longActive):
|
|
values = gra_stock.copy()
|
|
if longActive:
|
|
values.update({
|
|
"GRA_Neu_Setzen": 0,
|
|
"GRA_Recall": 0,
|
|
"GRA_Hauptschalt": 0,
|
|
})
|
|
return packer.make_can_msg("GRA_Neu", bus, values)
|
|
|
|
def acc_control_value(main_switch_on, long_active, cruiseOverride, accFaulted):
|
|
if long_active or cruiseOverride:
|
|
acc_control = 1
|
|
elif accFaulted:
|
|
acc_control = 3
|
|
elif main_switch_on:
|
|
acc_control = 2
|
|
else:
|
|
acc_control = 0
|
|
|
|
return acc_control
|
|
|
|
def acc_hud_status_value(main_switch_on, acc_faulted, longActive, longOverride):
|
|
if longOverride:
|
|
hud_status = 4
|
|
elif longActive:
|
|
hud_status = 3
|
|
elif acc_faulted:
|
|
hud_status = 6
|
|
elif main_switch_on:
|
|
hud_status = 2
|
|
else:
|
|
hud_status = 0
|
|
|
|
return hud_status
|
|
|
|
|
|
def create_acc_accel_control(packer, bus, acc_type, accel, acc_control, stopping, starting, esp_hold, comfortBand, jerkLimit, eBrakeActive, sng_active=False):
|
|
commands = []
|
|
acc_enabled = acc_control == 1 and not sng_active
|
|
|
|
values = {
|
|
"ACS_Sta_ADR": 0 if sng_active else acc_control,
|
|
"ACS_StSt_Info": acc_enabled,
|
|
"ACS_Typ_ACC": acc_type,
|
|
"ACS_Anhaltewunsch": (acc_type == 1 and stopping or eBrakeActive) or sng_active,
|
|
"ACS_FreigSollB": acc_enabled,
|
|
"ACS_Sollbeschl": accel if acc_enabled else 3.01,
|
|
"ACS_zul_Regelabw": comfortBand if acc_enabled else 1.27,
|
|
"ACS_max_AendGrad": jerkLimit if acc_enabled else 5.08,
|
|
"ACS_Schubabsch": 1 if acc_enabled and accel > 0.05 else 0,
|
|
"ACS_MomEingriff": 0,
|
|
"ACS_ADR_Schub": 0,
|
|
}
|
|
|
|
commands.append(packer.make_can_msg("ACC_System", bus, values))
|
|
|
|
return commands
|
|
|
|
|
|
def create_sng_handoff_control(packer, bus, handoff_active, decel_req):
|
|
values = {
|
|
"SNG_HandoffActive": handoff_active,
|
|
"SNG_DecelReq": decel_req if handoff_active else 0.0,
|
|
}
|
|
return packer.make_can_msg("SNG_1", bus, values)
|
|
|
|
|
|
def create_blinker_control(packer, bus, leftBlinker, rightBlinker):
|
|
values = {
|
|
"BM_rechts": rightBlinker,
|
|
"BM_links": leftBlinker,
|
|
}
|
|
return packer.make_can_msg("Blinkmodi_02", bus, values)
|
|
|
|
|
|
def create_acc_hud_control(packer, bus, acc_hud_status, set_speed, leadDistance, distanceBars, fcw_alert, leadVisible, unavailable, decel, d_unresponsive):
|
|
priodisp = 0 if fcw_alert else 0 if (acc_hud_status == 4 or decel) else 2 if (acc_hud_status in (3, 2) or leadVisible) else 0
|
|
leadDistanceBars = distanceBars + 1 if distanceBars in (1, 2, 3) else 2
|
|
values = {
|
|
"ACA_StaACC": acc_hud_status,
|
|
"ACA_AnzDisplay": 1 if acc_hud_status in (3, 4) else 0,
|
|
"ACA_Zeitluecke": leadDistanceBars,
|
|
"ACA_V_Wunsch": set_speed,
|
|
"ACA_gemZeitl": min(15, max(1, int(round(leadDistance)))) if leadVisible else 0,
|
|
"ACA_PrioDisp": priodisp,
|
|
"ACA_Akustik1": d_unresponsive,
|
|
"ACA_Akustik2": fcw_alert,
|
|
"ACA_ACC_Verz": decel,
|
|
}
|
|
|
|
return packer.make_can_msg("ACC_GRA_Anzeige", bus, values)
|
|
|
|
def filter_motor2(packer, bus, motor2_stock, gra_active=False):
|
|
values = dict(motor2_stock)
|
|
if gra_active:
|
|
values.update({
|
|
"MO2_Sta_GRA": 1,
|
|
"MO2_Status_TSK": 1,
|
|
})
|
|
else:
|
|
values.update({
|
|
"MO2_Sta_GRA": 0,
|
|
})
|
|
return packer.make_can_msg("Motor_2", bus, values)
|
|
|
|
|
|
def filter_motor5(packer, bus, motor5_stock, gra_active=False):
|
|
values = dict(motor5_stock)
|
|
if gra_active:
|
|
values["MO5_GRA_Hauptsch"] = 1
|
|
return packer.make_can_msg("Motor_5", bus, values)
|
|
|
|
|
|
def create_motor3_resume(packer, bus, motor1_stock, motor3_stock, resume=False):
|
|
values = dict(motor3_stock)
|
|
values_motor1 = dict(motor1_stock)
|
|
if resume:
|
|
values["MO3_Pedalwert"] = values_motor1["MO1_Pedalwert"]
|
|
return packer.make_can_msg("Motor_3", bus, values)
|
|
|
|
|
|
def create_radar_gra(packer, bus, gra_stock, counter, set_btn=False, cancel=False, resume=False,
|
|
up_short=False, down_short=False, up_long=False, down_long=False, zeitluecke=None):
|
|
values = {s: gra_stock[s] for s in [
|
|
"GRA_Hauptschalt", # ACC main switch passthrough
|
|
"GRA_Typ_Hauptschalt", # momentary vs latching
|
|
"GRA_Kodierinfo", # configuration
|
|
"GRA_Sender", # CAN originator
|
|
]}
|
|
values.update({
|
|
"COUNTER": counter % 16,
|
|
"GRA_Neu_Setzen": 1 if set_btn else 0,
|
|
"GRA_Abbrechen": 1 if cancel else 0,
|
|
"GRA_Recall": 1 if resume else 0,
|
|
"GRA_Up_kurz": 1 if up_short else 0,
|
|
"GRA_Down_kurz": 1 if down_short else 0,
|
|
"GRA_Up_lang": 1 if up_long else 0,
|
|
"GRA_Down_lang": 1 if down_long else 0,
|
|
})
|
|
if zeitluecke is not None:
|
|
values["GRA_Zeitluecke"] = zeitluecke
|
|
return packer.make_can_msg("GRA_Neu", bus, values)
|