mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 03:45:55 +08:00
Enable speed limit settings for Redneck Cruise
This commit is contained in:
@@ -110,7 +110,7 @@ def _owner_rows(params, CP, profile):
|
||||
parked = params.get("IsOffroad") is True
|
||||
profile = Profile(profile) if profile is not None else Profile.COMPACT if HARDWARE.get_device_type() == "mici" else Profile.LARGE
|
||||
context = AuthorityContext(parked, CP, None)
|
||||
owner = FeatureSettingsOwner(params, lambda group: _qualified(context, group),
|
||||
owner = FeatureSettingsOwner(params, lambda group: _qualified(context, group, params=params),
|
||||
vehicle_fingerprint=lambda: str(CP.carFingerprint) if CP is not None else None,
|
||||
vehicle_params=lambda: CP, show_cruise_intervals=True)
|
||||
system_long = bool(CP is not None and CP.openpilotLongitudinalControl)
|
||||
|
||||
@@ -2,13 +2,18 @@
|
||||
|
||||
from dataclasses import replace
|
||||
|
||||
from opendbc.car.hyundai.software_cruise import eligible
|
||||
from opendbc.car.hyundai.software_cruise import eligible, selected
|
||||
from openpilot.starpilot.saved_document import commit_exact
|
||||
from openpilot.starpilot.saved_source import read_saved
|
||||
from openpilot.starpilot.vehicle_selection import read_selection
|
||||
|
||||
KEY = 'RedneckCruise'
|
||||
|
||||
|
||||
def slc_configurable(cp, params):
|
||||
return eligible(cp) and (selected(cp) or (params is not None and read_saved(params, KEY, 8) == (b'1', True)))
|
||||
|
||||
|
||||
def capability(owner):
|
||||
cp = owner.vehicle_params()
|
||||
selection = read_selection(owner.params)
|
||||
|
||||
@@ -99,7 +99,7 @@ class ContextSource(Protocol):
|
||||
def sample(self) -> AuthorityContext: ...
|
||||
|
||||
|
||||
def _qualified(ctx: AuthorityContext, group: str) -> bool:
|
||||
def _qualified(ctx: AuthorityContext, group: str, *, params=None) -> bool:
|
||||
cp = ctx.cp
|
||||
if group == "preferences":
|
||||
return True
|
||||
@@ -126,8 +126,8 @@ def _qualified(ctx: AuthorityContext, group: str) -> bool:
|
||||
if group in ("conditional", "conditional_wheel", "long_output"):
|
||||
return bool((cp.openpilotLongitudinalControl or ctx.configuration_longitudinal) and not cp.notCar and not cp.dashcamOnly and not cp.passive)
|
||||
if group == "slc":
|
||||
from opendbc.car.hyundai.software_cruise import selected as button_cruise_selected
|
||||
return bool((cp.openpilotLongitudinalControl or ctx.configuration_longitudinal or button_cruise_selected(cp)) and
|
||||
from openpilot.starpilot.car.hyundai.software_cruise_settings import slc_configurable
|
||||
return bool((cp.openpilotLongitudinalControl or ctx.configuration_longitudinal or slc_configurable(cp, params)) and
|
||||
not cp.notCar and not cp.dashcamOnly and not cp.passive)
|
||||
if group == "long":
|
||||
return bool((cp.openpilotLongitudinalControl or ctx.configuration_longitudinal) and
|
||||
@@ -558,7 +558,7 @@ class SettingsGateway:
|
||||
if not session_valid():
|
||||
return False
|
||||
fresh = self.context.sample() if live else ctx
|
||||
return fresh.cp_raw == ctx.cp_raw and _qualified(fresh, group)
|
||||
return fresh.cp_raw == ctx.cp_raw and _qualified(fresh, group, params=self.params)
|
||||
return FeatureSettingsOwner(self.params, authorized,
|
||||
learning_messages=lambda: self.context._messages() if isinstance(self.context, LiveContextSource) else None,
|
||||
vehicle_fingerprint=lambda: getattr(current().cp, "carFingerprint", None),
|
||||
|
||||
@@ -155,6 +155,53 @@ class SettingsGatewayTest(unittest.TestCase):
|
||||
self.assertFalse(self.gateway.confirm(intent['intent'], self.session, self.generation))
|
||||
self.assertTrue(self.params.get_bool('AlwaysOnLateral'))
|
||||
|
||||
def test_redneck_cruise_allows_slc_setup_before_next_startup(self):
|
||||
from opendbc.car.hyundai.interface import CarInterface
|
||||
from opendbc.car.hyundai.software_cruise import prepare, selected
|
||||
from opendbc.car.hyundai.values import CAR
|
||||
|
||||
cp = CarInterface.get_non_essential_params(CAR.HYUNDAI_KONA_NON_SCC)
|
||||
raw = cp.as_reader().as_builder().to_bytes()
|
||||
self.context.value = AuthorityContext(True, cp, raw)
|
||||
self.params.put_bool('IsMetric', True, block=True)
|
||||
|
||||
def slc_row(page):
|
||||
return next(i for i, row in enumerate(page['rows']) if row['label'] == 'Speed Limit Controller')
|
||||
|
||||
page = self.page('slc')
|
||||
self.assertFalse(page['rows'][slc_row(page)]['available'])
|
||||
self.params.put_bool('RedneckCruise', True, block=True)
|
||||
page = self.page('slc')
|
||||
index = slc_row(page)
|
||||
self.assertTrue(page['rows'][index]['available'])
|
||||
intent = self.gateway.preview(page['view'], index, 0, self.session, self.generation, value='On')
|
||||
|
||||
self.params.put_bool('RedneckCruise', False, block=True)
|
||||
self.assertFalse(self.gateway.confirm(intent['intent'], self.session, self.generation))
|
||||
self.assertFalse(self.params.get_bool('SpeedLimitController'))
|
||||
|
||||
self.params.put_bool('RedneckCruise', True, block=True)
|
||||
page = self.page('slc')
|
||||
intent = self.gateway.preview(page['view'], slc_row(page), 0, self.session, self.generation, value='On')
|
||||
self.assertTrue(self.gateway.confirm(intent['intent'], self.session, self.generation))
|
||||
self.assertTrue(self.params.get_bool('SpeedLimitController'))
|
||||
self.assertFalse(selected(cp))
|
||||
self.assertFalse(cp.openpilotLongitudinalControl)
|
||||
self.assertEqual(cp.as_reader().as_builder().to_bytes(), raw)
|
||||
|
||||
prepare(cp, True)
|
||||
self.context.value = AuthorityContext(True, cp, cp.as_reader().as_builder().to_bytes())
|
||||
page = self.page('slc')
|
||||
index = next(i for i, row in enumerate(page['rows']) if row['label'].endswith('offset'))
|
||||
self.assertTrue(page['rows'][index]['available'])
|
||||
intent = self.gateway.preview(page['view'], index, 0, self.session, self.generation, value=3)
|
||||
self.assertTrue(self.gateway.confirm(intent['intent'], self.session, self.generation))
|
||||
|
||||
scc = CarInterface.get_non_essential_params(CAR.HYUNDAI_KONA)
|
||||
self.context.value = AuthorityContext(True, scc, scc.to_bytes())
|
||||
page = self.page('slc')
|
||||
self.assertFalse(page['rows'][slc_row(page)]['available'])
|
||||
|
||||
def test_pcm_cruise_long_owner_can_configure_slc_without_custom_cruise_authority(self):
|
||||
cp = self.context.value.cp
|
||||
cp.carFingerprint = "TOYOTA_HIGHLANDER_TSS2"
|
||||
|
||||
@@ -1186,9 +1186,8 @@ class FeatureSettingsOwner:
|
||||
rows.extend(self._cruise_rows(configurable))
|
||||
rows.extend(self.wheel.rows())
|
||||
elif page == FeaturePage.SLC:
|
||||
from opendbc.car.hyundai.software_cruise import selected as button_cruise_selected
|
||||
cp = self.vehicle_params()
|
||||
slc_available = system_long if cp is None else self.longitudinal_available() or button_cruise_selected(cp)
|
||||
slc_available = system_long if cp is None else self.longitudinal_available() or hyundai_software_cruise.slc_configurable(cp, self.params)
|
||||
system_long = slc_available and self.authority("slc")
|
||||
allowed = configurable and system_long
|
||||
offsets_ready, offset_rows = self.slc_offsets.rows(allowed, repair_allowed=parked and allowed)
|
||||
|
||||
@@ -720,8 +720,8 @@ class StarShellSession:
|
||||
from openpilot.starpilot.feature_capabilities import lateral_supported
|
||||
return lateral_supported(cp)
|
||||
if group == "slc":
|
||||
from opendbc.car.hyundai.software_cruise import selected as button_cruise_selected
|
||||
if button_cruise_selected(cp):
|
||||
from openpilot.starpilot.car.hyundai.software_cruise_settings import slc_configurable
|
||||
if slc_configurable(cp, ui_state.params):
|
||||
return True
|
||||
if group in ("conditional", "conditional_wheel", "long_output", "slc"):
|
||||
return bool(cp.openpilotLongitudinalControl and not cp.notCar and not cp.passive and not cp.dashcamOnly)
|
||||
|
||||
@@ -7,6 +7,7 @@ from dataclasses import dataclass
|
||||
import math
|
||||
import threading
|
||||
|
||||
from openpilot.starpilot.car.hyundai.software_cruise_settings import slc_configurable
|
||||
from openpilot.starpilot.speed_limits import offset_document as od
|
||||
from openpilot.starpilot.ui.feature_settings_state import FeatureRow, FeatureSettingsRequest, SLC_OFFSET_KEYS
|
||||
from openpilot.starpilot.saved_source import read_saved
|
||||
@@ -64,12 +65,14 @@ def _whole_limit_cutoff(bound_mps: float, factor: float) -> int:
|
||||
return nearest + (c_float(nearest * factor).value < bound_mps)
|
||||
|
||||
|
||||
def _capability(cp, configuration_longitudinal=False) -> tuple | None:
|
||||
def _capability(cp, configuration_longitudinal=False, *, params=None) -> tuple | None:
|
||||
try:
|
||||
if cp is None or not cp.carFingerprint or not (cp.openpilotLongitudinalControl or configuration_longitudinal) or \
|
||||
cp.notCar or cp.dashcamOnly or cp.passive:
|
||||
if cp is None or not cp.carFingerprint or cp.notCar or cp.dashcamOnly or cp.passive:
|
||||
return None
|
||||
return (str(cp.carFingerprint), bool(cp.openpilotLongitudinalControl or configuration_longitudinal), bool(cp.pcmCruise and not configuration_longitudinal),
|
||||
longitudinal = bool(cp.openpilotLongitudinalControl or configuration_longitudinal)
|
||||
if not longitudinal and not slc_configurable(cp, params):
|
||||
return None
|
||||
return (str(cp.carFingerprint), longitudinal, bool(cp.pcmCruise and not configuration_longitudinal),
|
||||
bool(cp.notCar), bool(cp.dashcamOnly), bool(cp.passive))
|
||||
except (AttributeError, TypeError, ValueError):
|
||||
return None
|
||||
@@ -84,7 +87,7 @@ class SlcOffsetOwner:
|
||||
self.configuration_longitudinal = configuration_longitudinal
|
||||
|
||||
def capability(self) -> tuple | None:
|
||||
return _capability(self.vehicle_params(), self.configuration_longitudinal())
|
||||
return _capability(self.vehicle_params(), self.configuration_longitudinal(), params=self.params)
|
||||
|
||||
def _raw(self, key: str) -> bytes | None:
|
||||
return read_saved(self.params, key, od.MAX_DOCUMENT_BYTES)[0]
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "7a9af272af4b15ee8aabfa88cd87f61639bfc7abe46436dd25309f4a914092a6", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "99e116e45a63154982dec4aa32ffbe28e4933ebc626928e2301a606b740047c2", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user