diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.cc b/selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.cc index 83fa0b1698..21c9a44cb4 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.cc +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.cc @@ -43,37 +43,74 @@ PlatformSelector::PlatformSelector() : ButtonControl(tr("Vehicle"), "", "") { } }); + main_layout->addStretch(0); refresh(offroad); } void PlatformSelector::refresh(bool _offroad) { QString name = getPlatformBundle("name").toString(); + platform = unrecognized_str; + QString platform_color = YELLOW_PLATFORM; + if (!name.isEmpty()) { - setValue(name); + platform = name; + platform_color = BLUE_PLATFORM; + brand = getPlatformBundle("brand").toString(); setText(tr("REMOVE")); } else { setText(tr("SEARCH")); + + platform = unrecognized_str; + brand = ""; auto cp_bytes = params.get("CarParamsPersistent"); if (!cp_bytes.empty()) { AlignedBuffer aligned_buf; capnp::FlatArrayMessageReader cmsg(aligned_buf.align(cp_bytes.data(), cp_bytes.size())); cereal::CarParams::Reader CP = cmsg.getRoot(); - setValue(QString::fromStdString(CP.getCarFingerprint().cStr())); + + platform = QString::fromStdString(CP.getCarFingerprint().cStr()); + + for (auto it = platforms.constBegin(); it != platforms.constEnd(); ++it) { + if (it.value()["platform"].toString() == platform) { + platform = it.key(); + brand = it.value()["brand"].toString(); + break; + } + } + + if (platform == "MOCK") { + platform = unrecognized_str; + } else { + platform_color = GREEN_PLATFORM; + } } } + setValue(platform, platform_color); setEnabled(true); emit refreshPanel(); offroad = _offroad; + + FingerprintStatus cur_status; + if (platform_color == GREEN_PLATFORM) { + cur_status = FingerprintStatus::AUTO_FINGERPRINT; + } else if (platform_color == BLUE_PLATFORM) { + cur_status = FingerprintStatus::MANUAL_FINGERPRINT; + } else { + cur_status = FingerprintStatus::UNRECOGNIZED; + } + + setDescription(platformDescription(cur_status)); + showDescription(); } -void PlatformSelector::setPlatform(const QString &platform) { - QVariantMap platform_data = platforms[platform]; +void PlatformSelector::setPlatform(const QString &_platform) { + QVariantMap platform_data = platforms[_platform]; const QString offroad_msg = offroad ? tr("This setting will take effect immediately.") : tr("This setting will take effect once the device enters offroad state."); const QString msg = QString("%1

%2") - .arg(platform, offroad_msg); + .arg(_platform, offroad_msg); QString content("

" + tr("Vehicle Selector") + "


" "

" + msg + "

"); @@ -81,7 +118,7 @@ void PlatformSelector::setPlatform(const QString &platform) { if (ConfirmationDialog(content, tr("Confirm"), tr("Cancel"), true, this).exec()) { QJsonObject json_bundle; json_bundle["platform"] = platform_data["platform"].toString(); - json_bundle["name"] = platform; + json_bundle["name"] = _platform; json_bundle["make"] = platform_data["make"].toString(); json_bundle["brand"] = platform_data["brand"].toString(); json_bundle["model"] = platform_data["model"].toString(); diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.h b/selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.h index 3d912f822c..9867371ef6 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.h +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.h @@ -9,6 +9,16 @@ #include "selfdrive/ui/sunnypilot/qt/offroad/settings/settings.h" +static const QString GREEN_PLATFORM = "#00F100"; +static const QString BLUE_PLATFORM = "#0086E9"; +static const QString YELLOW_PLATFORM = "#FFD500"; + +enum class FingerprintStatus { + AUTO_FINGERPRINT, + MANUAL_FINGERPRINT, + UNRECOGNIZED, +}; + class PlatformSelector : public ButtonControl { Q_OBJECT @@ -16,6 +26,9 @@ public: PlatformSelector(); QVariant getPlatformBundle(const QString &key); + QString platform; + QString brand; + public slots: void refresh(bool _offroad); @@ -29,4 +42,27 @@ private: Params params; bool offroad; + + QString unrecognized_str = tr("Unrecognized Vehicle"); + + static QString platformDescription(FingerprintStatus status = FingerprintStatus::UNRECOGNIZED) { + QString auto_str = "🟢 - " + tr("Fingerprinted automatically"); + QString manual_str = "🔵 - " + tr("Manually selected"); + QString unrecognized_str = "🟡 - " + tr("Not fingerprinted or manually selected"); + + if (status == FingerprintStatus::AUTO_FINGERPRINT) { + auto_str = "" + auto_str + ""; + } else if (status == FingerprintStatus::MANUAL_FINGERPRINT) { + manual_str = "" + manual_str + ""; + } else { + unrecognized_str = "" + unrecognized_str + ""; + } + + return QString("%1
%2

%3
%4
%5") + .arg(tr("Select vehicle to force fingerprint manually.")) + .arg(tr("Colors represent fingerprint status:")) + .arg(auto_str) + .arg(manual_str) + .arg(unrecognized_str); + } };