diff --git a/CHANGELOGS.md b/CHANGELOGS.md index ed244bddba..7d410f7df3 100644 --- a/CHANGELOGS.md +++ b/CHANGELOGS.md @@ -54,6 +54,7 @@ sunnypilot - 0.9.7.0 (2024-05-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! * Ford F-150 2022-23 support * Ford F-150 Lightning 2021-23 support * Ford Mustang Mach-E 2021-23 support diff --git a/selfdrive/ui/qt/sidebar.cc b/selfdrive/ui/qt/sidebar.cc index d44e818b24..df9ebc45c0 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,21 @@ 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); + 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) + 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 +199,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..be2c34cae0 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); @@ -53,12 +54,14 @@ 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; + 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";