mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-24 12:02:07 +08:00
ui: Platform Selector updates (#897)
* init * more * description * init them to true * back to false * fix * add description update colors fix stretch * yellow & orange are too similar - use blue * slight updates * dynamic description * split it out * more --------- Co-authored-by: nayan8teen <nayan8teen@gmail.com>
This commit is contained in:
@@ -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<cereal::CarParams>();
|
||||
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("<b>%1</b><br><br>%2")
|
||||
.arg(platform, offroad_msg);
|
||||
.arg(_platform, offroad_msg);
|
||||
|
||||
QString content("<body><h2 style=\"text-align: center;\">" + tr("Vehicle Selector") + "</h2><br>"
|
||||
"<p style=\"text-align: center; margin: 0 128px; font-size: 50px;\">" + msg + "</p></body>");
|
||||
@@ -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();
|
||||
|
||||
@@ -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 = "<font color='white'><b>" + auto_str + "</b></font>";
|
||||
} else if (status == FingerprintStatus::MANUAL_FINGERPRINT) {
|
||||
manual_str = "<font color='white'><b>" + manual_str + "</b></font>";
|
||||
} else {
|
||||
unrecognized_str = "<font color='white'><b>" + unrecognized_str + "</b></font>";
|
||||
}
|
||||
|
||||
return QString("%1<br>%2<br><br>%3<br>%4<br>%5")
|
||||
.arg(tr("Select vehicle to force fingerprint manually."))
|
||||
.arg(tr("Colors represent fingerprint status:"))
|
||||
.arg(auto_str)
|
||||
.arg(manual_str)
|
||||
.arg(unrecognized_str);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user