diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 6b70c63..3347258 100644 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -71,6 +71,7 @@ class Controls: self.frogpilot_toggles = FrogPilotVariables.toggles self.drive_added = False + self.onroad_distance_pressed = False self.openpilot_crashed_triggered = False self.display_timer = 0 @@ -681,12 +682,13 @@ class Controls: # decrement personality on distance button press if self.CP.openpilotLongitudinalControl: - if any(not be.pressed and be.type == ButtonType.gapAdjustCruise for be in CS.buttonEvents): + if any(not be.pressed and be.type == ButtonType.gapAdjustCruise for be in CS.buttonEvents) or self.onroad_distance_pressed: menu_open = self.display_timer > 0 or self.CP.carName != "gm" or not self.sm['frogpilotCarState'].hasCamera - if menu_open: + if not self.params_memory.get_bool("OnroadDistanceButtonPressed") and menu_open: self.personality = (self.personality - 1) % 3 self.params.put_nonblocking('LongitudinalPersonality', str(self.personality)) self.display_timer = 350 + self.onroad_distance_pressed = self.params_memory.get_bool("OnroadDistanceButtonPressed") self.display_timer -= 1 diff --git a/selfdrive/frogpilot/assets/other_images/aggressive.png b/selfdrive/frogpilot/assets/other_images/aggressive.png new file mode 100644 index 0000000..42d0055 Binary files /dev/null and b/selfdrive/frogpilot/assets/other_images/aggressive.png differ diff --git a/selfdrive/frogpilot/assets/other_images/aggressive_kaofui.png b/selfdrive/frogpilot/assets/other_images/aggressive_kaofui.png new file mode 100644 index 0000000..52da0a4 Binary files /dev/null and b/selfdrive/frogpilot/assets/other_images/aggressive_kaofui.png differ diff --git a/selfdrive/frogpilot/assets/other_images/relaxed.png b/selfdrive/frogpilot/assets/other_images/relaxed.png new file mode 100644 index 0000000..fb77ec3 Binary files /dev/null and b/selfdrive/frogpilot/assets/other_images/relaxed.png differ diff --git a/selfdrive/frogpilot/assets/other_images/relaxed_kaofui.png b/selfdrive/frogpilot/assets/other_images/relaxed_kaofui.png new file mode 100644 index 0000000..897ad3d Binary files /dev/null and b/selfdrive/frogpilot/assets/other_images/relaxed_kaofui.png differ diff --git a/selfdrive/frogpilot/assets/other_images/standard.png b/selfdrive/frogpilot/assets/other_images/standard.png new file mode 100644 index 0000000..57c5a67 Binary files /dev/null and b/selfdrive/frogpilot/assets/other_images/standard.png differ diff --git a/selfdrive/frogpilot/assets/other_images/standard_kaofui.png b/selfdrive/frogpilot/assets/other_images/standard_kaofui.png new file mode 100644 index 0000000..481e257 Binary files /dev/null and b/selfdrive/frogpilot/assets/other_images/standard_kaofui.png differ diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index 7cb9fac..41bbc22 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -544,6 +544,7 @@ void AnnotatedCameraWidget::drawDriverState(QPainter &painter, const UIState *s) // base icon int offset = UI_BORDER_SIZE + btn_size / 2; int x = rightHandDM ? width() - offset : offset; + x += onroadDistanceButton ? 250 : 0; offset += showAlwaysOnLateralStatusBar || showConditionalExperimentalStatusBar ? 25 : 0; int y = height() - offset; float opacity = dmActive ? 0.65 : 0.2; @@ -719,6 +720,9 @@ void AnnotatedCameraWidget::showEvent(QShowEvent *event) { void AnnotatedCameraWidget::initializeFrogPilotWidgets() { bottom_layout = new QHBoxLayout(); + distance_btn = new DistanceButton(this); + bottom_layout->addWidget(distance_btn); + QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); bottom_layout->addItem(spacer); @@ -758,6 +762,8 @@ void AnnotatedCameraWidget::updateFrogPilotWidgets() { experimentalMode = scene.experimental_mode; mapOpen = scene.map_open; + + onroadDistanceButton = scene.onroad_distance_button; } void AnnotatedCameraWidget::paintFrogPilotWidgets(QPainter &p) { @@ -765,6 +771,13 @@ void AnnotatedCameraWidget::paintFrogPilotWidgets(QPainter &p) { drawStatusBar(p); } + bool enableDistanceButton = onroadDistanceButton && !hideBottomIcons; + distance_btn->setVisible(enableDistanceButton); + if (enableDistanceButton) { + distance_btn->updateState(); + bottom_layout->setAlignment(distance_btn, (rightHandDM ? Qt::AlignRight : Qt::AlignLeft)); + } + map_settings_btn_bottom->setEnabled(map_settings_btn->isEnabled()); if (map_settings_btn_bottom->isEnabled()) { map_settings_btn_bottom->setVisible(!hideBottomIcons); @@ -772,6 +785,76 @@ void AnnotatedCameraWidget::paintFrogPilotWidgets(QPainter &p) { } } +DistanceButton::DistanceButton(QWidget *parent) : QPushButton(parent), scene(uiState()->scene) { + setFixedSize(btn_size * 1.5, btn_size * 1.5); + + profile_data = { + {QPixmap("../frogpilot/assets/other_images/traffic.png"), "Traffic"}, + {QPixmap("../frogpilot/assets/other_images/aggressive.png"), "Aggressive"}, + {QPixmap("../frogpilot/assets/other_images/standard.png"), "Standard"}, + {QPixmap("../frogpilot/assets/other_images/relaxed.png"), "Relaxed"} + }; + + profile_data_kaofui = { + {QPixmap("../frogpilot/assets/other_images/traffic_kaofui.png"), "Traffic"}, + {QPixmap("../frogpilot/assets/other_images/aggressive_kaofui.png"), "Aggressive"}, + {QPixmap("../frogpilot/assets/other_images/standard_kaofui.png"), "Standard"}, + {QPixmap("../frogpilot/assets/other_images/relaxed_kaofui.png"), "Relaxed"} + }; + + transitionTimer.start(); + + connect(this, &QPushButton::pressed, this, &DistanceButton::buttonPressed); + connect(this, &QPushButton::released, this, &DistanceButton::buttonReleased); +} + +void DistanceButton::buttonPressed() { + paramsMemory.putBool("OnroadDistanceButtonPressed", true); +} + +void DistanceButton::buttonReleased() { + paramsMemory.putBool("OnroadDistanceButtonPressed", false); +} + +void DistanceButton::updateState() { + bool stateChanged = (trafficModeActive != scene.traffic_mode_active) || + (personality != static_cast(scene.personality) && !trafficModeActive); + + if (stateChanged) { + transitionTimer.restart(); + } + + personality = static_cast(scene.personality); + trafficModeActive = scene.traffic_mode_active; +} + +void DistanceButton::paintEvent(QPaintEvent *event) { + QPainter p(this); + p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); + + constexpr qreal fadeDuration = 1000.0; + constexpr qreal textDuration = 3000.0; + int elapsed = transitionTimer.elapsed(); + + qreal textOpacity = qBound(0.0, 1.0 - ((elapsed - textDuration) / fadeDuration), 1.0); + qreal imageOpacity = qBound(0.0, (elapsed - textDuration) / fadeDuration, 1.0); + + int profile = trafficModeActive ? 0 : personality + 1; + auto &[profileImage, profileText] = scene.use_kaofui_icons ? profile_data_kaofui[profile] : profile_data[profile]; + + if (textOpacity > 0.0) { + p.setOpacity(textOpacity); + p.setFont(InterFont(40, QFont::Bold)); + p.setPen(Qt::white); + QRect textRect(-25, 0, width(), height() + 95); + p.drawText(textRect, Qt::AlignCenter, profileText); + } + + if (imageOpacity > 0.0) { + drawIcon(p, QPoint((btn_size / 2) * 1.25, btn_size / 2 + 95), profileImage, Qt::transparent, imageOpacity); + } +} + void AnnotatedCameraWidget::drawStatusBar(QPainter &p) { p.save(); diff --git a/selfdrive/ui/qt/onroad.h b/selfdrive/ui/qt/onroad.h index 27c01bd..aa4aa39 100644 --- a/selfdrive/ui/qt/onroad.h +++ b/selfdrive/ui/qt/onroad.h @@ -34,6 +34,32 @@ private: UIScene &scene; }; +class DistanceButton : public QPushButton { +public: + explicit DistanceButton(QWidget *parent = nullptr); + + void buttonPressed(); + void buttonReleased(); + void updateState(); + +protected: + void paintEvent(QPaintEvent *event) override; + +private: + Params paramsMemory{"/dev/shm/params"}; + + UIScene &scene; + + bool trafficModeActive; + + int personality; + + QElapsedTimer transitionTimer; + + QVector> profile_data; + QVector> profile_data_kaofui; +}; + class ExperimentalButton : public QPushButton { Q_OBJECT @@ -116,11 +142,14 @@ private: Params paramsMemory{"/dev/shm/params"}; UIScene &scene; + DistanceButton *distance_btn; + QHBoxLayout *bottom_layout; bool alwaysOnLateralActive; bool experimentalMode; bool mapOpen; + bool onroadDistanceButton; bool showAlwaysOnLateralStatusBar; bool showConditionalExperimentalStatusBar; diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index e1690b6..8e41cbf 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -268,6 +268,10 @@ void ui_update_frogpilot_params(UIState *s) { scene.conditional_speed = scene.conditional_experimental ? params.getInt("CESpeed") : 0; scene.conditional_speed_lead = scene.conditional_experimental ? params.getInt("CESpeedLead") : 0; scene.show_cem_status_bar = scene.conditional_experimental && !params.getBool("HideCEMStatusBar"); + + bool driving_personalities = scene.longitudinal_control && params.getBool("DrivingPersonalities"); + scene.onroad_distance_button = driving_personalities && params.getBool("OnroadDistanceButton"); + scene.use_kaofui_icons = scene.onroad_distance_button && params.getBool("KaofuiIcons"); } void UIState::updateStatus() { diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 8f9420f..0997c2c 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -188,11 +188,13 @@ typedef struct UIScene { bool experimental_mode; bool map_open; bool online; + bool onroad_distance_button; bool parked; bool right_hand_drive; bool show_aol_status_bar; bool show_cem_status_bar; bool tethering_enabled; + bool use_kaofui_icons; int alert_size; int conditional_speed;