diff --git a/selfdrive/ui/qt/home.cc b/selfdrive/ui/qt/home.cc index 4b9f050da3..128d46cfe0 100644 --- a/selfdrive/ui/qt/home.cc +++ b/selfdrive/ui/qt/home.cc @@ -21,7 +21,7 @@ HomeWindow::HomeWindow(QWidget* parent) : QWidget(parent) { sidebar = new Sidebar(this); layout->addWidget(sidebar); - QObject::connect(this, &HomeWindow::update, sidebar, &Sidebar::update); + QObject::connect(this, &HomeWindow::update, sidebar, &Sidebar::updateState); QObject::connect(sidebar, &Sidebar::openSettings, this, &HomeWindow::openSettings); slayout = new QStackedLayout(); diff --git a/selfdrive/ui/qt/sidebar.cc b/selfdrive/ui/qt/sidebar.cc index 8c49fbf396..9e9377f9ed 100644 --- a/selfdrive/ui/qt/sidebar.cc +++ b/selfdrive/ui/qt/sidebar.cc @@ -37,6 +37,8 @@ Sidebar::Sidebar(QWidget *parent) : QFrame(parent) { home_img = QImage("../assets/images/button_home.png").scaled(180, 180, Qt::KeepAspectRatio, Qt::SmoothTransformation); settings_img = QImage("../assets/images/button_settings.png").scaled(settings_btn.width(), settings_btn.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);; + connect(this, &Sidebar::valueChanged, [=] { update(); }); + setFixedWidth(300); setMinimumHeight(vwp_h); setStyleSheet("background-color: rgb(57, 57, 57);"); @@ -48,45 +50,44 @@ void Sidebar::mousePressEvent(QMouseEvent *event) { } } -void Sidebar::update(const UIState &s) { - if (s.sm->frame % (6*UI_FREQ) == 0) { - connect_str = "OFFLINE"; - connect_status = warning_color; - auto last_ping = params.get("LastAthenaPingTime"); - if (last_ping) { - bool online = nanos_since_boot() - *last_ping < 80e9; - connect_str = online ? "ONLINE" : "ERROR"; - connect_status = online ? good_color : danger_color; - } - repaint(); - } +void Sidebar::updateState(const UIState &s) { + auto &sm = *(s.sm); - auto deviceState = (*s.sm)["deviceState"].getDeviceState(); - net_type = deviceState.getNetworkType(); - strength = deviceState.getNetworkStrength(); + auto deviceState = sm["deviceState"].getDeviceState(); + setProperty("netType", (int)deviceState.getNetworkType()); + setProperty("netStrength", (int)deviceState.getNetworkStrength()); - temp_status = danger_color; + auto last_ping = deviceState.getLastAthenaPingTime(); + if (last_ping == 0) { + setProperty("connectStr", "OFFLINE"); + setProperty("connectStatus", warning_color); + } else { + bool online = nanos_since_boot() - last_ping < 80e9; + setProperty("connectStr", online ? "ONLINE" : "ERROR"); + setProperty("connectStatus", online ? good_color : danger_color); + } + + QColor tempStatus = danger_color; auto ts = deviceState.getThermalStatus(); if (ts == cereal::DeviceState::ThermalStatus::GREEN) { - temp_status = good_color; + tempStatus = good_color; } else if (ts == cereal::DeviceState::ThermalStatus::YELLOW) { - temp_status = warning_color; + tempStatus = warning_color; } - temp_val = (int)deviceState.getAmbientTempC(); + setProperty("tempStatus", tempStatus); + setProperty("tempVal", (int)deviceState.getAmbientTempC()); - panda_str = "VEHICLE\nONLINE"; - panda_status = good_color; + QString pandaStr = "VEHICLE\nONLINE"; + QColor pandaStatus = good_color; if (s.scene.pandaType == cereal::PandaState::PandaType::UNKNOWN) { - panda_status = danger_color; - panda_str = "NO\nPANDA"; + pandaStatus = danger_color; + pandaStr = "NO\nPANDA"; } else if (Hardware::TICI() && s.scene.started) { - panda_str = QString("SATS %1\nACC %2").arg(s.scene.satelliteCount).arg(fmin(10, s.scene.gpsAccuracy), 0, 'f', 2); - panda_status = (*s.sm)["liveLocationKalman"].getLiveLocationKalman().getGpsOK() ? good_color : warning_color; - } - - if (s.sm->updated("deviceState") || s.sm->updated("pandaState")) { - repaint(); + pandaStr = QString("SATS %1\nACC %2").arg(s.scene.satelliteCount).arg(fmin(10, s.scene.gpsAccuracy), 0, 'f', 2); + pandaStatus = sm["liveLocationKalman"].getLiveLocationKalman().getGpsOK() ? good_color : warning_color; } + setProperty("pandaStr", pandaStr); + setProperty("pandaStatus", pandaStatus); } void Sidebar::paintEvent(QPaintEvent *event) { @@ -101,7 +102,7 @@ void Sidebar::paintEvent(QPaintEvent *event) { p.drawImage(60, 1080 - 180 - 40, home_img); // network - p.drawImage(58, 196, signal_imgs[strength]); + p.drawImage(58, 196, signal_imgs[net_strength]); configFont(p, "Open Sans", 35, "Regular"); p.setPen(QColor(0xff, 0xff, 0xff)); const QRect r = QRect(50, 247, 100, 50); diff --git a/selfdrive/ui/qt/sidebar.h b/selfdrive/ui/qt/sidebar.h index 76d65569f7..52e2ee5686 100644 --- a/selfdrive/ui/qt/sidebar.h +++ b/selfdrive/ui/qt/sidebar.h @@ -6,15 +6,24 @@ 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(cereal::DeviceState::NetworkType netType MEMBER net_type NOTIFY valueChanged); + Q_PROPERTY(cereal::DeviceState::NetworkStrength netStrength MEMBER net_strength NOTIFY valueChanged); public: explicit Sidebar(QWidget* parent = 0); signals: void openSettings(); + void valueChanged(); public slots: - void update(const UIState &s); + void updateState(const UIState &s); protected: void paintEvent(QPaintEvent *event) override; @@ -45,7 +54,6 @@ private: const QColor warning_color = QColor(218, 202, 37); const QColor danger_color = QColor(201, 34, 49); - Params params; QString connect_str = "OFFLINE"; QColor connect_status = warning_color; QString panda_str = "NO\nPANDA"; @@ -53,5 +61,5 @@ private: int temp_val = 0; QColor temp_status = warning_color; cereal::DeviceState::NetworkType net_type; - cereal::DeviceState::NetworkStrength strength; + cereal::DeviceState::NetworkStrength net_strength; };