Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions openpilot/common/params_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
{"EnableRemoteUI", {PERSISTENT | BACKUP, BOOL, "0"}},
{"KonikApi", {PERSISTENT | BACKUP, BOOL, "0"}},
{"KonikDongleId", {PERSISTENT, STRING}},
{"SidebarNetworkIP", {PERSISTENT | BACKUP, BOOL, "0"}},
{"SidebarShowBattery", {PERSISTENT | BACKUP, BOOL, "0"}},
{"SidebarShowConnect", {PERSISTENT | BACKUP, BOOL, "1"}},
{"SidebarShowGps", {PERSISTENT | BACKUP, BOOL, "0"}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def _initialize_items(self):
description=lambda: tr("Show the signal strength and connection type in the sidebar."),
param="SidebarShowNetwork",
)
network_ip = toggle_item_sp(
title=lambda: tr("Sidebar: Network IP Address"),
description=lambda: tr("Show the device's IP address instead of Wi-Fi when connected to Wi-Fi."),
param="SidebarNetworkIP",
enabled=lambda: network.action_item.get_state(),
)

tile_toggles = [
("SidebarShowTemp", lambda: tr("Sidebar: Temperature"), lambda: tr("Show the device temperature status in the sidebar.")),
Expand All @@ -42,7 +48,7 @@ def _initialize_items(self):
enabled=lambda: temp.action_item.get_state(),
)

return [network, temp, temp_degrees, *self._tile_items[1:]]
return [network, network_ip, temp, temp_degrees, *self._tile_items[1:]]

def _tile_item(self, param, title, desc):
item = toggle_item_sp(title=title, description=desc, param=param)
Expand Down
24 changes: 22 additions & 2 deletions openpilot/selfdrive/ui/cloudypilot/layouts/sidebar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pyray as rl
import socket
import time
from collections.abc import Callable
from openpilot.cereal import log
Expand Down Expand Up @@ -31,6 +32,16 @@
NetworkType = log.DeviceState.NetworkType


def wifi_ip_address() -> str:
try:
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
# Connecting a UDP socket only resolves the route, nothing is sent
sock.connect(("8.8.8.8", 80))
return sock.getsockname()[0]
except OSError:
return ""


class Colors:
WHITE = rl.WHITE
WHITE_DIM = rl.Color(255, 255, 255, 85)
Expand Down Expand Up @@ -73,6 +84,7 @@ def __init__(self):
SidebarSP.__init__(self)
self._net_type = NETWORK_TYPES[NetworkType.none]
self._net_strength = 0
self._net_ip = ""

self._temp_status = MetricData(tr_noop("TEMP"), tr_noop("GOOD"), Colors.GOOD)
self._panda_status = MetricData(tr_noop("VEHICLE"), tr_noop("ONLINE"), Colors.GOOD)
Expand Down Expand Up @@ -134,7 +146,9 @@ def _update_state(self):
self._update_load_status(device_state)

def _update_network_status(self, device_state):
self._net_type = NETWORK_TYPES.get(device_state.networkType.raw, tr_noop("Unknown"))
net_type = device_state.networkType.raw
self._net_type = NETWORK_TYPES.get(net_type, tr_noop("Unknown"))
self._net_ip = wifi_ip_address() if ui_state.sidebar_network_ip and net_type == NetworkType.wifi else ""
strength = device_state.networkStrength
self._net_strength = max(0, min(5, strength.raw + 1)) if strength.raw > 0 else 0

Expand Down Expand Up @@ -329,7 +343,13 @@ def _draw_network_indicator(self, rect: rl.Rectangle):
# Network type text
text_y = rect.y + 247
text_pos = rl.Vector2(rect.x + 58, text_y)
rl.draw_text_ex(self._font_regular, tr(self._net_type), text_pos, FONT_SIZE, 0, Colors.WHITE)
text, font_size = tr(self._net_type), FONT_SIZE
# The mic indicator sits on the same row, so the IP only shows while it's hidden
if self._net_ip and not self._recording_audio:
text = self._net_ip
max_width = rect.width - 58 - METRIC_MARGIN
font_size = min(FONT_SIZE, FONT_SIZE * max_width / measure_text_cached(self._font_regular, text, FONT_SIZE).x)
rl.draw_text_ex(self._font_regular, text, text_pos, font_size, 0, Colors.WHITE)

def _draw_metrics(self, rect: rl.Rectangle):
if gui_app.cloudypilot_ui():
Expand Down
2 changes: 2 additions & 0 deletions openpilot/selfdrive/ui/cloudypilot/ui_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def __init__(self):
self.use_feet: bool = False
self.remote_ui: bool = False
self.sidebar_show_network: bool = True
self.sidebar_network_ip: bool = False
self.sidebar_show_temp: bool = True
self.sidebar_show_vehicle: bool = True
self.sidebar_show_connect: bool = True
Expand Down Expand Up @@ -34,6 +35,7 @@ def update_params(self) -> None:
self.use_feet = self.params.get_bool("UseFeetGPS")
self.remote_ui = self.params.get_bool("EnableRemoteUI")
self.sidebar_show_network = self.params.get_bool("SidebarShowNetwork")
self.sidebar_network_ip = self.params.get_bool("SidebarNetworkIP")
self.sidebar_show_temp = self.params.get_bool("SidebarShowTemp")
self.sidebar_show_vehicle = self.params.get_bool("SidebarShowVehicle")
self.sidebar_show_connect = self.params.get_bool("SidebarShowConnect")
Expand Down