From a177818e587ae7cfa57055dd7b83d1e819a3591d Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Fri, 12 Apr 2024 16:31:02 +0200 Subject: [PATCH 1/3] Add Sunnylink status to Sidebar UI Included a new 'ItemStatus' variable, 'sunnylinkStatus', to the Sidebar class and draw its metric in the UI. The status is determined by the value of 'LastSunnylinkPingTime', turning Sunnylink offline if it equals 0, online if the ping time is less than 80e9, and displaying an error otherwise. --- selfdrive/ui/qt/sidebar.cc | 20 +++++++++++++++++--- selfdrive/ui/qt/sidebar.h | 4 +++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/selfdrive/ui/qt/sidebar.cc b/selfdrive/ui/qt/sidebar.cc index 6b0ef8c7f7..50ece47df4 100644 --- a/selfdrive/ui/qt/sidebar.cc +++ b/selfdrive/ui/qt/sidebar.cc @@ -5,6 +5,7 @@ #include #include "selfdrive/ui/qt/util.h" +#include "common/params.h" void Sidebar::drawMetric(QPainter &p, const QPair &label, QColor c, int y) { const QRect rect = {30, y, 240, 126}; @@ -152,6 +153,18 @@ void Sidebar::updateState(const UIState &s) { pandaStatus = {{tr("GPS"), tr("SEARCH")}, warning_color}; } setProperty("pandaStatus", QVariant::fromValue(pandaStatus)); + + ItemStatus sunnylinkStatus; + auto last_sunnylink_ping = std::strtol(params.get("LastSunnylinkPingTime").c_str(), nullptr, 10); + if (last_ping == 0) { + sunnylinkStatus = ItemStatus{{tr("SUNNYLINK"), tr("OFFLINE")}, warning_color}; + } else { + if (nanos_since_boot() - last_sunnylink_ping < 80e9) + sunnylinkStatus = ItemStatus{{tr("SUNNYLINK"), tr("ONLINE")}, good_color}; + else + sunnylinkStatus = ItemStatus{{tr("SUNNYLINK"), tr("ERROR")}, danger_color}; + } + setProperty("sunnylinkStatus", QVariant::fromValue(sunnylinkStatus)); } void Sidebar::paintEvent(QPaintEvent *event) { @@ -183,7 +196,8 @@ void Sidebar::paintEvent(QPaintEvent *event) { p.drawText(r, Qt::AlignCenter, net_type); // metrics - drawMetric(p, temp_status.first, temp_status.second, 338); - drawMetric(p, panda_status.first, panda_status.second, 496); - drawMetric(p, connect_status.first, connect_status.second, 654); + drawMetric(p, temp_status.first, temp_status.second, 310); + drawMetric(p, panda_status.first, panda_status.second, 440); + drawMetric(p, connect_status.first, connect_status.second, 570); + drawMetric(p, sunnylink_status.first, sunnylink_status.second, 700); } diff --git a/selfdrive/ui/qt/sidebar.h b/selfdrive/ui/qt/sidebar.h index 4297602908..7a7f2387bd 100644 --- a/selfdrive/ui/qt/sidebar.h +++ b/selfdrive/ui/qt/sidebar.h @@ -13,6 +13,7 @@ Q_DECLARE_METATYPE(ItemStatus); class Sidebar : public QFrame { Q_OBJECT Q_PROPERTY(ItemStatus connectStatus MEMBER connect_status NOTIFY valueChanged); + Q_PROPERTY(ItemStatus sunnylinkStatus MEMBER sunnylink_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); @@ -54,11 +55,12 @@ protected: const QColor warning_color = QColor(218, 202, 37); const QColor danger_color = QColor(201, 34, 49); - ItemStatus connect_status, panda_status, temp_status; + ItemStatus connect_status, panda_status, temp_status, sunnylink_status; QString net_type; int net_strength = 0; private: + Params params; std::unique_ptr pm; QString sidebar_temp = "0"; From abdb9e64d0fb3c2b6efd704573b438e864f21da0 Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Fri, 12 Apr 2024 16:43:29 +0200 Subject: [PATCH 2/3] Add disabled state to sidebar status items A new disabled color has been added to the sidebar items. This change primarily impacts the 'Sunnylink' status where a new state has been introduced. Now, when 'Sunnylink' is not enabled, it will show as 'DISABLED' in the disabled color. --- selfdrive/ui/qt/sidebar.cc | 5 ++++- selfdrive/ui/qt/sidebar.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/selfdrive/ui/qt/sidebar.cc b/selfdrive/ui/qt/sidebar.cc index 50ece47df4..425f8fb92e 100644 --- a/selfdrive/ui/qt/sidebar.cc +++ b/selfdrive/ui/qt/sidebar.cc @@ -156,7 +156,10 @@ void Sidebar::updateState(const UIState &s) { ItemStatus sunnylinkStatus; auto last_sunnylink_ping = std::strtol(params.get("LastSunnylinkPingTime").c_str(), nullptr, 10); - if (last_ping == 0) { + auto sunnylink_enabled = params.getBool("SunnylinkEnabled"); + if (!sunnylink_enabled) { + sunnylinkStatus = ItemStatus{{tr("SUNNYLINK"), tr("DISABLED")}, disabled_color}; + } else if (last_ping == 0) { sunnylinkStatus = ItemStatus{{tr("SUNNYLINK"), tr("OFFLINE")}, warning_color}; } else { if (nanos_since_boot() - last_sunnylink_ping < 80e9) diff --git a/selfdrive/ui/qt/sidebar.h b/selfdrive/ui/qt/sidebar.h index 7a7f2387bd..be2c34cae0 100644 --- a/selfdrive/ui/qt/sidebar.h +++ b/selfdrive/ui/qt/sidebar.h @@ -54,6 +54,7 @@ protected: const QColor good_color = QColor(255, 255, 255); const QColor warning_color = QColor(218, 202, 37); const QColor danger_color = QColor(201, 34, 49); + const QColor disabled_color = QColor(128, 128, 128); ItemStatus connect_status, panda_status, temp_status, sunnylink_status; QString net_type; From ba9fb8af6bba1c073ee58c1f87cc8685def9d324 Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Sat, 13 Apr 2024 19:03:17 +0200 Subject: [PATCH 3/3] Add sunnylink connectivity status to changelog In the update information for the changelog, a record of the new feature displaying the sunnylink connectivity status on the left sidebar has been added. This lets users and developers quickly see that this change has been implemented. --- CHANGELOGS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOGS.md b/CHANGELOGS.md index 18c0a9df45..30881e67b2 100644 --- a/CHANGELOGS.md +++ b/CHANGELOGS.md @@ -25,6 +25,7 @@ sunnypilot - 0.9.7.0 (2024-xx-xx) * Display Metrics Below Chevron * NEW❗: Metrics is now being displayed below the chevron instead of above * NEW❗: Display both Distance and Speed simultaneously + * NEW❗: View sunnylink connectivity status on the left sidebar! sunnypilot - 0.9.6.1 (2024-02-27) ========================