mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-21 01:42:52 +08:00
Fix DevTekVE's comments
This commit is contained in:
+1
-1
Submodule opendbc_repo updated: 3a89d4932c...ad06564a6b
@@ -109,10 +109,6 @@ class Car:
|
||||
|
||||
self.CI = get_car(*self.can_callbacks, obd_callback(self.params), experimental_long_allowed, num_pandas, cached_params, fixed_fingerprint)
|
||||
sunnypilot_interfaces.setup_car_interface_sp(self.CI.CP, self.CI.CP_SP, self.params)
|
||||
sunnypilot_interfaces.set_hyundai_long_tune_flag(self.CI.CP_SP, self.params)
|
||||
|
||||
if self.CI.CP.brand == 'hyundai':
|
||||
self.CI.apply_longitudinal_tuning()
|
||||
|
||||
self.RI = interfaces[self.CI.CP.carFingerprint].RadarInterface(self.CI.CP, self.CI.CP_SP)
|
||||
self.CP = self.CI.CP
|
||||
|
||||
@@ -13,6 +13,12 @@
|
||||
|
||||
#include "selfdrive/ui/sunnypilot/qt/widgets/scrollview.h"
|
||||
|
||||
enum HyundaiLongTuneOption {
|
||||
Off = 0,
|
||||
LongTune = 1,
|
||||
EvenSmootherBraking = 2,
|
||||
};
|
||||
|
||||
VehiclePanel::VehiclePanel(QWidget *parent) : QFrame(parent) {
|
||||
main_layout = new QStackedLayout(this);
|
||||
ListWidget *list = new ListWidget(this);
|
||||
@@ -24,9 +30,10 @@ VehiclePanel::VehiclePanel(QWidget *parent) : QFrame(parent) {
|
||||
platformSelector = new PlatformSelector();
|
||||
list->addItem(platformSelector);
|
||||
|
||||
// Use updateUI() on offroad transition.
|
||||
QObject::connect(uiState(), &UIState::offroadTransition, this, [=](bool offroad_transition) {
|
||||
updateToggles(offroad_transition);
|
||||
updatePanel(offroad_transition);
|
||||
offroad = offroad_transition;
|
||||
updateUI();
|
||||
});
|
||||
|
||||
ScrollViewSP *scroller = new ScrollViewSP(list, this);
|
||||
@@ -40,9 +47,9 @@ VehiclePanel::VehiclePanel(QWidget *parent) : QFrame(parent) {
|
||||
hkgtuningToggle = new ButtonParamControlSP(
|
||||
"HyundaiLongTune",
|
||||
tr("HKG Custom Longitudinal Tuning"),
|
||||
tr("Select a tuning mode. 'Off' means there is no custom tuning is currently applied. "
|
||||
"'Long Tune' is a dynamic acceleration/brake tune individualized to your specific car. "
|
||||
"'Tune + Smoother Braking' is the dynamic tuning but with even smoother braking applied."),
|
||||
tr("Select a tuning mode. 'Off' means no custom tuning is applied. "
|
||||
"'Long Tune' is a dynamic acceleration/brake tune individualized to your car. "
|
||||
"'Tune + Smoother Braking' is the dynamic tuning with even smoother braking."),
|
||||
"../assets/offroad/icon_shell.png",
|
||||
tuning_buttons
|
||||
);
|
||||
@@ -51,9 +58,8 @@ VehiclePanel::VehiclePanel(QWidget *parent) : QFrame(parent) {
|
||||
|
||||
connect(hkgtuningToggle, &ButtonParamControlSP::buttonToggled, this, [=](int index) {
|
||||
hkg_state = index;
|
||||
// Inline update of tuning and braking params
|
||||
params.put("HyundaiLongTune", QString::number(index).toStdString());
|
||||
params.put("HyundaiSmootherBraking", (index == 2) ? "1" : "0");
|
||||
params.putBool("HyundaiSmootherBraking", index == EvenSmootherBraking);
|
||||
updateCarToggles();
|
||||
});
|
||||
|
||||
@@ -64,8 +70,14 @@ VehiclePanel::VehiclePanel(QWidget *parent) : QFrame(parent) {
|
||||
main_layout->addWidget(vehicleScreen);
|
||||
}
|
||||
|
||||
void VehiclePanel::showEvent(QShowEvent *event) {
|
||||
void VehiclePanel::updateUI() {
|
||||
updatePanel(offroad);
|
||||
updateCarToggles();
|
||||
}
|
||||
|
||||
void VehiclePanel::showEvent(QShowEvent *event) {
|
||||
QFrame::showEvent(event);
|
||||
updateUI();
|
||||
}
|
||||
|
||||
void VehiclePanel::updatePanel(bool _offroad) {
|
||||
@@ -73,79 +85,30 @@ void VehiclePanel::updatePanel(bool _offroad) {
|
||||
offroad = _offroad;
|
||||
}
|
||||
|
||||
void VehiclePanel::updateToggles(bool offroad_transition) {
|
||||
updatePanel(offroad_transition);
|
||||
updateCarToggles();
|
||||
}
|
||||
|
||||
VehiclePanel::ToggleState VehiclePanel::getToggleState(bool hasOpenpilotLong) const {
|
||||
if (!hasOpenpilotLong) {
|
||||
return ToggleState::DISABLED_LONGITUDINAL;
|
||||
}
|
||||
if (!uiState()->scene.started) {
|
||||
return ToggleState::ENABLED;
|
||||
}
|
||||
return ToggleState::DISABLED_DRIVING;
|
||||
}
|
||||
|
||||
void VehiclePanel::updateToggleState(AbstractControlSP* toggle, bool hasOpenpilotLong) {
|
||||
static const QString LONGITUDINAL_MSG = tr("Enable openpilot longitudinal control first.");
|
||||
static const QString DRIVING_MSG = tr("Cannot modify while driving. Please go offroad mode first.");
|
||||
|
||||
ToggleState state = getToggleState(hasOpenpilotLong);
|
||||
|
||||
switch (state) {
|
||||
case ToggleState::ENABLED:
|
||||
toggle->setDescription(toggle->property("originalDesc").toString());
|
||||
break;
|
||||
case ToggleState::DISABLED_LONGITUDINAL: {
|
||||
QString msg = "<font color='orange'>" + tr("Enable openpilot longitudinal control first to modify this setting.") + "</font>";
|
||||
toggle->setDescription(msg);
|
||||
toggle->showDescription();
|
||||
break;
|
||||
}
|
||||
case ToggleState::DISABLED_DRIVING: {
|
||||
QString msg = "<font color='orange'>" + tr("Cannot modify while driving. Please go offroad mode first.") + "</font>";
|
||||
toggle->setDescription(msg);
|
||||
toggle->showDescription();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VehiclePanel::handleToggleAction(AbstractControlSP* toggle, bool checked) {
|
||||
bool hasOpenpilotLong = params.getBool("ExperimentalLongitudinalEnabled");
|
||||
|
||||
// Only apply changes if all conditions are met
|
||||
toggle->setEnabled(true);
|
||||
params.putBool(toggle->objectName().toStdString(), checked);
|
||||
updateToggleState(toggle, hasOpenpilotLong);
|
||||
updatePanel(offroad);
|
||||
}
|
||||
|
||||
void VehiclePanel::updateCarToggles() {
|
||||
bool hasOpenpilotLong = params.getBool("ExperimentalLongitudinalEnabled");
|
||||
|
||||
// Pre-stage vehicle information
|
||||
QString platform = platformSelector->getPlatformBundle("platform").toString();
|
||||
bool openpilotLong = params.getBool("ExperimentalLongitudinalEnabled");
|
||||
QString brand = platformSelector->getPlatformBundle("brand").toString();
|
||||
QString make = platformSelector->getPlatformBundle("make").toString();
|
||||
QString model = platformSelector->getPlatformBundle("model").toString();
|
||||
|
||||
if (brand == "hyundai") {
|
||||
hkgtuningToggle->setVisible(true);
|
||||
hkgtuningToggle->setEnabled(true);
|
||||
QString tuning = QString::fromStdString(params.get("HyundaiLongTune"));
|
||||
QString braking = QString::fromStdString(params.get("HyundaiSmootherBraking"));
|
||||
hkg_state = (tuning == "2") ? 2 : ((tuning == "1") ? ((braking == "1") ? 2 : 1) : 0);
|
||||
updateToggleState(hkgtuningToggle, hasOpenpilotLong);
|
||||
// Set enabled state/description based on openpilotLong
|
||||
hkgtuningToggle->setEnabled(openpilotLong);
|
||||
hkgtuningToggle->setDescription(openpilotLong ?
|
||||
hkgtuningToggle->property("originalDesc").toString() :
|
||||
tr("Enable openpilot longitudinal control first."));
|
||||
// If not enabled, show disabled description.
|
||||
if (!openpilotLong) {
|
||||
hkgtuningToggle->showDescription();
|
||||
return;
|
||||
}
|
||||
int tuningOption = QString::fromStdString(params.get("HyundaiLongTune")).toInt();
|
||||
hkg_state = tuningOption; // Off=0, LongTune=1, EvenSmootherBraking=2
|
||||
hkgtuningToggle->setCheckedButton(hkg_state);
|
||||
hkgtuningToggle->setDescription(hkgtuningToggle->property("originalDesc").toString());
|
||||
hkgtuningToggle->showDescription();
|
||||
} else {
|
||||
// Reset if not Hyundai
|
||||
// Hide toggle if not hyundai.
|
||||
params.put("HyundaiLongTune", "0");
|
||||
params.put("HyundaiSmootherBraking", "0");
|
||||
params.putBool("HyundaiSmootherBraking", false);
|
||||
hkgtuningToggle->setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/settings.h"
|
||||
|
||||
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/vehicle/platform_selector.h"
|
||||
|
||||
class VehiclePanel : public QFrame {
|
||||
@@ -17,12 +16,6 @@ class VehiclePanel : public QFrame {
|
||||
public:
|
||||
explicit VehiclePanel(QWidget *parent = nullptr);
|
||||
void showEvent(QShowEvent *event) override;
|
||||
// Toggle states
|
||||
enum class ToggleState {
|
||||
ENABLED,
|
||||
DISABLED_LONGITUDINAL,
|
||||
DISABLED_DRIVING
|
||||
};
|
||||
public slots:
|
||||
void updatePanel(bool _offroad);
|
||||
|
||||
@@ -31,7 +24,6 @@ private:
|
||||
QStackedLayout* main_layout = nullptr;
|
||||
QWidget* vehicleScreen = nullptr;
|
||||
PlatformSelector *platformSelector = nullptr;
|
||||
// Tuning control using ButtonParamControlSP with the buttonToggled signal.
|
||||
ButtonParamControlSP* hkgtuningToggle = nullptr;
|
||||
bool offroad;
|
||||
|
||||
@@ -39,12 +31,7 @@ private:
|
||||
Params params;
|
||||
int hkg_state = 0;
|
||||
|
||||
// Helper methods
|
||||
ToggleState getToggleState(bool hasOpenpilotLong) const;
|
||||
void updateToggleState(AbstractControlSP* toggle, bool hasOpenpilotLong);
|
||||
|
||||
private slots:
|
||||
void updateUI();
|
||||
void updateCarToggles();
|
||||
void updateToggles(bool offroad_transition);
|
||||
void handleToggleAction(AbstractControlSP* toggle, bool checked);
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors.
|
||||
This file is part of sunnypilot and is licensed under the MIT License.
|
||||
See the LICENSE.md file in the root directory for more details.
|
||||
"""
|
||||
|
||||
from enum import Enum
|
||||
from opendbc.car import Bus, structs
|
||||
from opendbc.car.can_definitions import CanRecvCallable, CanSendCallable
|
||||
from opendbc.car.car_helpers import can_fingerprint
|
||||
@@ -19,6 +19,11 @@ from openpilot.sunnypilot.selfdrive.controls.lib.nnlc.helpers import get_nn_mode
|
||||
import openpilot.system.sentry as sentry
|
||||
|
||||
|
||||
class HyundaiLongTuneOption(Enum):
|
||||
LONG_TUNING = "1"
|
||||
LONG_TUNING_ALT = "2"
|
||||
|
||||
|
||||
def log_fingerprint(CP: structs.CarParams) -> None:
|
||||
if CP.carFingerprint == "MOCK":
|
||||
sentry.capture_fingerprint_mock()
|
||||
@@ -51,6 +56,17 @@ def setup_car_interface_sp(CP: structs.CarParams, CP_SP: structs.CarParamsSP, pa
|
||||
if params is None:
|
||||
params = Params()
|
||||
|
||||
if CP.brand == 'hyundai':
|
||||
tuning_option_str = params.get("HyundaiLongTune")
|
||||
try:
|
||||
tuning_option = HyundaiLongTuneOption(tuning_option_str)
|
||||
except ValueError:
|
||||
tuning_option = None
|
||||
if tuning_option is not None:
|
||||
CP_SP.flags |= HyundaiFlagsSP.HKGLONGTUNING.value
|
||||
if params.get_bool("HyundaiSmootherBraking"):
|
||||
CP_SP.flags |= HyundaiFlagsSP.HKGLONGTUNING_BRAKING.value
|
||||
|
||||
if CP.brand == 'hyundai':
|
||||
if CP.flags & HyundaiFlags.MANDO_RADAR and CP.radarUnavailable:
|
||||
# Having this automatic without a toggle causes a weird process replay diff because
|
||||
@@ -63,20 +79,6 @@ def setup_car_interface_sp(CP: structs.CarParams, CP_SP: structs.CarParamsSP, pa
|
||||
initialize_neural_network_lateral_control(CP, CP_SP, params)
|
||||
|
||||
|
||||
def set_hyundai_long_tune_flag(CP_SP: structs.CarParamsSP, params):
|
||||
val = params.get("HyundaiLongTune")
|
||||
if isinstance(val, bytes):
|
||||
val = val.decode("utf-8")
|
||||
if isinstance(val, str) and ',' in val:
|
||||
val_list = [v.strip() for v in val.split(',')]
|
||||
else:
|
||||
val_list = [val]
|
||||
|
||||
if any(item in ["1", "2"] for item in val_list):
|
||||
CP_SP.flags |= HyundaiFlagsSP.HKGLONGTUNING.value
|
||||
if params.get_bool("HyundaiSmootherBraking"):
|
||||
CP_SP.flags |= HyundaiFlagsSP.HKGLONGTUNING_BRAKING.value
|
||||
|
||||
def initialize_car_interface_sp(CP: structs.CarParams, CP_SP: structs.CarParamsSP, params, can_recv: CanRecvCallable,
|
||||
can_send: CanSendCallable):
|
||||
if CP.brand == 'hyundai':
|
||||
|
||||
Reference in New Issue
Block a user