mirror of
https://github.com/MoreTore/openpilot.git
synced 2026-08-05 08:16:06 +08:00
type hints for alerts and fix community feature alert (#2196)
* fix startup alert for community features * type hints for alerts * more type hints * fix dashcam only alerts * more type hints
This commit is contained in:
@@ -25,9 +25,6 @@ class CarInterface(CarInterfaceBase):
|
||||
|
||||
ret.radarOffCan = True
|
||||
|
||||
# Mazda port is a community feature for now
|
||||
ret.communityFeature = True
|
||||
|
||||
ret.steerActuatorDelay = 0.1
|
||||
ret.steerRateCost = 1.0
|
||||
ret.steerLimitTimer = 0.8
|
||||
|
||||
@@ -83,7 +83,7 @@ class Controls:
|
||||
|
||||
car_recognized = self.CP.carName != 'mock'
|
||||
# If stock camera is disconnected, we loaded car controls and it's not dashcam mode
|
||||
controller_available = self.CP.enableCamera and self.CI.CC is not None and not passive
|
||||
controller_available = self.CP.enableCamera and self.CI.CC is not None and not passive and not self.CP.dashcamOnly
|
||||
community_feature_disallowed = self.CP.communityFeature and not community_feature_toggle
|
||||
self.read_only = not car_recognized or not controller_available or \
|
||||
self.CP.dashcamOnly or community_feature_disallowed
|
||||
@@ -138,7 +138,7 @@ class Controls:
|
||||
self.events.add(EventName.internetConnectivityNeeded, static=True)
|
||||
if community_feature_disallowed:
|
||||
self.events.add(EventName.communityFeatureDisallowed, static=True)
|
||||
if self.read_only and not passive:
|
||||
if not car_recognized:
|
||||
self.events.add(EventName.carUnrecognized, static=True)
|
||||
if hw_type == HwType.whitePanda:
|
||||
self.events.add(EventName.whitePandaUnsupported, static=True)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from functools import total_ordering
|
||||
from typing import Dict, Union, Callable, Any
|
||||
|
||||
from cereal import log, car
|
||||
import cereal.messaging as messaging
|
||||
from common.realtime import DT_CTRL
|
||||
from selfdrive.config import Conversions as CV
|
||||
from selfdrive.locationd.calibrationd import MIN_SPEED_FILTER
|
||||
@@ -97,18 +99,18 @@ class Events:
|
||||
@total_ordering
|
||||
class Alert:
|
||||
def __init__(self,
|
||||
alert_text_1,
|
||||
alert_text_2,
|
||||
alert_text_1: str,
|
||||
alert_text_2: str,
|
||||
alert_status,
|
||||
alert_size,
|
||||
alert_priority,
|
||||
visual_alert,
|
||||
audible_alert,
|
||||
duration_sound,
|
||||
duration_hud_alert,
|
||||
duration_text,
|
||||
alert_rate=0.,
|
||||
creation_delay=0.):
|
||||
duration_sound: float,
|
||||
duration_hud_alert: float,
|
||||
duration_text: float,
|
||||
alert_rate: float = 0.,
|
||||
creation_delay: float = 0.):
|
||||
|
||||
self.alert_type = ""
|
||||
self.alert_text_1 = alert_text_1
|
||||
@@ -131,14 +133,14 @@ class Alert:
|
||||
tst = car.CarControl.new_message()
|
||||
tst.hudControl.visualAlert = self.visual_alert
|
||||
|
||||
def __str__(self):
|
||||
def __str__(self) -> str:
|
||||
return self.alert_text_1 + "/" + self.alert_text_2 + " " + str(self.alert_priority) + " " + str(
|
||||
self.visual_alert) + " " + str(self.audible_alert)
|
||||
|
||||
def __gt__(self, alert2):
|
||||
def __gt__(self, alert2) -> bool:
|
||||
return self.alert_priority > alert2.alert_priority
|
||||
|
||||
def __eq__(self, alert2):
|
||||
def __eq__(self, alert2) -> bool:
|
||||
return self.alert_priority == alert2.alert_priority
|
||||
|
||||
class NoEntryAlert(Alert):
|
||||
@@ -174,7 +176,7 @@ class EngagementAlert(Alert):
|
||||
|
||||
# ********** alert callback functions **********
|
||||
|
||||
def below_steer_speed_alert(CP, sm, metric):
|
||||
def below_steer_speed_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool) -> Alert:
|
||||
speed = int(round(CP.minSteerSpeed * (CV.MS_TO_KPH if metric else CV.MS_TO_MPH)))
|
||||
unit = "km/h" if metric else "mph"
|
||||
return Alert(
|
||||
@@ -183,7 +185,7 @@ def below_steer_speed_alert(CP, sm, metric):
|
||||
AlertStatus.userPrompt, AlertSize.mid,
|
||||
Priority.MID, VisualAlert.steerRequired, AudibleAlert.none, 0., 0.4, .3)
|
||||
|
||||
def calibration_incomplete_alert(CP, sm, metric):
|
||||
def calibration_incomplete_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool) -> Alert:
|
||||
speed = int(MIN_SPEED_FILTER * (CV.MS_TO_KPH if metric else CV.MS_TO_MPH))
|
||||
unit = "km/h" if metric else "mph"
|
||||
return Alert(
|
||||
@@ -192,7 +194,7 @@ def calibration_incomplete_alert(CP, sm, metric):
|
||||
AlertStatus.normal, AlertSize.mid,
|
||||
Priority.LOWEST, VisualAlert.none, AudibleAlert.none, 0., 0., .2)
|
||||
|
||||
def no_gps_alert(CP, sm, metric):
|
||||
def no_gps_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool) -> Alert:
|
||||
gps_integrated = sm['health'].hwType in [log.HealthData.HwType.uno, log.HealthData.HwType.dos]
|
||||
return Alert(
|
||||
"Poor GPS reception",
|
||||
@@ -200,13 +202,13 @@ def no_gps_alert(CP, sm, metric):
|
||||
AlertStatus.normal, AlertSize.mid,
|
||||
Priority.LOWER, VisualAlert.none, AudibleAlert.none, 0., 0., .2, creation_delay=300.)
|
||||
|
||||
def wrong_car_mode_alert(CP, sm, metric):
|
||||
def wrong_car_mode_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool) -> Alert:
|
||||
text = "Cruise Mode Disabled"
|
||||
if CP.carName == "honda":
|
||||
text = "Main Switch Off"
|
||||
return NoEntryAlert(text, duration_hud_alert=0.)
|
||||
|
||||
EVENTS = {
|
||||
EVENTS: Dict[int, Dict[str, Union[Alert, Callable[[Any, messaging.SubMaster, bool], Alert]]]] = {
|
||||
# ********** events with no alerts **********
|
||||
|
||||
# ********** events only containing alerts displayed in all states **********
|
||||
@@ -287,7 +289,6 @@ EVENTS = {
|
||||
EventName.communityFeatureDisallowed: {
|
||||
# LOW priority to overcome Cruise Error
|
||||
ET.PERMANENT: Alert(
|
||||
"",
|
||||
"Community Feature Detected",
|
||||
"Enable Community Features in Developer Settings",
|
||||
AlertStatus.normal, AlertSize.mid,
|
||||
|
||||
@@ -26,11 +26,11 @@ class TestStartup(unittest.TestCase):
|
||||
|
||||
# community supported car
|
||||
(EventName.startupMaster, HYUNDAI.KIA_STINGER, True),
|
||||
(EventName.startupMaster, HYUNDAI.KIA_STINGER, False),
|
||||
(EventName.communityFeatureDisallowed, HYUNDAI.KIA_STINGER, False),
|
||||
|
||||
# dashcamOnly car
|
||||
(EventName.startupMaster, MAZDA.CX5, True),
|
||||
(EventName.startupMaster, MAZDA.CX5, False),
|
||||
(EventName.startupNoControl, MAZDA.CX5, True),
|
||||
(EventName.startupNoControl, MAZDA.CX5, False),
|
||||
|
||||
# unrecognized car
|
||||
(EventName.startupNoCar, None, True),
|
||||
|
||||
Reference in New Issue
Block a user