mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-04-06 16:53:58 +08:00
[MICI] ui: Speed Limit Assist preActive status (#1742)
* mici init * obv * hybrid * adapt * less * consolidate * oops Refactor speed limit alert function to use car state directly. * no event border for tizi/tici * abstract it * less * nah
This commit is contained in:
@@ -13,6 +13,8 @@ from openpilot.system.ui.lib.application import gui_app, FontWeight
|
||||
from openpilot.system.ui.widgets import Widget
|
||||
from openpilot.system.ui.widgets.label import UnifiedLabel
|
||||
|
||||
from openpilot.selfdrive.ui.sunnypilot.onroad.speed_limit import SpeedLimitAlertRenderer
|
||||
|
||||
AlertSize = log.SelfdriveState.AlertSize
|
||||
AlertStatus = log.SelfdriveState.AlertStatus
|
||||
|
||||
@@ -46,6 +48,7 @@ class IconLayout(NamedTuple):
|
||||
side: IconSide
|
||||
margin_x: int
|
||||
margin_y: int
|
||||
alpha: float = 255.0
|
||||
|
||||
|
||||
class AlertLayout(NamedTuple):
|
||||
@@ -86,9 +89,10 @@ ALERT_CRITICAL_REBOOT = Alert(
|
||||
)
|
||||
|
||||
|
||||
class AlertRenderer(Widget):
|
||||
class AlertRenderer(Widget, SpeedLimitAlertRenderer):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
Widget.__init__(self)
|
||||
SpeedLimitAlertRenderer.__init__(self)
|
||||
|
||||
self._alert_text1_label = UnifiedLabel(text="", font_size=ALERT_FONT_BIG, font_weight=FontWeight.DISPLAY, line_height=0.86,
|
||||
letter_spacing=-0.02)
|
||||
@@ -155,6 +159,7 @@ class AlertRenderer(Widget):
|
||||
def _icon_helper(self, alert: Alert) -> AlertLayout:
|
||||
icon_side = None
|
||||
txt_icon = None
|
||||
icon_alpha = 255.0
|
||||
icon_margin_x = 20
|
||||
icon_margin_y = 18
|
||||
|
||||
@@ -191,6 +196,9 @@ class AlertRenderer(Widget):
|
||||
icon_margin_x = 8
|
||||
icon_margin_y = 0
|
||||
|
||||
elif event_name == 'speedLimitPreActive':
|
||||
icon_side, txt_icon, icon_alpha, icon_margin_x, icon_margin_y = SpeedLimitAlertRenderer.speed_limit_pre_active_icon_helper(self)
|
||||
|
||||
else:
|
||||
self._turn_signal_timer = 0.0
|
||||
|
||||
@@ -212,7 +220,7 @@ class AlertRenderer(Widget):
|
||||
text_width,
|
||||
self._rect.height,
|
||||
)
|
||||
icon_layout = IconLayout(txt_icon, icon_side, icon_margin_x, icon_margin_y) if txt_icon is not None and icon_side is not None else None
|
||||
icon_layout = IconLayout(txt_icon, icon_side, icon_margin_x, icon_margin_y, icon_alpha) if txt_icon is not None and icon_side is not None else None
|
||||
return AlertLayout(text_rect, icon_layout)
|
||||
|
||||
def _render(self, rect: rl.Rectangle) -> bool:
|
||||
@@ -235,6 +243,9 @@ class AlertRenderer(Widget):
|
||||
|
||||
self._draw_background(alert)
|
||||
|
||||
# update speed limit UI states
|
||||
SpeedLimitAlertRenderer.update(self)
|
||||
|
||||
alert_layout = self._icon_helper(alert)
|
||||
self._draw_text(alert, alert_layout)
|
||||
self._draw_icons(alert_layout)
|
||||
@@ -257,7 +268,7 @@ class AlertRenderer(Widget):
|
||||
pos_x = int(self._rect.x + self._rect.width - alert_layout.icon.margin_x - alert_layout.icon.texture.width)
|
||||
|
||||
if alert_layout.icon.texture not in (self._txt_turn_signal_left, self._txt_turn_signal_right):
|
||||
icon_alpha = 255
|
||||
icon_alpha = alert_layout.icon.alpha
|
||||
else:
|
||||
icon_alpha = int(min(self._turn_signal_alpha_filter.x, 255))
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ from openpilot.common.constants import CV
|
||||
from openpilot.sunnypilot.selfdrive.selfdrived.events_base import EventsBase, Priority, ET, Alert, \
|
||||
NoEntryAlert, ImmediateDisableAlert, EngagementAlert, NormalPermanentAlert, AlertCallbackType, wrong_car_mode_alert
|
||||
from openpilot.sunnypilot.selfdrive.controls.lib.speed_limit import PCM_LONG_REQUIRED_MAX_SET_SPEED, CONFIRM_SPEED_THRESHOLD
|
||||
|
||||
from openpilot.system.hardware import HARDWARE
|
||||
|
||||
AlertSize = log.SelfdriveState.AlertSize
|
||||
AlertStatus = log.SelfdriveState.AlertStatus
|
||||
@@ -23,6 +23,8 @@ EventNameSP = custom.OnroadEventSP.EventName
|
||||
# get event name from enum
|
||||
EVENT_NAME_SP = {v: k for k, v in EventNameSP.schema.enumerants.items()}
|
||||
|
||||
IS_MICI = HARDWARE.get_device_type() == 'mici'
|
||||
|
||||
|
||||
def speed_limit_adjust_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int, personality) -> Alert:
|
||||
speedLimit = sm['longitudinalPlanSP'].speedLimit.resolver.speedLimit
|
||||
@@ -37,10 +39,14 @@ def speed_limit_adjust_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.
|
||||
|
||||
def speed_limit_pre_active_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int, personality) -> Alert:
|
||||
speed_conv = CV.MS_TO_KPH if metric else CV.MS_TO_MPH
|
||||
v_cruise_cluster = CS.vCruiseCluster
|
||||
set_speed = sm['controlsState'].vCruiseDEPRECATED if v_cruise_cluster == 0.0 else v_cruise_cluster
|
||||
set_speed_conv = round(set_speed * speed_conv)
|
||||
|
||||
speed_limit_final_last = sm['longitudinalPlanSP'].speedLimit.resolver.speedLimitFinalLast
|
||||
speed_limit_final_last_conv = round(speed_limit_final_last * speed_conv)
|
||||
alert_1_str = ""
|
||||
alert_size = AlertSize.none
|
||||
alert_size = AlertSize.small
|
||||
|
||||
if CP.openpilotLongitudinalControl and CP.pcmCruise:
|
||||
# PCM long
|
||||
@@ -50,7 +56,14 @@ def speed_limit_pre_active_alert(CP: car.CarParams, CS: car.CarState, sm: messag
|
||||
speed_unit = "km/h" if metric else "mph"
|
||||
|
||||
alert_1_str = f"Speed Limit Assist: set to {pcm_long_required_max_set_speed_conv} {speed_unit} to engage"
|
||||
alert_size = AlertSize.small
|
||||
else:
|
||||
if IS_MICI:
|
||||
if set_speed_conv < speed_limit_final_last_conv:
|
||||
alert_1_str = "Press + to confirm speed limit"
|
||||
elif set_speed_conv > speed_limit_final_last_conv:
|
||||
alert_1_str = "Press - to confirm speed limit"
|
||||
else:
|
||||
alert_size = AlertSize.none
|
||||
|
||||
return Alert(
|
||||
alert_1_str,
|
||||
|
||||
Reference in New Issue
Block a user