Files
StarPilot/selfdrive/ui/qt/offroad/developer_panel.cc
T
Discountchubbs 47c8ac2431 ui: Developer Panel Fixes (#688)
* Add error log to developer panel

* Add lang files

* Refactor GitHub runner control to local variable

Replaced the `enableGithubRunner` member variable with a local variable, as it is not used elsewhere in the class. Simplified visibility management for developer panel toggles in release branches.

* Modifying visibility rules for developer panel controls

This commit modifies the visibility settings for controls within the developer panel such as `enableGithubRunner`, `errorLogBtn`, `joystickToggle` and `longManeuverToggle`. The visibility of these controls is now dependent on whether the software is running in release mode. This update ensures that certain settings are hidden from the end user in the release version, enhancing the user interface by simplifying it and preventing potential user confusion.

* Translation files

* we already handle this in stock

---------

Co-authored-by: DevTekVE <devtekve@gmail.com>
Co-authored-by: Jason Wen <haibin.wen3@gmail.com>
2025-03-19 19:16:54 -04:00

134 lines
5.5 KiB
C++

#include "selfdrive/ui/qt/offroad/developer_panel.h"
#include "selfdrive/ui/qt/widgets/ssh_keys.h"
#ifdef SUNNYPILOT
#include "selfdrive/ui/sunnypilot/qt/widgets/controls.h"
#else
#include "selfdrive/ui/qt/widgets/controls.h"
#endif
DeveloperPanel::DeveloperPanel(SettingsWindow *parent) : ListWidget(parent) {
adbToggle = new ParamControl("AdbEnabled", tr("Enable ADB"),
tr("ADB (Android Debug Bridge) allows connecting to your device over USB or over the network. See https://docs.comma.ai/how-to/connect-to-comma for more info."), "");
addItem(adbToggle);
// SSH keys
addItem(new SshToggle());
addItem(new SshControl());
joystickToggle = new ParamControl("JoystickDebugMode", tr("Joystick Debug Mode"), "", "");
QObject::connect(joystickToggle, &ParamControl::toggleFlipped, [=](bool state) {
params.putBool("LongitudinalManeuverMode", false);
longManeuverToggle->refresh();
});
addItem(joystickToggle);
longManeuverToggle = new ParamControl("LongitudinalManeuverMode", tr("Longitudinal Maneuver Mode"), "", "");
QObject::connect(longManeuverToggle, &ParamControl::toggleFlipped, [=](bool state) {
params.putBool("JoystickDebugMode", false);
joystickToggle->refresh();
});
addItem(longManeuverToggle);
experimentalLongitudinalToggle = new ParamControl(
"ExperimentalLongitudinalEnabled",
tr("openpilot Longitudinal Control (Alpha)"),
QString("<b>%1</b><br><br>%2")
.arg(tr("WARNING: openpilot longitudinal control is in alpha for this car and will disable Automatic Emergency Braking (AEB)."))
.arg(tr("On this car, openpilot defaults to the car's built-in ACC instead of openpilot's longitudinal control. "
"Enable this to switch to openpilot longitudinal control. Enabling Experimental mode is recommended when enabling openpilot longitudinal control alpha.")),
""
);
experimentalLongitudinalToggle->setConfirmation(true, false);
QObject::connect(experimentalLongitudinalToggle, &ParamControl::toggleFlipped, [=]() {
updateToggles(offroad);
});
addItem(experimentalLongitudinalToggle);
// TODO-SP: Move to Vehicles panel when ported back
hyundaiRadarTracksToggle = new ParamControl(
"HyundaiRadarTracksToggle",
tr("Hyundai: Enable Radar Tracks"),
tr("Enable this to attempt to enable radar tracks for Hyundai, Kia, and Genesis models equipped with the supported Mando SCC radar. "
"This allows sunnypilot to use radar data for improved lead tracking and overall longitudinal performance."), "");
hyundaiRadarTracksToggle->setConfirmation(true, false);
QObject::connect(hyundaiRadarTracksToggle, &ParamControl::toggleFlipped, [=](bool state) {
updateToggles(offroad);
});
addItem(hyundaiRadarTracksToggle);
enableGithubRunner = new ParamControl("EnableGithubRunner", tr("Enable GitHub runner service"), tr("Enables or disables the github runner service."), "");
addItem(enableGithubRunner);
// error log button
errorLogBtn = new ButtonControl(tr("Error Log"), tr("VIEW"), tr("View the error log for sunnypilot crashes."));
connect(errorLogBtn, &ButtonControl::clicked, [=]() {
std::string txt = util::read_file("/data/community/crashes/error.log");
ConfirmationDialog::rich(QString::fromStdString(txt), this);
});
addItem(errorLogBtn);
// Joystick and longitudinal maneuvers should be hidden on release branches
is_release = params.getBool("IsReleaseBranch");
// Toggles should be not available to change in onroad state
QObject::connect(uiState(), &UIState::offroadTransition, this, &DeveloperPanel::updateToggles);
}
void DeveloperPanel::updateToggles(bool _offroad) {
for (auto btn : findChildren<ParamControl *>()) {
btn->setVisible(!is_release);
/*
* experimentalLongitudinalToggle should be toggelable when:
* - visible, and
* - during onroad & offroad states
*/
if (btn != experimentalLongitudinalToggle) {
btn->setEnabled(_offroad);
}
}
// longManeuverToggle and experimentalLongitudinalToggle should not be toggleable if the car does not have longitudinal control
auto cp_bytes = params.get("CarParamsPersistent");
if (!cp_bytes.empty()) {
AlignedBuffer aligned_buf;
capnp::FlatArrayMessageReader cmsg(aligned_buf.align(cp_bytes.data(), cp_bytes.size()));
cereal::CarParams::Reader CP = cmsg.getRoot<cereal::CarParams>();
auto hyundai = CP.getBrand() == "hyundai";
auto hyundai_mando_radar = hyundai && (CP.getFlags() & 4096);
if (!CP.getExperimentalLongitudinalAvailable() || is_release) {
params.remove("ExperimentalLongitudinalEnabled");
experimentalLongitudinalToggle->setEnabled(false);
}
/*
* experimentalLongitudinalToggle should be visible when:
* - is not a release branch, and
* - the car supports experimental longitudinal control (alpha)
*/
experimentalLongitudinalToggle->setVisible(CP.getExperimentalLongitudinalAvailable() && !is_release);
longManeuverToggle->setEnabled(hasLongitudinalControl(CP) && _offroad);
hyundaiRadarTracksToggle->setVisible(hyundai_mando_radar && hasLongitudinalControl(CP));
} else {
longManeuverToggle->setEnabled(false);
experimentalLongitudinalToggle->setVisible(false);
hyundaiRadarTracksToggle->setVisible(false);
}
experimentalLongitudinalToggle->refresh();
// Handle specific controls visibility for release branches
enableGithubRunner->setVisible(!is_release);
errorLogBtn->setVisible(!is_release);
joystickToggle->setVisible(!is_release);
offroad = _offroad;
}
void DeveloperPanel::showEvent(QShowEvent *event) {
updateToggles(offroad);
}