mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-02-20 11:23:56 +08:00
add recover mode to factory resetter (#21492)
* recover mode * clean up * less margin * use inter * little nicer Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
@@ -2,82 +2,89 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
#include "selfdrive/ui/qt/qt_window.h"
|
||||
#include "selfdrive/ui/qt/setup/reset.h"
|
||||
|
||||
#define USERDATA "/dev/disk/by-partlabel/userdata"
|
||||
#define NVME "/dev/nvme0n1"
|
||||
#define USERDATA "/dev/disk/by-partlabel/userdata"
|
||||
|
||||
bool do_reset() {
|
||||
void Reset::doReset() {
|
||||
std::vector<const char*> cmds = {
|
||||
"sudo umount " NVME,
|
||||
"yes | sudo mkfs.ext4 " NVME,
|
||||
"sudo umount " USERDATA,
|
||||
"sudo umount " NVME " || true",
|
||||
"yes | sudo mkfs.ext4 " NVME " || true",
|
||||
"sudo umount " USERDATA " || true",
|
||||
"yes | sudo mkfs.ext4 " USERDATA,
|
||||
"sudo reboot",
|
||||
};
|
||||
|
||||
for (auto &cmd : cmds) {
|
||||
int ret = std::system(cmd);
|
||||
if (ret != 0) return false;
|
||||
if (ret != 0) {
|
||||
body->setText("Reset failed. Reboot to try again.");
|
||||
rebootBtn->show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
QApplication a(argc, argv);
|
||||
QWidget window;
|
||||
setMainWindow(&window);
|
||||
void Reset::confirm() {
|
||||
const QString confirm_txt = "Are you sure you want to reset your device?";
|
||||
if (body->text() != confirm_txt) {
|
||||
body->setText(confirm_txt);
|
||||
} else {
|
||||
body->setText("Resetting device...");
|
||||
rejectBtn->hide();
|
||||
rebootBtn->hide();
|
||||
confirmBtn->hide();
|
||||
#ifdef __aarch64__
|
||||
QTimer::singleShot(100, this, &Reset::doReset);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(&window);
|
||||
main_layout->setContentsMargins(125, 125, 125, 125);
|
||||
Reset::Reset(bool recover, QWidget *parent) : QWidget(parent) {
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||
main_layout->setContentsMargins(100, 100, 100, 100);
|
||||
|
||||
QLabel *title = new QLabel("System Reset");
|
||||
title->setStyleSheet(R"(
|
||||
font-weight: 500;
|
||||
font-size: 100px;
|
||||
)");
|
||||
title->setStyleSheet(R"(font-weight: 500; font-size: 100px;)");
|
||||
main_layout->addWidget(title, 0, Qt::AlignTop);
|
||||
|
||||
QLabel *body = new QLabel("System reset triggered. Press confirm to erase all content and settings. Press cancel to resume boot.");
|
||||
body = new QLabel("System reset triggered. Press confirm to erase all content and settings. Press cancel to resume boot.");
|
||||
body->setWordWrap(true);
|
||||
body->setAlignment(Qt::AlignCenter);
|
||||
body->setStyleSheet("font-size: 65px;");
|
||||
body->setStyleSheet("font-size: 80px;");
|
||||
main_layout->addWidget(body, 1, Qt::AlignCenter);
|
||||
|
||||
QHBoxLayout *btn_layout = new QHBoxLayout();
|
||||
QHBoxLayout *blayout = new QHBoxLayout();
|
||||
main_layout->addLayout(blayout);
|
||||
|
||||
QPushButton *cancel_btn = new QPushButton("Cancel");
|
||||
btn_layout->addWidget(cancel_btn, 0, Qt::AlignLeft);
|
||||
QObject::connect(cancel_btn, &QPushButton::released, &a, &QApplication::quit);
|
||||
rejectBtn = new QPushButton("Cancel");
|
||||
blayout->addWidget(rejectBtn, 0, Qt::AlignLeft);
|
||||
QObject::connect(rejectBtn, &QPushButton::released, QCoreApplication::instance(), &QCoreApplication::quit);
|
||||
|
||||
QPushButton *confirm_btn = new QPushButton("Confirm");
|
||||
btn_layout->addWidget(confirm_btn, 0, Qt::AlignRight);
|
||||
QObject::connect(confirm_btn, &QPushButton::released, [=]() {
|
||||
const QString confirm_txt = "Are you sure you want to reset your device?";
|
||||
if (body->text() != confirm_txt) {
|
||||
body->setText(confirm_txt);
|
||||
} else {
|
||||
body->setText("Resetting device...");
|
||||
cancel_btn->hide();
|
||||
confirm_btn->hide();
|
||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
|
||||
#ifdef __aarch64__
|
||||
bool ret = do_reset();
|
||||
if (!ret) {
|
||||
body->setText("Reset failed.");
|
||||
cancel_btn->show();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
rebootBtn = new QPushButton("Reboot");
|
||||
blayout->addWidget(rebootBtn, 0, Qt::AlignLeft);
|
||||
QObject::connect(rebootBtn, &QPushButton::released, [=]{
|
||||
std::system("sudo reboot");
|
||||
});
|
||||
|
||||
main_layout->addLayout(btn_layout);
|
||||
confirmBtn = new QPushButton("Confirm");
|
||||
blayout->addWidget(confirmBtn, 0, Qt::AlignRight);
|
||||
QObject::connect(confirmBtn, &QPushButton::released, this, &Reset::confirm);
|
||||
|
||||
window.setStyleSheet(R"(
|
||||
rejectBtn->setVisible(!recover);
|
||||
rebootBtn->setVisible(recover);
|
||||
if (recover) {
|
||||
body->setText("Unable to mount data partition. Press confirm to reset your device.");
|
||||
}
|
||||
|
||||
setStyleSheet(R"(
|
||||
* {
|
||||
font-family: Inter;
|
||||
color: white;
|
||||
background-color: black;
|
||||
}
|
||||
@@ -90,6 +97,12 @@ int main(int argc, char *argv[]) {
|
||||
font-size: 50px;
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
bool recover = argc > 1 && strcmp(argv[1], "--recover") == 0;
|
||||
QApplication a(argc, argv);
|
||||
Reset reset(recover);
|
||||
setMainWindow(&reset);
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
20
selfdrive/ui/qt/setup/reset.h
Normal file
20
selfdrive/ui/qt/setup/reset.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QWidget>
|
||||
|
||||
class Reset : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Reset(bool recover = false, QWidget *parent = 0);
|
||||
|
||||
private:
|
||||
QLabel *body;
|
||||
QPushButton *rejectBtn;
|
||||
QPushButton *rebootBtn;
|
||||
QPushButton *confirmBtn;
|
||||
void doReset();
|
||||
|
||||
private slots:
|
||||
void confirm();
|
||||
};
|
||||
Reference in New Issue
Block a user