mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-15 06:12:11 +08:00
guess we need these
This commit is contained in:
@@ -247,7 +247,25 @@ class StarPilotOnroadView(AugmentedRoadView):
|
||||
super()._handle_mouse_press(mouse_pos)
|
||||
|
||||
def _render_developer_metrics(self):
|
||||
if not self._params.get_bool("FPSCounter"):
|
||||
toggles = ui_state.starpilot_toggles
|
||||
debug_mode = bool(toggles.get("debug_mode", self._params.get_bool("DebugMode")))
|
||||
developer_metrics = (
|
||||
bool(toggles.get("developer_ui", self._params.get_bool("DeveloperUI"))) and
|
||||
self._params.get_bool("DeveloperMetrics")
|
||||
) or debug_mode
|
||||
|
||||
def metric_enabled(toggle_key: str, param_key: str, debug_override: bool = False) -> bool:
|
||||
if toggle_key in toggles:
|
||||
return bool(toggles.get(toggle_key))
|
||||
return (developer_metrics and self._params.get_bool(param_key)) or (debug_mode and debug_override)
|
||||
|
||||
show_fps = metric_enabled("show_fps", "FPSCounter", debug_override=True)
|
||||
show_cpu = metric_enabled("cpu_metrics", "ShowCPU", debug_override=True)
|
||||
show_gpu = metric_enabled("gpu_metrics", "ShowGPU")
|
||||
show_temp = metric_enabled("numerical_temp", "NumericalTemp", debug_override=True)
|
||||
show_memory = metric_enabled("memory_metrics", "ShowMemoryUsage", debug_override=True)
|
||||
|
||||
if not any((show_fps, show_cpu, show_gpu, show_temp, show_memory)):
|
||||
return
|
||||
|
||||
# Track FPS
|
||||
@@ -269,23 +287,28 @@ class StarPilotOnroadView(AugmentedRoadView):
|
||||
# Gather device stats
|
||||
device_state = ui_state.sm["deviceState"] if ui_state.sm.valid.get("deviceState", False) else None
|
||||
cpu_val = 0
|
||||
gpu_val = 0
|
||||
temp_val = 0
|
||||
mem_val = 0
|
||||
mem_gb = 0.0
|
||||
if device_state:
|
||||
cpu_list = list(device_state.cpuUsagePercent)
|
||||
cpu_val = int(sum(cpu_list) / len(cpu_list)) if cpu_list else 0
|
||||
gpu_val = int(device_state.gpuUsagePercent)
|
||||
temp_val = int(device_state.maxTempC)
|
||||
mem_val = int(device_state.memoryUsagePercent)
|
||||
mem_gb = 8.0 * mem_val / 100.0
|
||||
|
||||
# Format text lines for top-right developer metrics overlay
|
||||
text_lines = [
|
||||
f"FPS: {round(fps)}",
|
||||
f"CPU: {cpu_val}%",
|
||||
f"TEMP: {temp_val}°C",
|
||||
f"RAM: {mem_gb:.1f} GB ({mem_val}%)"
|
||||
]
|
||||
# Format text lines for top-right developer metrics overlay.
|
||||
text_lines = []
|
||||
if show_cpu:
|
||||
text_lines.append(f"CPU: {cpu_val}%")
|
||||
if show_gpu:
|
||||
text_lines.append(f"GPU: {gpu_val}%")
|
||||
if show_temp:
|
||||
text_lines.append(f"TEMP: {temp_val}°C")
|
||||
if show_memory:
|
||||
text_lines.append(f"RAM: {mem_gb:.1f} GB ({mem_val}%)")
|
||||
|
||||
# Helper function for outlined text drawing
|
||||
font = self._font_medium
|
||||
@@ -301,18 +324,20 @@ class StarPilotOnroadView(AugmentedRoadView):
|
||||
rl.draw_text_ex(font, text, pos, font_size, 0, color)
|
||||
|
||||
# 1. Render top-right developer metrics block
|
||||
x = self._content_rect.x + self._content_rect.width - 30
|
||||
y = self._content_rect.y + 40
|
||||
for i, line in enumerate(text_lines):
|
||||
sz = measure_text_cached(font, line, font_size)
|
||||
draw_text_with_outline(line, x - sz.x, y + i * line_height, rl.WHITE)
|
||||
if text_lines:
|
||||
x = self._content_rect.x + self._content_rect.width - 30
|
||||
y = self._content_rect.y + 40
|
||||
for i, line in enumerate(text_lines):
|
||||
sz = measure_text_cached(font, line, font_size)
|
||||
draw_text_with_outline(line, x - sz.x, y + i * line_height, rl.WHITE)
|
||||
|
||||
# 2. Render bottom-center detailed FPS tracker string (min/max/avg)
|
||||
fps_str = f"FPS: {round(fps)} | Min: {round(self._min_fps)} | Max: {round(self._max_fps)} | Avg: {round(self._avg_fps)}"
|
||||
sz = measure_text_cached(font, fps_str, font_size)
|
||||
bx = self._content_rect.x + (self._content_rect.width - sz.x) / 2
|
||||
by = self._content_rect.y + self._content_rect.height - sz.y - 10
|
||||
draw_text_with_outline(fps_str, bx, by, rl.WHITE)
|
||||
if show_fps:
|
||||
fps_str = f"FPS: {round(fps)} | Min: {round(self._min_fps)} | Max: {round(self._max_fps)} | Avg: {round(self._avg_fps)}"
|
||||
sz = measure_text_cached(font, fps_str, font_size)
|
||||
bx = self._content_rect.x + (self._content_rect.width - sz.x) / 2
|
||||
by = self._content_rect.y + self._content_rect.height - sz.y - 10
|
||||
draw_text_with_outline(fps_str, bx, by, rl.WHITE)
|
||||
|
||||
|
||||
def _render_bottom_row_widgets(self):
|
||||
|
||||
@@ -3642,6 +3642,63 @@
|
||||
"name": "Developer",
|
||||
"icon": "bi-exclamation-triangle",
|
||||
"params": [
|
||||
{
|
||||
"key": "DeveloperUI",
|
||||
"label": "Developer UI",
|
||||
"description": "Detailed information about openpilot's internal operations.",
|
||||
"data_type": "bool",
|
||||
"ui_type": "toggle",
|
||||
"is_parent_toggle": true
|
||||
},
|
||||
{
|
||||
"key": "DeveloperMetrics",
|
||||
"label": "Developer Metrics",
|
||||
"description": "Performance data, sensor readings, and system metrics for debugging and optimizing openpilot.",
|
||||
"data_type": "bool",
|
||||
"ui_type": "toggle",
|
||||
"is_parent_toggle": true,
|
||||
"parent_key": "DeveloperUI"
|
||||
},
|
||||
{
|
||||
"key": "FPSCounter",
|
||||
"label": "FPS Display",
|
||||
"description": "Show the frames per second at the bottom of the driving screen.",
|
||||
"data_type": "bool",
|
||||
"ui_type": "toggle",
|
||||
"parent_key": "DeveloperMetrics"
|
||||
},
|
||||
{
|
||||
"key": "ShowCPU",
|
||||
"label": "CPU Metrics",
|
||||
"description": "Show CPU usage in the driving screen developer metrics.",
|
||||
"data_type": "bool",
|
||||
"ui_type": "toggle",
|
||||
"parent_key": "DeveloperMetrics"
|
||||
},
|
||||
{
|
||||
"key": "ShowGPU",
|
||||
"label": "GPU Metrics",
|
||||
"description": "Show GPU usage in the driving screen developer metrics.",
|
||||
"data_type": "bool",
|
||||
"ui_type": "toggle",
|
||||
"parent_key": "DeveloperMetrics"
|
||||
},
|
||||
{
|
||||
"key": "NumericalTemp",
|
||||
"label": "Temperature Metrics",
|
||||
"description": "Show numerical device temperature in the driving screen developer metrics.",
|
||||
"data_type": "bool",
|
||||
"ui_type": "toggle",
|
||||
"parent_key": "DeveloperMetrics"
|
||||
},
|
||||
{
|
||||
"key": "ShowMemoryUsage",
|
||||
"label": "RAM Metrics",
|
||||
"description": "Show memory usage in the driving screen developer metrics.",
|
||||
"data_type": "bool",
|
||||
"ui_type": "toggle",
|
||||
"parent_key": "DeveloperMetrics"
|
||||
},
|
||||
{
|
||||
"key": "UseOldUI",
|
||||
"label": "Use Old UI",
|
||||
|
||||
Reference in New Issue
Block a user