diff --git a/common/params.cc b/common/params.cc index 559b5bc..7287938 100644 --- a/common/params.cc +++ b/common/params.cc @@ -297,6 +297,8 @@ std::unordered_map keys = { {"RefuseVolume", PERSISTENT}, {"RelaxedFollow", PERSISTENT}, {"RelaxedJerk", PERSISTENT}, + {"ReverseCruise", PERSISTENT}, + {"ReverseCruiseUI", PERSISTENT}, {"RoadEdgesWidth", PERSISTENT}, {"SilentMode", PERSISTENT}, {"ShowCPU", PERSISTENT}, diff --git a/selfdrive/car/toyota/toyotacan.py b/selfdrive/car/toyota/toyotacan.py index ab25797..6d74e75 100644 --- a/selfdrive/car/toyota/toyotacan.py +++ b/selfdrive/car/toyota/toyotacan.py @@ -43,7 +43,7 @@ def create_accel_command(packer, accel, accel_raw, pcm_cancel, standstill_req, l "PERMIT_BRAKING": 1, "RELEASE_STANDSTILL": not standstill_req, "CANCEL_REQ": pcm_cancel, - "ALLOW_LONG_PRESS": 1, + "ALLOW_LONG_PRESS": 2 if frogpilot_variables.reverse_cruise_increase else 1, "ACC_CUT_IN": fcw_alert, # only shown when ACC enabled "ACCEL_CMD_ALT": accel_raw, # raw accel command, pcm uses this to calculate a compensatory force } diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 725c388..6e5e1f7 100644 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -606,7 +606,7 @@ class Controls: def state_transition(self, CS): """Compute conditional state transitions and execute actions on state transitions""" - self.v_cruise_helper.update_v_cruise(CS, self.enabled, self.is_metric) + self.v_cruise_helper.update_v_cruise(CS, self.enabled, self.is_metric, self.frogpilot_variables) # decrement the soft disable timer at every step, as it's reset on # entrance in SOFT_DISABLING state @@ -1062,6 +1062,7 @@ class Controls: self.frogpilot_variables.sport_plus = longitudinal_tune and self.params.get_int("AccelerationProfile") == 3 quality_of_life = self.params.get_bool("QOLControls") + self.frogpilot_variables.reverse_cruise_increase = quality_of_life and self.params.get_bool("ReverseCruise") def main(): controls = Controls() diff --git a/selfdrive/controls/lib/drive_helpers.py b/selfdrive/controls/lib/drive_helpers.py index 7324373..ac967f2 100644 --- a/selfdrive/controls/lib/drive_helpers.py +++ b/selfdrive/controls/lib/drive_helpers.py @@ -52,13 +52,13 @@ class VCruiseHelper: def v_cruise_initialized(self): return self.v_cruise_kph != V_CRUISE_UNSET - def update_v_cruise(self, CS, enabled, is_metric): + def update_v_cruise(self, CS, enabled, is_metric, frogpilot_variables): self.v_cruise_kph_last = self.v_cruise_kph if CS.cruiseState.available: if not self.CP.pcmCruise: # if stock cruise is completely disabled, then we can use our own set speed logic - self._update_v_cruise_non_pcm(CS, enabled, is_metric) + self._update_v_cruise_non_pcm(CS, enabled, is_metric, frogpilot_variables) self.v_cruise_cluster_kph = self.v_cruise_kph self.update_button_timers(CS, enabled) else: @@ -68,7 +68,7 @@ class VCruiseHelper: self.v_cruise_kph = V_CRUISE_UNSET self.v_cruise_cluster_kph = V_CRUISE_UNSET - def _update_v_cruise_non_pcm(self, CS, enabled, is_metric): + def _update_v_cruise_non_pcm(self, CS, enabled, is_metric, frogpilot_variables): # handle button presses. TODO: this should be in state_control, but a decelCruise press # would have the effect of both enabling and changing speed is checked after the state transition if not enabled: @@ -92,6 +92,10 @@ class VCruiseHelper: long_press = True break + # Reverse the long press value for reverse cruise increase + if frogpilot_variables.reverse_cruise_increase: + long_press = not long_press + if button_type is None: return diff --git a/selfdrive/frogpilot/ui/control_settings.cc b/selfdrive/frogpilot/ui/control_settings.cc index ab72c5f..4db1825 100644 --- a/selfdrive/frogpilot/ui/control_settings.cc +++ b/selfdrive/frogpilot/ui/control_settings.cc @@ -35,6 +35,7 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil {"QOLControls", "Quality of Life", "Miscellaneous quality of life changes to improve your overall openpilot experience.", "../frogpilot/assets/toggle_icons/quality_of_life.png"}, {"DisableOnroadUploads", "Disable Onroad Uploads", "Prevent large data uploads when onroad.", ""}, {"HigherBitrate", "Higher Bitrate Recording", "Increases the quality of the footage uploaded to comma connect.", ""}, + {"ReverseCruise", "Reverse Cruise Increase", "Reverses the 'long press' functionality when increasing the max set speed. Useful to increase the max speed quickly.", ""}, }; for (const auto &[param, title, desc, icon] : controlToggles) { @@ -218,6 +219,10 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil } }); toggle = qolToggle; + } else if (param == "ReverseCruise") { + std::vector reverseCruiseToggles{"ReverseCruiseUI"}; + std::vector reverseCruiseNames{tr("Control Via UI")}; + toggle = new FrogPilotParamToggleControl(param, title, desc, icon, reverseCruiseToggles, reverseCruiseNames); } else { toggle = new ParamControl(param, title, desc, icon, this); diff --git a/selfdrive/frogpilot/ui/control_settings.h b/selfdrive/frogpilot/ui/control_settings.h index e7da1dc..94f1813 100644 --- a/selfdrive/frogpilot/ui/control_settings.h +++ b/selfdrive/frogpilot/ui/control_settings.h @@ -42,7 +42,7 @@ private: std::set lateralTuneKeys = {"ForceAutoTune"}; std::set longitudinalTuneKeys = {"AccelerationProfile", "DecelerationProfile", "AggressiveAcceleration"}; std::set mtscKeys = {}; - std::set qolKeys = {"DisableOnroadUploads", "HigherBitrate"}; + std::set qolKeys = {"DisableOnroadUploads", "HigherBitrate", "ReverseCruise"}; std::set speedLimitControllerKeys = {}; std::set speedLimitControllerControlsKeys = {}; std::set speedLimitControllerQOLKeys = {}; diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index befc361..f30fc3b 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -105,15 +105,27 @@ void OnroadWindow::mousePressEvent(QMouseEvent* e) { // FrogPilot clickable widgets bool widgetClicked = false; + // Change cruise control increments button + QRect maxSpeedRect(7, 25, 225, 225); + bool isMaxSpeedClicked = maxSpeedRect.contains(e->pos()); + // Hide speed button QRect hideSpeedRect(rect().center().x() - 175, 50, 350, 350); bool isSpeedClicked = hideSpeedRect.contains(e->pos()); - if (isSpeedClicked && scene.hide_speed_ui) { - bool currentHideSpeed = scene.hide_speed; + if (isMaxSpeedClicked || isSpeedClicked) { + if (isMaxSpeedClicked && scene.reverse_cruise_ui) { + bool currentReverseCruise = scene.reverse_cruise; - uiState()->scene.hide_speed = !currentHideSpeed; - params.putBoolNonBlocking("HideSpeed", !currentHideSpeed); + uiState()->scene.reverse_cruise = !currentReverseCruise; + params.putBoolNonBlocking("ReverseCruise", !currentReverseCruise); + + } else if (isSpeedClicked && scene.hide_speed_ui) { + bool currentHideSpeed = scene.hide_speed; + + uiState()->scene.hide_speed = !currentHideSpeed; + params.putBoolNonBlocking("HideSpeed", !currentHideSpeed); + } widgetClicked = true; // If the click wasn't for anything specific, change the value of "ExperimentalMode" @@ -483,7 +495,11 @@ void AnnotatedCameraWidget::drawHud(QPainter &p) { int bottom_radius = has_eu_speed_limit ? 100 : 32; QRect set_speed_rect(QPoint(60 + (default_size.width() - set_speed_size.width()) / 2, 45), set_speed_size); - p.setPen(QPen(whiteColor(75), 6)); + if (scene.reverse_cruise) { + p.setPen(QPen(QColor(0, 150, 255), 6)); + } else { + p.setPen(QPen(whiteColor(75), 6)); + } p.setBrush(blackColor(166)); drawRoundedRect(p, set_speed_rect, top_radius, top_radius, bottom_radius, bottom_radius); diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 19d7a94..41d3632 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -319,6 +319,8 @@ void ui_update_frogpilot_params(UIState *s) { scene.unlimited_road_ui_length = scene.model_ui && params.getBool("UnlimitedLength"); bool quality_of_life_controls = params.getBool("QOLControls"); + scene.reverse_cruise = quality_of_life_controls && params.getBool("ReverseCruise"); + scene.reverse_cruise_ui = scene.reverse_cruise && params.getBool("ReverseCruiseUI"); bool quality_of_life_visuals = params.getBool("QOLVisuals"); scene.full_map = quality_of_life_visuals && params.getBool("FullMap"); diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 476bb9f..5b82005 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -191,6 +191,8 @@ typedef struct UIScene { bool lead_info; bool map_open; bool model_ui; + bool reverse_cruise; + bool reverse_cruise_ui; bool show_driver_camera; bool turn_signal_left; bool turn_signal_right;