some dynamic checks

This commit is contained in:
Jason Wen
2025-05-19 06:35:58 -04:00
parent 0bd603c2f8
commit 607c11e86d
2 changed files with 46 additions and 24 deletions
@@ -21,22 +21,11 @@ MadsSettings::MadsSettings(QWidget *parent) : QWidget(parent) {
ListWidget *list = new ListWidget(this, false);
// Main cruise
madsMainCruiseToggle = new ParamControl(
"MadsMainCruiseAllowed",
tr("Toggle with Main Cruise"),
tr("Note: For vehicles without LFA/LKAS button, disabling this will prevent lateral control engagement."),
"");
madsMainCruiseToggle = new ParamControl("MadsMainCruiseAllowed", tr("Toggle with Main Cruise"), "", "");
list->addItem(madsMainCruiseToggle);
// Unified Engagement Mode
madsUnifiedEngagementModeToggle = new ParamControl(
"MadsUnifiedEngagementMode",
tr("Unified Engagement Mode (UEM)"),
QString("%1<br>"
"<h4>%2</h4>")
.arg(tr("Engage lateral and longitudinal control with cruise control engagement."))
.arg(tr("Note: Once lateral control is engaged via UEM, it will remain engaged until it is manually disabled via the MADS button or car shut off.")),
"");
madsUnifiedEngagementModeToggle = new ParamControl("MadsUnifiedEngagementMode", tr("Unified Engagement Mode (UEM)"), "", "");
list->addItem(madsUnifiedEngagementModeToggle);
// Steering Mode On Brake
@@ -45,7 +34,6 @@ MadsSettings::MadsSettings(QWidget *parent) : QWidget(parent) {
updateToggles(offroad);
});
list->addItem(madsSteeringMode);
madsSteeringMode->showDescription();
QObject::connect(uiState(), &UIState::offroadTransition, this, &MadsSettings::updateToggles);
@@ -70,14 +58,41 @@ void MadsSettings::updateToggles(bool _offroad) {
cereal::CarParams::Reader CP = cmsg.getRoot<cereal::CarParams>();
if (CP.getBrand() == "rivian" || CP.getBrand() == "tesla") {
params.remove("MadsMainCruiseAllowed");
params.putBool("MadsUnifiedEngagementMode", true);
params.put("MadsSteeringMode", std::to_string(static_cast<int>(MadsSteeringMode::DISENGAGE)));
madsMainCruiseToggle->setEnabled(false);
madsMainCruiseToggle->setDescription(madsDescriptionBuilder(DEFAULT_TO_OFF, MADS_MAIN_CRUISE_BASE_DESC));
madsMainCruiseToggle->showDescription();
madsUnifiedEngagementModeToggle->setEnabled(false);
madsUnifiedEngagementModeToggle->setDescription(madsDescriptionBuilder(DEFAULT_TO_ON, MADS_UNIFIED_ENGAGEMENT_MODE_BASE_DESC));
madsUnifiedEngagementModeToggle->showDescription();
madsSteeringModeValues = convertMadsSteeringModeValues({MadsSteeringMode::DISENGAGE});
madsSteeringMode->setDescription(madsSteeringModeDescriptionBuilder(STATUS_DISENGAGE_ONLY, madsSteeringModeDescription(steering_mode)));
madsSteeringMode->setDescription(madsDescriptionBuilder(STATUS_DISENGAGE_ONLY, madsSteeringModeDescription(steering_mode)));
} else {
madsMainCruiseToggle->setEnabled(true);
madsMainCruiseToggle->setDescription(MADS_MAIN_CRUISE_BASE_DESC);
madsUnifiedEngagementModeToggle->setEnabled(true);
madsUnifiedEngagementModeToggle->setDescription(MADS_UNIFIED_ENGAGEMENT_MODE_BASE_DESC);
madsSteeringModeValues = convertMadsSteeringModeValues(getMadsSteeringModeValues());
madsSteeringMode->setDescription(madsSteeringModeDescription(steering_mode));
}
} else {
madsSteeringMode->setDescription(madsSteeringModeDescriptionBuilder(STATUS_CHECK_COMPATIBILITY, madsSteeringModeDescription(steering_mode)));
madsMainCruiseToggle->setEnabled(false);
madsMainCruiseToggle->setDescription(madsDescriptionBuilder(STATUS_CHECK_COMPATIBILITY, MADS_MAIN_CRUISE_BASE_DESC));
madsMainCruiseToggle->showDescription();
madsUnifiedEngagementModeToggle->setEnabled(false);
madsUnifiedEngagementModeToggle->setDescription(madsDescriptionBuilder(STATUS_CHECK_COMPATIBILITY, MADS_UNIFIED_ENGAGEMENT_MODE_BASE_DESC));
madsUnifiedEngagementModeToggle->showDescription();
madsSteeringModeValues = {};
madsSteeringMode->setDescription(madsDescriptionBuilder(STATUS_CHECK_COMPATIBILITY, madsSteeringModeDescription(steering_mode)));
}
madsSteeringMode->setEnableSelectedButtons(_offroad, madsSteeringModeValues);
@@ -46,10 +46,17 @@ private:
ParamControl *madsUnifiedEngagementModeToggle;
ButtonParamControl *madsSteeringMode;
std::vector<int> madsSteeringModeValues = getMadsSteeringModeValues();
std::vector<int> madsSteeringModeValues = {};
const QString STATUS_CHECK_COMPATIBILITY = tr("Start the car to check car compatibility.");
const QString STATUS_DISENGAGE_ONLY = tr("This platform only supports Disengage mode due to car limitations.");
const QString MADS_MAIN_CRUISE_BASE_DESC = tr("Note: For vehicles without LFA/LKAS button, disabling this will prevent lateral control engagement.");
const QString MADS_UNIFIED_ENGAGEMENT_MODE_BASE_DESC = QString("%1<br>""<h4>%2</h4>")
.arg(tr("Engage lateral and longitudinal control with cruise control engagement."))
.arg(tr("Note: Once lateral control is engaged via UEM, it will remain engaged until it is manually disabled via the MADS button or car shut off."));
const QString STATUS_CHECK_COMPATIBILITY = tr("Start the vehicle to check vehicle compatibility.");
const QString DEFAULT_TO_OFF = tr("This feature defaults to OFF, and does not allow selection due to vehicle limitations.");
const QString DEFAULT_TO_ON = tr("This feature defaults to ON, and does not allow selection due to vehicle limitations.");
const QString STATUS_DISENGAGE_ONLY = tr("This platform only supports Disengage mode due to vehicle limitations.");
static const std::vector<MadsSteeringModeOption> &madsSteeringModeOptions() {
static const std::vector<MadsSteeringModeOption> options = {
@@ -60,10 +67,10 @@ private:
return options;
}
static std::vector<int> getMadsSteeringModeValues() {
std::vector<int> values;
static std::vector<MadsSteeringMode> getMadsSteeringModeValues() {
std::vector<MadsSteeringMode> values;
for (const auto& option : madsSteeringModeOptions()) {
values.push_back(static_cast<int>(option.mode));
values.push_back(option.mode);
}
return values;
}
@@ -99,7 +106,7 @@ private:
return result;
}
static QString madsSteeringModeDescriptionBuilder(const QString &custom_description, const QString &madsSteeringModeDescription) {
return "<font color='white'><b>" + custom_description + "</b></font><br><br>" + madsSteeringModeDescription;
static QString madsDescriptionBuilder(const QString &custom_description, const QString &base_description) {
return "<font color='white'><b>" + custom_description + "</b></font><br><br>" + base_description;
}
};