#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("sunnypilot Longitudinal Control (Alpha)"), QString("%1

%2") .arg(tr("WARNING: sunnypilot longitudinal control is in alpha for this car and will disable Automatic Emergency Braking (AEB).")) .arg(tr("On this car, sunnypilot defaults to the car's built-in ACC instead of sunnypilot's longitudinal control. " "Enable this to switch to sunnypilot longitudinal control. Enabling Experimental mode is recommended when enabling sunnypilot 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()) { 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(); 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); }