mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-04 15:13:58 +08:00
141 lines
5.3 KiB
C++
141 lines
5.3 KiB
C++
#include "frogpilot/ui/qt/offroad/utilities.h"
|
|
|
|
FrogPilotUtilitiesPanel::FrogPilotUtilitiesPanel(FrogPilotSettingsWindow *parent, bool forceOpen) : FrogPilotListWidget(parent), parent(parent) {
|
|
forceOpenDescriptions = forceOpen;
|
|
|
|
ParamControl *debugModeToggle = new ParamControl("DebugMode", tr("Debug Mode"), tr("<b>Use all of FrogPilot's developer metrics on your next drive</b> to diagnose issues and improve bug reports."), "");
|
|
if (forceOpenDescriptions) {
|
|
debugModeToggle->showDescription();
|
|
}
|
|
addItem(debugModeToggle);
|
|
|
|
ButtonControl *flashPandaButton = new ButtonControl(tr("Flash Panda"), tr("FLASH"), tr("<b>Flash the latest, official firmware onto your Panda device</b> to restore core functionality, fix bugs, or ensure you have the most up-to-date software."));
|
|
QObject::connect(flashPandaButton, &ButtonControl::clicked, [parent, flashPandaButton, this]() {
|
|
if (ConfirmationDialog::confirm(tr("Are you sure you want to flash the Panda firmware?"), tr("Flash"), this)) {
|
|
std::thread([parent, flashPandaButton, this]() {
|
|
parent->keepScreenOn = true;
|
|
|
|
flashPandaButton->setEnabled(false);
|
|
flashPandaButton->setValue(tr("Flashing..."));
|
|
|
|
params_memory.putBool("FlashPanda", true);
|
|
while (params_memory.getBool("FlashPanda")) {
|
|
util::sleep_for(UI_FREQ);
|
|
}
|
|
|
|
flashPandaButton->setValue(tr("Flashed!"));
|
|
|
|
util::sleep_for(2500);
|
|
|
|
flashPandaButton->setValue(tr("Rebooting..."));
|
|
|
|
util::sleep_for(2500);
|
|
|
|
Hardware::reboot();
|
|
}).detach();
|
|
}
|
|
});
|
|
if (forceOpenDescriptions) {
|
|
flashPandaButton->showDescription();
|
|
}
|
|
addItem(flashPandaButton);
|
|
|
|
FrogPilotButtonsControl *forceStartedButton = new FrogPilotButtonsControl(tr("Force Drive State"), tr("<b>Force openpilot to be offroad or onroad.</b>"), "", {tr("OFFROAD"), tr("ONROAD"), tr("OFF")}, true);
|
|
QObject::connect(forceStartedButton, &FrogPilotButtonsControl::buttonClicked, [this](int id) {
|
|
if (id == 0) {
|
|
params.putBool("ForceOffroad", true);
|
|
params.putBool("ForceOnroad", false);
|
|
|
|
updateFrogPilotToggles();
|
|
} else if (id == 1) {
|
|
params.put("CarParams", params.get("CarParamsPersistent"));
|
|
params.put("FrogPilotCarParams", params.get("FrogPilotCarParamsPersistent"));
|
|
|
|
params.putBool("ForceOffroad", false);
|
|
params.putBool("ForceOnroad", true);
|
|
|
|
updateFrogPilotToggles();
|
|
} else if (id == 2) {
|
|
params.putBool("ForceOffroad", false);
|
|
params.putBool("ForceOnroad", false);
|
|
|
|
updateFrogPilotToggles();
|
|
}
|
|
});
|
|
forceStartedButton->setCheckedButton(2);
|
|
if (forceOpenDescriptions) {
|
|
forceStartedButton->showDescription();
|
|
}
|
|
addItem(forceStartedButton);
|
|
|
|
ButtonControl *resetTogglesButton = new ButtonControl(tr("Reset Toggles to Default"), tr("RESET"), tr("<b>Reset all toggles to their default values.</b>"));
|
|
QObject::connect(resetTogglesButton, &ButtonControl::clicked, [parent, resetTogglesButton, this]() {
|
|
if (ConfirmationDialog::confirm(tr("Are you sure you want to reset all toggles to their default values?"), tr("Reset"), this)) {
|
|
std::thread([parent, resetTogglesButton, this]() {
|
|
parent->keepScreenOn = true;
|
|
|
|
resetTogglesButton->setEnabled(false);
|
|
resetTogglesButton->setValue(tr("Resetting..."));
|
|
|
|
std::vector<std::string> all_keys = params.allKeys();
|
|
for (const std::string &key : all_keys) {
|
|
if (excluded_keys.count(key)) {
|
|
continue;
|
|
}
|
|
std::optional<std::string> default_value = params.getKeyDefaultValue(key);
|
|
if (default_value.has_value()) {
|
|
params.put(key, default_value.value());
|
|
}
|
|
}
|
|
|
|
updateFrogPilotToggles();
|
|
|
|
resetTogglesButton->setValue(tr("Reset!"));
|
|
|
|
util::sleep_for(2500);
|
|
|
|
resetTogglesButton->setValue("");
|
|
}).detach();
|
|
}
|
|
});
|
|
if (forceOpenDescriptions) {
|
|
resetTogglesButton->showDescription();
|
|
}
|
|
addItem(resetTogglesButton);
|
|
|
|
ButtonControl *resetTogglesButtonStock = new ButtonControl(tr("Reset Toggles to Stock openpilot"), tr("RESET"), tr("<b>Reset all toggles to match stock openpilot.</b>"));
|
|
QObject::connect(resetTogglesButtonStock, &ButtonControl::clicked, [parent, resetTogglesButtonStock, this]() {
|
|
if (ConfirmationDialog::confirm(tr("Are you sure you want to reset all toggles to match stock openpilot?"), tr("Reset"), this)) {
|
|
std::thread([parent, resetTogglesButtonStock, this]() {
|
|
parent->keepScreenOn = true;
|
|
|
|
resetTogglesButtonStock->setEnabled(false);
|
|
resetTogglesButtonStock->setValue(tr("Resetting..."));
|
|
|
|
std::vector<std::string> all_keys = params.allKeys();
|
|
for (const std::string &key : all_keys) {
|
|
if (excluded_keys.count(key)) {
|
|
continue;
|
|
}
|
|
std::optional<std::string> stock_value = params.getStockValue(key);
|
|
if (stock_value.has_value()) {
|
|
params.put(key, stock_value.value());
|
|
}
|
|
}
|
|
|
|
updateFrogPilotToggles();
|
|
|
|
resetTogglesButtonStock->setValue(tr("Reset!"));
|
|
|
|
util::sleep_for(2500);
|
|
|
|
resetTogglesButtonStock->setValue("");
|
|
}).detach();
|
|
}
|
|
});
|
|
if (forceOpenDescriptions) {
|
|
resetTogglesButtonStock->showDescription();
|
|
}
|
|
addItem(resetTogglesButtonStock);
|
|
}
|