diff --git a/selfdrive/ui/qt/home.cc b/selfdrive/ui/qt/home.cc index b674d39fbd..f5eab4664e 100644 --- a/selfdrive/ui/qt/home.cc +++ b/selfdrive/ui/qt/home.cc @@ -158,8 +158,8 @@ OffroadHome::OffroadHome(QWidget* parent) : QFrame(parent) { left_widget->setStyleSheet("border-radius: 10px;"); left_widget->setCurrentIndex(uiState()->primeType() ? 0 : 1); - connect(uiState(), &UIState::primeTypeChanged, [=](int prime_type) { - left_widget->setCurrentIndex(prime_type ? 0 : 1); + connect(uiState(), &UIState::primeTypeChanged, [=](PrimeType prime_type) { + left_widget->setCurrentIndex((prime_type != PrimeType::NONE) ? 0 : 1); }); home_layout->addWidget(left_widget, 1); diff --git a/selfdrive/ui/qt/offroad/networking.cc b/selfdrive/ui/qt/offroad/networking.cc index 628a92fb58..0a5c07af70 100644 --- a/selfdrive/ui/qt/offroad/networking.cc +++ b/selfdrive/ui/qt/offroad/networking.cc @@ -10,7 +10,6 @@ #include "selfdrive/ui/qt/qt_window.h" #include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/widgets/controls.h" -#include "selfdrive/ui/qt/widgets/prime.h" #include "selfdrive/ui/qt/widgets/scrollview.h" @@ -184,7 +183,7 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid // Set initial config wifi->updateGsmSettings(roamingEnabled, QString::fromStdString(params.get("GsmApn")), metered); - connect(uiState(), &UIState::primeTypeChanged, this, [=](int prime_type) { + connect(uiState(), &UIState::primeTypeChanged, this, [=](PrimeType prime_type) { bool gsmVisible = prime_type == PrimeType::NONE || prime_type == PrimeType::LITE; roamingToggle->setVisible(gsmVisible); editApnButton->setVisible(gsmVisible); diff --git a/selfdrive/ui/qt/widgets/prime.cc b/selfdrive/ui/qt/widgets/prime.cc index afc6bd898e..57d9d87a64 100644 --- a/selfdrive/ui/qt/widgets/prime.cc +++ b/selfdrive/ui/qt/widgets/prime.cc @@ -269,7 +269,7 @@ void SetupWidget::replyFinished(const QString &response, bool success) { } QJsonObject json = doc.object(); - int prime_type = json["prime_type"].toInt(); + PrimeType prime_type = static_cast(json["prime_type"].toInt()); uiState()->setPrimeType(prime_type); if (!json["is_paired"].toBool()) { diff --git a/selfdrive/ui/qt/widgets/prime.h b/selfdrive/ui/qt/widgets/prime.h index b41bab1695..227a0f31c1 100644 --- a/selfdrive/ui/qt/widgets/prime.h +++ b/selfdrive/ui/qt/widgets/prime.h @@ -7,15 +7,6 @@ #include "selfdrive/ui/qt/widgets/input.h" -enum PrimeType { - NONE = 0, - MAGENTA = 1, - LITE = 2, - BLUE = 3, - MAGENTA_NEW = 4, -}; - - // pairing QR code class PairingQRWidget : public QWidget { Q_OBJECT diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 26e8464a61..7b12d54888 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -245,8 +245,11 @@ UIState::UIState(QObject *parent) : QObject(parent) { }); Params params; - prime_type = std::atoi(params.get("PrimeType").c_str()); language = QString::fromStdString(params.get("LanguageSetting")); + auto prime_value = params.get("PrimeType"); + if (!prime_value.empty()) { + prime_type = static_cast(std::atoi(prime_value.c_str())); + } // update timer timer = new QTimer(this); @@ -265,7 +268,7 @@ void UIState::update() { emit uiUpdate(*this); } -void UIState::setPrimeType(int type) { +void UIState::setPrimeType(PrimeType type) { if (type != prime_type) { prime_type = type; Params().put("PrimeType", std::to_string(prime_type)); diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 82f65d128f..cac8995278 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -96,6 +96,15 @@ typedef enum UIStatus { STATUS_ENGAGED, } UIStatus; +enum PrimeType { + UNKNOWN = -1, + NONE = 0, + MAGENTA = 1, + LITE = 2, + BLUE = 3, + MAGENTA_NEW = 4, +}; + const QColor bg_colors [] = { [STATUS_DISENGAGED] = QColor(0x17, 0x33, 0x49, 0xc8), [STATUS_OVERRIDE] = QColor(0x91, 0x9b, 0x95, 0xf1), @@ -153,8 +162,8 @@ public: return scene.started && (*sm)["controlsState"].getControlsState().getEnabled(); } - void setPrimeType(int type); - inline int primeType() const { return prime_type; } + void setPrimeType(PrimeType type); + inline PrimeType primeType() const { return prime_type; } int fb_w = 0, fb_h = 0; @@ -170,7 +179,7 @@ public: signals: void uiUpdate(const UIState &s); void offroadTransition(bool offroad); - void primeTypeChanged(int prime_type); + void primeTypeChanged(PrimeType prime_type); private slots: void update(); @@ -178,7 +187,7 @@ private slots: private: QTimer *timer; bool started_prev = false; - int prime_type = -1; + PrimeType prime_type = PrimeType::UNKNOWN; }; UIState *uiState();