[TIZI/TICI] ui: sunnylink status on sidebar (#1638)

* Initial plan

* feat: add sunnylink status metric

Co-authored-by: devtekve <7696966+devtekve@users.noreply.github.com>

* chore: extract sidebar constants

Co-authored-by: devtekve <7696966+devtekve@users.noreply.github.com>

* refactor: guard metric spacing

Co-authored-by: devtekve <7696966+devtekve@users.noreply.github.com>

* chore: clarify sunnylink helpers

Co-authored-by: devtekve <7696966+devtekve@users.noreply.github.com>

* refactor: guard metric spacing edge cases

Co-authored-by: devtekve <7696966+devtekve@users.noreply.github.com>

* chore: simplify spacing guards

Co-authored-by: devtekve <7696966+devtekve@users.noreply.github.com>

* chore: normalize sunnylink params

Co-authored-by: devtekve <7696966+devtekve@users.noreply.github.com>

* chore: harden sunnylink param parsing

Co-authored-by: devtekve <7696966+devtekve@users.noreply.github.com>

* chore: add param decode helper

Co-authored-by: devtekve <7696966+devtekve@users.noreply.github.com>

* chore: simplify sidebar metric spacing

Co-authored-by: devtekve <7696966+devtekve@users.noreply.github.com>

* chore: update sunnylink status color logic for improved clarity

* sunnylink: update status handling to reflect offline state and improve fault indication

sunnylink: enhance status handling with temporary fault indication

* sunnylink: enhance status update logic for improved accuracy and clarity

* make it int

* Ugly with zero value, but done. Now we only need to remember to check the new sidebar if the old sidebar ever changes

* Revert "Ugly with zero value, but done. Now we only need to remember to check the new sidebar if the old sidebar ever changes"

This reverts commit 2d3b740e38.

* decouple

* no bad bot

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: devtekve <7696966+devtekve@users.noreply.github.com>
Co-authored-by: DevTekVE <devtekve@gmail.com>
Co-authored-by: Jason Wen <haibin.wen3@gmail.com>
This commit is contained in:
Copilot
2026-01-03 21:01:21 -05:00
committed by GitHub
parent 9a04a5eaae
commit 987f53e69a
2 changed files with 100 additions and 2 deletions

View File

@@ -9,6 +9,8 @@ from openpilot.system.ui.lib.multilang import tr, tr_noop
from openpilot.system.ui.lib.text_measure import measure_text_cached
from openpilot.system.ui.widgets import Widget
from openpilot.selfdrive.ui.sunnypilot.layouts.sidebar import SidebarSP
SIDEBAR_WIDTH = 300
METRIC_HEIGHT = 126
METRIC_WIDTH = 240
@@ -62,9 +64,10 @@ class MetricData:
self.color = color
class Sidebar(Widget):
class Sidebar(Widget, SidebarSP):
def __init__(self):
super().__init__()
Widget.__init__(self)
SidebarSP.__init__(self)
self._net_type = NETWORK_TYPES.get(NetworkType.none)
self._net_strength = 0
@@ -112,6 +115,7 @@ class Sidebar(Widget):
self._update_temperature_status(device_state)
self._update_connection_status(device_state)
self._update_panda_status()
SidebarSP._update_sunnylink_status(self)
def _update_network_status(self, device_state):
self._net_type = NETWORK_TYPES.get(device_state.networkType.raw, tr_noop("Unknown"))
@@ -200,6 +204,13 @@ class Sidebar(Widget):
rl.draw_text_ex(self._font_regular, tr(self._net_type), text_pos, FONT_SIZE, 0, Colors.WHITE)
def _draw_metrics(self, rect: rl.Rectangle):
if gui_app.sunnypilot_ui():
metrics, start_y, spacing = SidebarSP._draw_metrics_w_sunnylink(self, rect, self._temp_status, self._panda_status, self._connect_status)
for idx, metric in enumerate(metrics):
self._draw_metric(rect, metric, start_y + idx * spacing)
return
metrics = [(self._temp_status, 338), (self._panda_status, 496), (self._connect_status, 654)]
for metric, y_offset in metrics:

View File

@@ -0,0 +1,87 @@
"""
Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors.
This file is part of sunnypilot and is licensed under the MIT License.
See the LICENSE.md file in the root directory for more details.
"""
import pyray as rl
import time
from dataclasses import dataclass
from openpilot.selfdrive.ui.ui_state import ui_state
from openpilot.sunnypilot.sunnylink.api import UNREGISTERED_SUNNYLINK_DONGLE_ID
from openpilot.system.ui.lib.multilang import tr_noop
PING_TIMEOUT_NS = 80_000_000_000 # 80 seconds in nanoseconds
METRIC_HEIGHT = 126
METRIC_MARGIN = 30
METRIC_START_Y = 300
HOME_BTN = rl.Rectangle(60, 860, 180, 180)
# Color scheme
class Colors:
WHITE = rl.WHITE
WHITE_DIM = rl.Color(255, 255, 255, 85)
GRAY = rl.Color(84, 84, 84, 255)
# Status colors
GOOD = rl.WHITE
WARNING = rl.Color(218, 202, 37, 255)
DANGER = rl.Color(201, 34, 49, 255)
PROGRESS = rl.Color(0, 134, 233, 255)
DISABLED = rl.Color(128, 128, 128, 255)
# UI elements
METRIC_BORDER = rl.Color(255, 255, 255, 85)
BUTTON_NORMAL = rl.WHITE
BUTTON_PRESSED = rl.Color(255, 255, 255, 166)
@dataclass(slots=True)
class MetricData:
label: str
value: str
color: rl.Color
def update(self, label: str, value: str, color: rl.Color):
self.label = label
self.value = value
self.color = color
class SidebarSP:
def __init__(self):
self._sunnylink_status = MetricData(tr_noop("SUNNYLINK"), tr_noop("OFFLINE"), Colors.WARNING)
def _update_sunnylink_status(self):
if not ui_state.params.get_bool("SunnylinkEnabled"):
self._sunnylink_status.update(tr_noop("SUNNYLINK"), tr_noop("DISABLED"), Colors.DISABLED)
return
last_ping = ui_state.params.get("LastSunnylinkPingTime") or 0
dongle_id = ui_state.params.get("SunnylinkDongleId")
is_online = last_ping and (time.monotonic_ns() - last_ping) < PING_TIMEOUT_NS
is_temp_fault = ui_state.params.get_bool("SunnylinkTempFault")
is_registering = not is_temp_fault and dongle_id in (None, "", UNREGISTERED_SUNNYLINK_DONGLE_ID)
# Determine status/color pair based on priority
if last_ping:
status, color = (tr_noop("ONLINE"), Colors.GOOD) if is_online else (tr_noop("ERROR"), Colors.DANGER)
elif is_temp_fault:
status, color = (tr_noop("FAULT"), Colors.WARNING)
elif is_registering:
status, color = (tr_noop("REGIST..."), Colors.PROGRESS)
else:
status, color = (tr_noop("OFFLINE"), Colors.DANGER)
self._sunnylink_status.update(tr_noop("SUNNYLINK"), status, color)
def _draw_metrics_w_sunnylink(self, rect: rl.Rectangle, _temp, _panda, _connect):
metrics = [_temp, _panda, _connect, self._sunnylink_status]
start_y = int(rect.y) + METRIC_START_Y
available_height = max(0, int(HOME_BTN.y) - METRIC_MARGIN - METRIC_HEIGHT - start_y)
spacing = available_height / max(1, len(metrics) - 1)
return metrics, start_y, spacing