mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-23 01:04:01 +08:00
26 lines
755 B
Python
26 lines
755 B
Python
from openpilot.selfdrive.ui.ui_state import ui_state
|
|
|
|
def get_compass_text() -> str | None:
|
|
if not ui_state.params.get_bool("Compass"):
|
|
return None
|
|
|
|
# Retrieve bearing
|
|
bearing = 0.0
|
|
gps = ui_state.sm["gpsLocationExternal"] if ui_state.sm.valid.get("gpsLocationExternal", False) else None
|
|
if gps and gps.bearingDeg != 0:
|
|
bearing = gps.bearingDeg
|
|
else:
|
|
try:
|
|
last_gps = ui_state.params_memory.get("LastGPSPosition")
|
|
if last_gps:
|
|
import json
|
|
data = json.loads(last_gps)
|
|
bearing = data.get("bearing", 0.0)
|
|
except Exception:
|
|
pass
|
|
|
|
bearing = bearing % 360
|
|
directions = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]
|
|
idx = int((bearing + 22.5) // 45) % 8
|
|
return f"- {directions[idx]} -"
|