diff --git a/selfdrive/ui/qt/sidebar.cc b/selfdrive/ui/qt/sidebar.cc index c3fff1b90f..cd2c9534dd 100644 --- a/selfdrive/ui/qt/sidebar.cc +++ b/selfdrive/ui/qt/sidebar.cc @@ -2,8 +2,6 @@ #include -#include "selfdrive/common/util.h" -#include "selfdrive/hardware/hw.h" #include "selfdrive/ui/qt/util.h" void Sidebar::drawMetric(QPainter &p, const QString &label, const QString &val, QColor c, int y) { @@ -59,42 +57,31 @@ void Sidebar::updateState(const UIState &s) { int strength = (int)deviceState.getNetworkStrength(); setProperty("netStrength", strength > 0 ? strength + 1 : 0); + ItemStatus connectstatus; auto last_ping = deviceState.getLastAthenaPingTime(); if (last_ping == 0) { - if (params.getBool("PrimeRedirected")) { - setProperty("connectStr", "NO\nPRIME"); - setProperty("connectStatus", danger_color); - } else { - setProperty("connectStr", "CONNECT\nOFFLINE"); - setProperty("connectStatus", warning_color); - } + connectstatus = params.getBool("PrimeRedirected") ? ItemStatus{"NO\nPRIME", danger_color} : ItemStatus{"CONNECT\nOFFLINE", warning_color}; } else { - bool online = nanos_since_boot() - last_ping < 80e9; - setProperty("connectStr", (online ? "CONNECT\nONLINE" : "CONNECT\nERROR")); - setProperty("connectStatus", online ? good_color : danger_color); + connectstatus = nanos_since_boot() - last_ping < 80e9 ? ItemStatus{"CONNECT\nONLINE", good_color} : ItemStatus{"CONNECT\nERROR", danger_color}; } + setProperty("connectStatus", QVariant::fromValue(connectstatus)); - QColor tempStatus = danger_color; + QColor tempColor = danger_color; auto ts = deviceState.getThermalStatus(); if (ts == cereal::DeviceState::ThermalStatus::GREEN) { - tempStatus = good_color; + tempColor = good_color; } else if (ts == cereal::DeviceState::ThermalStatus::YELLOW) { - tempStatus = warning_color; + tempColor = warning_color; } - setProperty("tempStatus", tempStatus); - setProperty("tempVal", (int)deviceState.getAmbientTempC()); + setProperty("tempStatus", QVariant::fromValue(ItemStatus{QString("%1°C").arg((int)deviceState.getAmbientTempC()), tempColor})); - QString pandaStr = "VEHICLE\nONLINE"; - QColor pandaStatus = good_color; + ItemStatus pandaStatus = {"VEHICLE\nONLINE", good_color}; if (s.scene.pandaType == cereal::PandaState::PandaType::UNKNOWN) { - pandaStatus = danger_color; - pandaStr = "NO\nPANDA"; + pandaStatus = {"NO\nPANDA", danger_color}; } else if (s.scene.started && !sm["liveLocationKalman"].getLiveLocationKalman().getGpsOK()) { - pandaStatus = warning_color; - pandaStr = "GPS\nSEARCHING"; + pandaStatus = {"GPS\nSEARCHING", warning_color}; } - setProperty("pandaStr", pandaStr); - setProperty("pandaStatus", pandaStatus); + setProperty("pandaStatus", QVariant::fromValue(pandaStatus)); } void Sidebar::paintEvent(QPaintEvent *event) { @@ -125,7 +112,7 @@ void Sidebar::paintEvent(QPaintEvent *event) { p.drawText(r, Qt::AlignCenter, net_type); // metrics - drawMetric(p, "TEMP", QString("%1°C").arg(temp_val), temp_status, 338); - drawMetric(p, panda_str, "", panda_status, 518); - drawMetric(p, connect_str, "", connect_status, 676); + drawMetric(p, "TEMP", temp_status.first, temp_status.second, 338); + drawMetric(p, panda_status.first, "", panda_status.second, 518); + drawMetric(p, connect_status.first, "", connect_status.second, 676); } diff --git a/selfdrive/ui/qt/sidebar.h b/selfdrive/ui/qt/sidebar.h index 7cd04519a4..8785cd919c 100644 --- a/selfdrive/ui/qt/sidebar.h +++ b/selfdrive/ui/qt/sidebar.h @@ -6,14 +6,14 @@ #include "selfdrive/common/params.h" #include "selfdrive/ui/ui.h" +typedef QPair ItemStatus; +Q_DECLARE_METATYPE(ItemStatus); + class Sidebar : public QFrame { Q_OBJECT - Q_PROPERTY(QString connectStr MEMBER connect_str NOTIFY valueChanged); - Q_PROPERTY(QColor connectStatus MEMBER connect_status NOTIFY valueChanged); - Q_PROPERTY(QString pandaStr MEMBER panda_str NOTIFY valueChanged); - Q_PROPERTY(QColor pandaStatus MEMBER panda_status NOTIFY valueChanged); - Q_PROPERTY(int tempVal MEMBER temp_val NOTIFY valueChanged); - Q_PROPERTY(QColor tempStatus MEMBER temp_status NOTIFY valueChanged); + Q_PROPERTY(ItemStatus connectStatus MEMBER connect_status NOTIFY valueChanged); + Q_PROPERTY(ItemStatus pandaStatus MEMBER panda_status NOTIFY valueChanged); + Q_PROPERTY(ItemStatus tempStatus MEMBER temp_status NOTIFY valueChanged); Q_PROPERTY(QString netType MEMBER net_type NOTIFY valueChanged); Q_PROPERTY(int netStrength MEMBER net_strength NOTIFY valueChanged); @@ -30,8 +30,6 @@ public slots: protected: void paintEvent(QPaintEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; - -private: void drawMetric(QPainter &p, const QString &label, const QString &val, QColor c, int y); QImage home_img, settings_img; @@ -51,12 +49,7 @@ private: const QColor danger_color = QColor(201, 34, 49); Params params; - QString connect_str = "OFFLINE"; - QColor connect_status = warning_color; - QString panda_str = "NO\nPANDA"; - QColor panda_status = warning_color; - int temp_val = 0; - QColor temp_status = warning_color; + ItemStatus connect_status, panda_status, temp_status; QString net_type; int net_strength = 0; };