ui: use `enum PrimeType` for prime_type (#29491)

pull/29590/head
Dean Lee 2 years ago committed by GitHub
parent e38ce6087f
commit 99279b8eef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      selfdrive/ui/qt/home.cc
  2. 3
      selfdrive/ui/qt/offroad/networking.cc
  3. 2
      selfdrive/ui/qt/widgets/prime.cc
  4. 9
      selfdrive/ui/qt/widgets/prime.h
  5. 7
      selfdrive/ui/ui.cc
  6. 17
      selfdrive/ui/ui.h

@ -158,8 +158,8 @@ OffroadHome::OffroadHome(QWidget* parent) : QFrame(parent) {
left_widget->setStyleSheet("border-radius: 10px;"); left_widget->setStyleSheet("border-radius: 10px;");
left_widget->setCurrentIndex(uiState()->primeType() ? 0 : 1); left_widget->setCurrentIndex(uiState()->primeType() ? 0 : 1);
connect(uiState(), &UIState::primeTypeChanged, [=](int prime_type) { connect(uiState(), &UIState::primeTypeChanged, [=](PrimeType prime_type) {
left_widget->setCurrentIndex(prime_type ? 0 : 1); left_widget->setCurrentIndex((prime_type != PrimeType::NONE) ? 0 : 1);
}); });
home_layout->addWidget(left_widget, 1); home_layout->addWidget(left_widget, 1);

@ -10,7 +10,6 @@
#include "selfdrive/ui/qt/qt_window.h" #include "selfdrive/ui/qt/qt_window.h"
#include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/util.h"
#include "selfdrive/ui/qt/widgets/controls.h" #include "selfdrive/ui/qt/widgets/controls.h"
#include "selfdrive/ui/qt/widgets/prime.h"
#include "selfdrive/ui/qt/widgets/scrollview.h" #include "selfdrive/ui/qt/widgets/scrollview.h"
@ -184,7 +183,7 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid
// Set initial config // Set initial config
wifi->updateGsmSettings(roamingEnabled, QString::fromStdString(params.get("GsmApn")), metered); 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; bool gsmVisible = prime_type == PrimeType::NONE || prime_type == PrimeType::LITE;
roamingToggle->setVisible(gsmVisible); roamingToggle->setVisible(gsmVisible);
editApnButton->setVisible(gsmVisible); editApnButton->setVisible(gsmVisible);

@ -269,7 +269,7 @@ void SetupWidget::replyFinished(const QString &response, bool success) {
} }
QJsonObject json = doc.object(); QJsonObject json = doc.object();
int prime_type = json["prime_type"].toInt(); PrimeType prime_type = static_cast<PrimeType>(json["prime_type"].toInt());
uiState()->setPrimeType(prime_type); uiState()->setPrimeType(prime_type);
if (!json["is_paired"].toBool()) { if (!json["is_paired"].toBool()) {

@ -7,15 +7,6 @@
#include "selfdrive/ui/qt/widgets/input.h" #include "selfdrive/ui/qt/widgets/input.h"
enum PrimeType {
NONE = 0,
MAGENTA = 1,
LITE = 2,
BLUE = 3,
MAGENTA_NEW = 4,
};
// pairing QR code // pairing QR code
class PairingQRWidget : public QWidget { class PairingQRWidget : public QWidget {
Q_OBJECT Q_OBJECT

@ -245,8 +245,11 @@ UIState::UIState(QObject *parent) : QObject(parent) {
}); });
Params params; Params params;
prime_type = std::atoi(params.get("PrimeType").c_str());
language = QString::fromStdString(params.get("LanguageSetting")); language = QString::fromStdString(params.get("LanguageSetting"));
auto prime_value = params.get("PrimeType");
if (!prime_value.empty()) {
prime_type = static_cast<PrimeType>(std::atoi(prime_value.c_str()));
}
// update timer // update timer
timer = new QTimer(this); timer = new QTimer(this);
@ -265,7 +268,7 @@ void UIState::update() {
emit uiUpdate(*this); emit uiUpdate(*this);
} }
void UIState::setPrimeType(int type) { void UIState::setPrimeType(PrimeType type) {
if (type != prime_type) { if (type != prime_type) {
prime_type = type; prime_type = type;
Params().put("PrimeType", std::to_string(prime_type)); Params().put("PrimeType", std::to_string(prime_type));

@ -96,6 +96,15 @@ typedef enum UIStatus {
STATUS_ENGAGED, STATUS_ENGAGED,
} UIStatus; } UIStatus;
enum PrimeType {
UNKNOWN = -1,
NONE = 0,
MAGENTA = 1,
LITE = 2,
BLUE = 3,
MAGENTA_NEW = 4,
};
const QColor bg_colors [] = { const QColor bg_colors [] = {
[STATUS_DISENGAGED] = QColor(0x17, 0x33, 0x49, 0xc8), [STATUS_DISENGAGED] = QColor(0x17, 0x33, 0x49, 0xc8),
[STATUS_OVERRIDE] = QColor(0x91, 0x9b, 0x95, 0xf1), [STATUS_OVERRIDE] = QColor(0x91, 0x9b, 0x95, 0xf1),
@ -153,8 +162,8 @@ public:
return scene.started && (*sm)["controlsState"].getControlsState().getEnabled(); return scene.started && (*sm)["controlsState"].getControlsState().getEnabled();
} }
void setPrimeType(int type); void setPrimeType(PrimeType type);
inline int primeType() const { return prime_type; } inline PrimeType primeType() const { return prime_type; }
int fb_w = 0, fb_h = 0; int fb_w = 0, fb_h = 0;
@ -170,7 +179,7 @@ public:
signals: signals:
void uiUpdate(const UIState &s); void uiUpdate(const UIState &s);
void offroadTransition(bool offroad); void offroadTransition(bool offroad);
void primeTypeChanged(int prime_type); void primeTypeChanged(PrimeType prime_type);
private slots: private slots:
void update(); void update();
@ -178,7 +187,7 @@ private slots:
private: private:
QTimer *timer; QTimer *timer;
bool started_prev = false; bool started_prev = false;
int prime_type = -1; PrimeType prime_type = PrimeType::UNKNOWN;
}; };
UIState *uiState(); UIState *uiState();

Loading…
Cancel
Save