wip
This commit is contained in:
141
selfdrive/ui/qt/setup/reset.cc
Executable file
141
selfdrive/ui/qt/setup/reset.cc
Executable file
@@ -0,0 +1,141 @@
|
||||
#include <QApplication>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "selfdrive/ui/qt/qt_window.h"
|
||||
#include "selfdrive/ui/qt/setup/reset.h"
|
||||
|
||||
#define NVME "/dev/nvme0n1"
|
||||
#define USERDATA "/dev/disk/by-partlabel/userdata"
|
||||
|
||||
void Reset::doErase() {
|
||||
// best effort to wipe nvme
|
||||
std::system("sudo umount " NVME);
|
||||
std::system("yes | sudo mkfs.ext4 " NVME);
|
||||
|
||||
int rm = std::system("sudo rm -rf /data/*");
|
||||
std::system("sudo umount " USERDATA);
|
||||
int fmt = std::system("yes | sudo mkfs.ext4 " USERDATA);
|
||||
|
||||
if (rm == 0 || fmt == 0) {
|
||||
std::system("sudo reboot");
|
||||
}
|
||||
body->setText(tr("Reset failed. Reboot to try again."));
|
||||
rebootBtn->show();
|
||||
}
|
||||
|
||||
void Reset::startReset() {
|
||||
body->setText(tr("Resetting device...\nThis may take up to a minute."));
|
||||
rejectBtn->hide();
|
||||
rebootBtn->hide();
|
||||
confirmBtn->hide();
|
||||
#ifdef __aarch64__
|
||||
QTimer::singleShot(100, this, &Reset::doErase);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Reset::confirm() {
|
||||
const QString confirm_txt = tr("Are you sure you want to reset your device?");
|
||||
if (body->text() != confirm_txt) {
|
||||
body->setText(confirm_txt);
|
||||
} else {
|
||||
startReset();
|
||||
}
|
||||
}
|
||||
|
||||
Reset::Reset(ResetMode mode, QWidget *parent) : QWidget(parent) {
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||
main_layout->setContentsMargins(45, 220, 45, 45);
|
||||
main_layout->setSpacing(0);
|
||||
|
||||
QLabel *title = new QLabel(tr("System Reset"));
|
||||
title->setStyleSheet("font-size: 90px; font-weight: 600;");
|
||||
main_layout->addWidget(title, 0, Qt::AlignTop | Qt::AlignLeft);
|
||||
|
||||
main_layout->addSpacing(60);
|
||||
|
||||
body = new QLabel(tr("Press confirm to erase all content and settings. Press cancel to resume boot."));
|
||||
body->setWordWrap(true);
|
||||
body->setStyleSheet("font-size: 80px; font-weight: light;");
|
||||
main_layout->addWidget(body, 1, Qt::AlignTop | Qt::AlignLeft);
|
||||
|
||||
QHBoxLayout *blayout = new QHBoxLayout();
|
||||
main_layout->addLayout(blayout);
|
||||
blayout->setSpacing(50);
|
||||
|
||||
rejectBtn = new QPushButton(tr("Cancel"));
|
||||
blayout->addWidget(rejectBtn);
|
||||
QObject::connect(rejectBtn, &QPushButton::clicked, QCoreApplication::instance(), &QCoreApplication::quit);
|
||||
|
||||
rebootBtn = new QPushButton(tr("Reboot"));
|
||||
blayout->addWidget(rebootBtn);
|
||||
#ifdef __aarch64__
|
||||
QObject::connect(rebootBtn, &QPushButton::clicked, [=]{
|
||||
std::system("sudo reboot");
|
||||
});
|
||||
#endif
|
||||
|
||||
confirmBtn = new QPushButton(tr("Confirm"));
|
||||
confirmBtn->setStyleSheet(R"(
|
||||
QPushButton {
|
||||
background-color: #465BEA;
|
||||
}
|
||||
QPushButton:pressed {
|
||||
background-color: #3049F4;
|
||||
}
|
||||
)");
|
||||
blayout->addWidget(confirmBtn);
|
||||
QObject::connect(confirmBtn, &QPushButton::clicked, this, &Reset::confirm);
|
||||
|
||||
bool recover = mode == ResetMode::RECOVER;
|
||||
rejectBtn->setVisible(!recover);
|
||||
rebootBtn->setVisible(recover);
|
||||
if (recover) {
|
||||
body->setText(tr("Unable to mount data partition. Partition may be corrupted. Press confirm to erase and reset your device."));
|
||||
}
|
||||
|
||||
// automatically start if we're just finishing up an ABL reset
|
||||
if (mode == ResetMode::FORMAT) {
|
||||
startReset();
|
||||
}
|
||||
|
||||
setStyleSheet(R"(
|
||||
* {
|
||||
font-family: Inter;
|
||||
color: white;
|
||||
background-color: black;
|
||||
}
|
||||
QLabel {
|
||||
margin-left: 140;
|
||||
}
|
||||
QPushButton {
|
||||
height: 160;
|
||||
font-size: 55px;
|
||||
font-weight: 400;
|
||||
border-radius: 10px;
|
||||
background-color: #333333;
|
||||
}
|
||||
QPushButton:pressed {
|
||||
background-color: #444444;
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
ResetMode mode = ResetMode::USER_RESET;
|
||||
if (argc > 1) {
|
||||
if (strcmp(argv[1], "--recover") == 0) {
|
||||
mode = ResetMode::RECOVER;
|
||||
} else if (strcmp(argv[1], "--format") == 0) {
|
||||
mode = ResetMode::FORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
QApplication a(argc, argv);
|
||||
Reset reset(mode);
|
||||
setMainWindow(&reset);
|
||||
return a.exec();
|
||||
}
|
||||
27
selfdrive/ui/qt/setup/reset.h
Executable file
27
selfdrive/ui/qt/setup/reset.h
Executable file
@@ -0,0 +1,27 @@
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QWidget>
|
||||
|
||||
enum ResetMode {
|
||||
USER_RESET, // user initiated a factory reset from openpilot
|
||||
RECOVER, // userdata is corrupt for some reason, give a chance to recover
|
||||
FORMAT, // finish up an ABL factory reset
|
||||
};
|
||||
|
||||
class Reset : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Reset(ResetMode mode, QWidget *parent = 0);
|
||||
|
||||
private:
|
||||
QLabel *body;
|
||||
QPushButton *rejectBtn;
|
||||
QPushButton *rebootBtn;
|
||||
QPushButton *confirmBtn;
|
||||
void doErase();
|
||||
void startReset();
|
||||
|
||||
private slots:
|
||||
void confirm();
|
||||
};
|
||||
399
selfdrive/ui/qt/setup/setup.cc
Executable file
399
selfdrive/ui/qt/setup/setup.cc
Executable file
@@ -0,0 +1,399 @@
|
||||
#include "selfdrive/ui/qt/setup/setup.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include "common/util.h"
|
||||
#include "system/hardware/hw.h"
|
||||
#include "selfdrive/ui/qt/api.h"
|
||||
#include "selfdrive/ui/qt/qt_window.h"
|
||||
#include "selfdrive/ui/qt/network/networking.h"
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
#include "selfdrive/ui/qt/widgets/input.h"
|
||||
|
||||
const std::string USER_AGENT = "AGNOSSetup-";
|
||||
const QString DASHCAM_URL = "https://dashcam.comma.ai";
|
||||
|
||||
bool is_elf(char *fname) {
|
||||
FILE *fp = fopen(fname, "rb");
|
||||
if (fp == NULL) {
|
||||
return false;
|
||||
}
|
||||
char buf[4];
|
||||
size_t n = fread(buf, 1, 4, fp);
|
||||
fclose(fp);
|
||||
return n == 4 && buf[0] == 0x7f && buf[1] == 'E' && buf[2] == 'L' && buf[3] == 'F';
|
||||
}
|
||||
|
||||
void Setup::download(QString url) {
|
||||
// autocomplete incomplete urls
|
||||
if (QRegularExpression("^([^/.]+)/([^/]+)$").match(url).hasMatch()) {
|
||||
url.prepend("https://installer.comma.ai/");
|
||||
}
|
||||
|
||||
CURL *curl = curl_easy_init();
|
||||
if (!curl) {
|
||||
emit finished(url, tr("Something went wrong. Reboot the device."));
|
||||
return;
|
||||
}
|
||||
|
||||
auto version = util::read_file("/VERSION");
|
||||
|
||||
struct curl_slist *list = NULL;
|
||||
list = curl_slist_append(list, ("X-openpilot-serial: " + Hardware::get_serial()).c_str());
|
||||
|
||||
char tmpfile[] = "/tmp/installer_XXXXXX";
|
||||
FILE *fp = fdopen(mkstemp(tmpfile), "w");
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.toStdString().c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, (USER_AGENT + version).c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30L);
|
||||
|
||||
int ret = curl_easy_perform(curl);
|
||||
long res_status = 0;
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &res_status);
|
||||
|
||||
if (ret != CURLE_OK || res_status != 200) {
|
||||
emit finished(url, tr("Ensure the entered URL is valid, and the device’s internet connection is good."));
|
||||
} else if (!is_elf(tmpfile)) {
|
||||
emit finished(url, tr("No custom software found at this URL."));
|
||||
} else {
|
||||
rename(tmpfile, "/tmp/installer");
|
||||
|
||||
FILE *fp_url = fopen("/tmp/installer_url", "w");
|
||||
fprintf(fp_url, "%s", url.toStdString().c_str());
|
||||
fclose(fp_url);
|
||||
|
||||
emit finished(url);
|
||||
}
|
||||
|
||||
curl_slist_free_all(list);
|
||||
curl_easy_cleanup(curl);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
QWidget * Setup::low_voltage() {
|
||||
QWidget *widget = new QWidget();
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(widget);
|
||||
main_layout->setContentsMargins(55, 0, 55, 55);
|
||||
main_layout->setSpacing(0);
|
||||
|
||||
// inner text layout: warning icon, title, and body
|
||||
QVBoxLayout *inner_layout = new QVBoxLayout();
|
||||
inner_layout->setContentsMargins(110, 144, 365, 0);
|
||||
main_layout->addLayout(inner_layout);
|
||||
|
||||
QLabel *triangle = new QLabel();
|
||||
triangle->setPixmap(QPixmap(ASSET_PATH + "offroad/icon_warning.png"));
|
||||
inner_layout->addWidget(triangle, 0, Qt::AlignTop | Qt::AlignLeft);
|
||||
inner_layout->addSpacing(80);
|
||||
|
||||
QLabel *title = new QLabel(tr("WARNING: Low Voltage"));
|
||||
title->setStyleSheet("font-size: 90px; font-weight: 500; color: #FF594F;");
|
||||
inner_layout->addWidget(title, 0, Qt::AlignTop | Qt::AlignLeft);
|
||||
|
||||
inner_layout->addSpacing(25);
|
||||
|
||||
QLabel *body = new QLabel(tr("Power your device in a car with a harness or proceed at your own risk."));
|
||||
body->setWordWrap(true);
|
||||
body->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
body->setStyleSheet("font-size: 80px; font-weight: 300;");
|
||||
inner_layout->addWidget(body);
|
||||
|
||||
inner_layout->addStretch();
|
||||
|
||||
// power off + continue buttons
|
||||
QHBoxLayout *blayout = new QHBoxLayout();
|
||||
blayout->setSpacing(50);
|
||||
main_layout->addLayout(blayout, 0);
|
||||
|
||||
QPushButton *poweroff = new QPushButton(tr("Power off"));
|
||||
poweroff->setObjectName("navBtn");
|
||||
blayout->addWidget(poweroff);
|
||||
QObject::connect(poweroff, &QPushButton::clicked, this, [=]() {
|
||||
Hardware::poweroff();
|
||||
});
|
||||
|
||||
QPushButton *cont = new QPushButton(tr("Continue"));
|
||||
cont->setObjectName("navBtn");
|
||||
blayout->addWidget(cont);
|
||||
QObject::connect(cont, &QPushButton::clicked, this, &Setup::nextPage);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
QWidget * Setup::getting_started() {
|
||||
QWidget *widget = new QWidget();
|
||||
|
||||
QHBoxLayout *main_layout = new QHBoxLayout(widget);
|
||||
main_layout->setMargin(0);
|
||||
|
||||
QVBoxLayout *vlayout = new QVBoxLayout();
|
||||
vlayout->setContentsMargins(165, 280, 100, 0);
|
||||
main_layout->addLayout(vlayout);
|
||||
|
||||
QLabel *title = new QLabel(tr("Getting Started"));
|
||||
title->setStyleSheet("font-size: 90px; font-weight: 500;");
|
||||
vlayout->addWidget(title, 0, Qt::AlignTop | Qt::AlignLeft);
|
||||
|
||||
vlayout->addSpacing(90);
|
||||
QLabel *desc = new QLabel(tr("Before we get on the road, let’s finish installation and cover some details."));
|
||||
desc->setWordWrap(true);
|
||||
desc->setStyleSheet("font-size: 80px; font-weight: 300;");
|
||||
vlayout->addWidget(desc, 0, Qt::AlignTop | Qt::AlignLeft);
|
||||
|
||||
vlayout->addStretch();
|
||||
|
||||
QPushButton *btn = new QPushButton();
|
||||
btn->setIcon(QIcon(":/img_continue_triangle.svg"));
|
||||
btn->setIconSize(QSize(54, 106));
|
||||
btn->setFixedSize(310, 1080);
|
||||
btn->setProperty("primary", true);
|
||||
btn->setStyleSheet("border: none;");
|
||||
main_layout->addWidget(btn, 0, Qt::AlignRight);
|
||||
QObject::connect(btn, &QPushButton::clicked, this, &Setup::nextPage);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
QWidget * Setup::network_setup() {
|
||||
QWidget *widget = new QWidget();
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(widget);
|
||||
main_layout->setContentsMargins(55, 50, 55, 50);
|
||||
|
||||
// title
|
||||
QLabel *title = new QLabel(tr("Connect to Wi-Fi"));
|
||||
title->setStyleSheet("font-size: 90px; font-weight: 500;");
|
||||
main_layout->addWidget(title, 0, Qt::AlignLeft | Qt::AlignTop);
|
||||
|
||||
main_layout->addSpacing(25);
|
||||
|
||||
// wifi widget
|
||||
Networking *networking = new Networking(this, false);
|
||||
networking->setStyleSheet("Networking {background-color: #292929; border-radius: 13px;}");
|
||||
main_layout->addWidget(networking, 1);
|
||||
|
||||
main_layout->addSpacing(35);
|
||||
|
||||
// back + continue buttons
|
||||
QHBoxLayout *blayout = new QHBoxLayout;
|
||||
main_layout->addLayout(blayout);
|
||||
blayout->setSpacing(50);
|
||||
|
||||
QPushButton *back = new QPushButton(tr("Back"));
|
||||
back->setObjectName("navBtn");
|
||||
QObject::connect(back, &QPushButton::clicked, this, &Setup::prevPage);
|
||||
blayout->addWidget(back);
|
||||
|
||||
QPushButton *cont = new QPushButton();
|
||||
cont->setObjectName("navBtn");
|
||||
cont->setProperty("primary", true);
|
||||
QObject::connect(cont, &QPushButton::clicked, [=]() {
|
||||
auto w = currentWidget();
|
||||
QTimer::singleShot(0, [=]() {
|
||||
setCurrentWidget(downloading_widget);
|
||||
});
|
||||
QString url = InputDialog::getText(tr("Enter URL"), this, tr("for Custom Software"));
|
||||
if (!url.isEmpty()) {
|
||||
QTimer::singleShot(1000, this, [=]() {
|
||||
download(url);
|
||||
});
|
||||
} else {
|
||||
setCurrentWidget(w);
|
||||
}
|
||||
});
|
||||
blayout->addWidget(cont);
|
||||
|
||||
// setup timer for testing internet connection
|
||||
HttpRequest *request = new HttpRequest(this, false, 2500);
|
||||
QObject::connect(request, &HttpRequest::requestDone, [=](const QString &, bool success) {
|
||||
cont->setEnabled(success);
|
||||
if (success) {
|
||||
const bool wifi = networking->wifi->currentNetworkType() == NetworkType::WIFI;
|
||||
cont->setText(wifi ? tr("Continue") : tr("Continue without Wi-Fi"));
|
||||
} else {
|
||||
cont->setText(tr("Waiting for internet"));
|
||||
}
|
||||
repaint();
|
||||
});
|
||||
request->sendRequest(DASHCAM_URL);
|
||||
QTimer *timer = new QTimer(this);
|
||||
QObject::connect(timer, &QTimer::timeout, [=]() {
|
||||
if (!request->active() && cont->isVisible()) {
|
||||
request->sendRequest(DASHCAM_URL);
|
||||
}
|
||||
});
|
||||
timer->start(1000);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
QWidget * Setup::downloading() {
|
||||
QWidget *widget = new QWidget();
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(widget);
|
||||
QLabel *txt = new QLabel(tr("Downloading..."));
|
||||
txt->setStyleSheet("font-size: 90px; font-weight: 500;");
|
||||
main_layout->addWidget(txt, 0, Qt::AlignCenter);
|
||||
return widget;
|
||||
}
|
||||
|
||||
QWidget * Setup::download_failed(QLabel *url, QLabel *body) {
|
||||
QWidget *widget = new QWidget();
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(widget);
|
||||
main_layout->setContentsMargins(55, 185, 55, 55);
|
||||
main_layout->setSpacing(0);
|
||||
|
||||
QLabel *title = new QLabel(tr("Download Failed"));
|
||||
title->setStyleSheet("font-size: 90px; font-weight: 500;");
|
||||
main_layout->addWidget(title, 0, Qt::AlignTop | Qt::AlignLeft);
|
||||
|
||||
main_layout->addSpacing(67);
|
||||
|
||||
url->setWordWrap(true);
|
||||
url->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
url->setStyleSheet("font-family: \"JetBrains Mono\"; font-size: 64px; font-weight: 400; margin-right: 100px;");
|
||||
main_layout->addWidget(url);
|
||||
|
||||
main_layout->addSpacing(48);
|
||||
|
||||
body->setWordWrap(true);
|
||||
body->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
body->setStyleSheet("font-size: 80px; font-weight: 300; margin-right: 100px;");
|
||||
main_layout->addWidget(body);
|
||||
|
||||
main_layout->addStretch();
|
||||
|
||||
// reboot + start over buttons
|
||||
QHBoxLayout *blayout = new QHBoxLayout();
|
||||
blayout->setSpacing(50);
|
||||
main_layout->addLayout(blayout, 0);
|
||||
|
||||
QPushButton *reboot = new QPushButton(tr("Reboot device"));
|
||||
reboot->setObjectName("navBtn");
|
||||
blayout->addWidget(reboot);
|
||||
QObject::connect(reboot, &QPushButton::clicked, this, [=]() {
|
||||
Hardware::reboot();
|
||||
});
|
||||
|
||||
QPushButton *restart = new QPushButton(tr("Start over"));
|
||||
restart->setObjectName("navBtn");
|
||||
restart->setProperty("primary", true);
|
||||
blayout->addWidget(restart);
|
||||
QObject::connect(restart, &QPushButton::clicked, this, [=]() {
|
||||
setCurrentIndex(1);
|
||||
});
|
||||
|
||||
widget->setStyleSheet(R"(
|
||||
QLabel {
|
||||
margin-left: 117;
|
||||
}
|
||||
)");
|
||||
return widget;
|
||||
}
|
||||
|
||||
void Setup::prevPage() {
|
||||
setCurrentIndex(currentIndex() - 1);
|
||||
}
|
||||
|
||||
void Setup::nextPage() {
|
||||
setCurrentIndex(currentIndex() + 1);
|
||||
}
|
||||
|
||||
Setup::Setup(QWidget *parent) : QStackedWidget(parent) {
|
||||
if (std::getenv("MULTILANG")) {
|
||||
selectLanguage();
|
||||
}
|
||||
|
||||
std::stringstream buffer;
|
||||
buffer << std::ifstream("/sys/class/hwmon/hwmon1/in1_input").rdbuf();
|
||||
float voltage = (float)std::atoi(buffer.str().c_str()) / 1000.;
|
||||
if (voltage < 7) {
|
||||
addWidget(low_voltage());
|
||||
}
|
||||
|
||||
addWidget(getting_started());
|
||||
addWidget(network_setup());
|
||||
|
||||
downloading_widget = downloading();
|
||||
addWidget(downloading_widget);
|
||||
|
||||
QLabel *url_label = new QLabel();
|
||||
QLabel *body_label = new QLabel();
|
||||
failed_widget = download_failed(url_label, body_label);
|
||||
addWidget(failed_widget);
|
||||
|
||||
QObject::connect(this, &Setup::finished, [=](const QString &url, const QString &error) {
|
||||
qDebug() << "finished" << url << error;
|
||||
if (error.isEmpty()) {
|
||||
// hide setup on success
|
||||
QTimer::singleShot(3000, this, &QWidget::hide);
|
||||
} else {
|
||||
url_label->setText(url);
|
||||
body_label->setText(error);
|
||||
setCurrentWidget(failed_widget);
|
||||
}
|
||||
});
|
||||
|
||||
// TODO: revisit pressed bg color
|
||||
setStyleSheet(R"(
|
||||
* {
|
||||
color: white;
|
||||
font-family: Inter;
|
||||
}
|
||||
Setup {
|
||||
background-color: black;
|
||||
}
|
||||
QPushButton#navBtn {
|
||||
height: 160;
|
||||
font-size: 55px;
|
||||
font-weight: 400;
|
||||
border-radius: 10px;
|
||||
background-color: #333333;
|
||||
}
|
||||
QPushButton#navBtn:disabled, QPushButton[primary='true']:disabled {
|
||||
color: #808080;
|
||||
background-color: #333333;
|
||||
}
|
||||
QPushButton#navBtn:pressed {
|
||||
background-color: #444444;
|
||||
}
|
||||
QPushButton[primary='true'], #navBtn[primary='true'] {
|
||||
background-color: #465BEA;
|
||||
}
|
||||
QPushButton[primary='true']:pressed, #navBtn:pressed[primary='true'] {
|
||||
background-color: #3049F4;
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
void Setup::selectLanguage() {
|
||||
QMap<QString, QString> langs = getSupportedLanguages();
|
||||
QString selection = MultiOptionDialog::getSelection(tr("Select a language"), langs.keys(), "", this);
|
||||
if (!selection.isEmpty()) {
|
||||
QString selectedLang = langs[selection];
|
||||
Params().put("LanguageSetting", selectedLang.toStdString());
|
||||
if (translator.load(":/" + selectedLang)) {
|
||||
qApp->installTranslator(&translator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
QApplication a(argc, argv);
|
||||
Setup setup;
|
||||
setMainWindow(&setup);
|
||||
return a.exec();
|
||||
}
|
||||
34
selfdrive/ui/qt/setup/setup.h
Executable file
34
selfdrive/ui/qt/setup/setup.h
Executable file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <QLabel>
|
||||
#include <QStackedWidget>
|
||||
#include <QString>
|
||||
#include <QTranslator>
|
||||
#include <QWidget>
|
||||
|
||||
class Setup : public QStackedWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Setup(QWidget *parent = 0);
|
||||
|
||||
private:
|
||||
void selectLanguage();
|
||||
QWidget *low_voltage();
|
||||
QWidget *getting_started();
|
||||
QWidget *network_setup();
|
||||
QWidget *downloading();
|
||||
QWidget *download_failed(QLabel *url, QLabel *body);
|
||||
|
||||
QWidget *failed_widget;
|
||||
QWidget *downloading_widget;
|
||||
QTranslator translator;
|
||||
|
||||
signals:
|
||||
void finished(const QString &url, const QString &error = "");
|
||||
|
||||
public slots:
|
||||
void nextPage();
|
||||
void prevPage();
|
||||
void download(QString url);
|
||||
};
|
||||
215
selfdrive/ui/qt/setup/updater.cc
Executable file
215
selfdrive/ui/qt/setup/updater.cc
Executable file
@@ -0,0 +1,215 @@
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "system/hardware/hw.h"
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
#include "selfdrive/ui/qt/qt_window.h"
|
||||
#include "selfdrive/ui/qt/setup/updater.h"
|
||||
#include "selfdrive/ui/qt/network/networking.h"
|
||||
|
||||
Updater::Updater(const QString &updater_path, const QString &manifest_path, QWidget *parent)
|
||||
: updater(updater_path), manifest(manifest_path), QStackedWidget(parent) {
|
||||
|
||||
assert(updater.size());
|
||||
assert(manifest.size());
|
||||
|
||||
// initial prompt screen
|
||||
prompt = new QWidget;
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(prompt);
|
||||
layout->setContentsMargins(100, 250, 100, 100);
|
||||
|
||||
QLabel *title = new QLabel(tr("Update Required"));
|
||||
title->setStyleSheet("font-size: 80px; font-weight: bold;");
|
||||
layout->addWidget(title);
|
||||
|
||||
layout->addSpacing(75);
|
||||
|
||||
QLabel *desc = new QLabel(tr("An operating system update is required. Connect your device to Wi-Fi for the fastest update experience. The download size is approximately 1GB."));
|
||||
desc->setWordWrap(true);
|
||||
desc->setStyleSheet("font-size: 65px;");
|
||||
layout->addWidget(desc);
|
||||
|
||||
layout->addStretch();
|
||||
|
||||
QHBoxLayout *hlayout = new QHBoxLayout;
|
||||
hlayout->setSpacing(30);
|
||||
layout->addLayout(hlayout);
|
||||
|
||||
QPushButton *connect = new QPushButton(tr("Connect to Wi-Fi"));
|
||||
connect->setObjectName("navBtn");
|
||||
QObject::connect(connect, &QPushButton::clicked, [=]() {
|
||||
setCurrentWidget(wifi);
|
||||
});
|
||||
hlayout->addWidget(connect);
|
||||
|
||||
QPushButton *install = new QPushButton(tr("Install"));
|
||||
install->setObjectName("navBtn");
|
||||
install->setStyleSheet(R"(
|
||||
QPushButton {
|
||||
background-color: #465BEA;
|
||||
}
|
||||
QPushButton:pressed {
|
||||
background-color: #3049F4;
|
||||
}
|
||||
)");
|
||||
|
||||
QObject::connect(connect, &QPushButton::clicked, [=]() {
|
||||
countdownTimer->stop();
|
||||
setCurrentWidget(wifi);
|
||||
});
|
||||
|
||||
hlayout->addWidget(install);
|
||||
}
|
||||
|
||||
// wifi connection screen
|
||||
wifi = new QWidget;
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(wifi);
|
||||
layout->setContentsMargins(100, 100, 100, 100);
|
||||
|
||||
Networking *networking = new Networking(this, false);
|
||||
networking->setStyleSheet("Networking { background-color: #292929; border-radius: 13px; }");
|
||||
layout->addWidget(networking, 1);
|
||||
|
||||
QPushButton *back = new QPushButton(tr("Back"));
|
||||
back->setObjectName("navBtn");
|
||||
back->setStyleSheet("padding-left: 60px; padding-right: 60px;");
|
||||
QObject::connect(back, &QPushButton::clicked, [=]() {
|
||||
setCurrentWidget(prompt);
|
||||
});
|
||||
layout->addWidget(back, 0, Qt::AlignLeft);
|
||||
}
|
||||
|
||||
// progress screen
|
||||
progress = new QWidget;
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(progress);
|
||||
layout->setContentsMargins(150, 330, 150, 150);
|
||||
layout->setSpacing(0);
|
||||
|
||||
text = new QLabel(tr("Loading..."));
|
||||
text->setStyleSheet("font-size: 90px; font-weight: 600;");
|
||||
layout->addWidget(text, 0, Qt::AlignTop);
|
||||
|
||||
layout->addSpacing(100);
|
||||
|
||||
bar = new QProgressBar();
|
||||
bar->setRange(0, 100);
|
||||
bar->setTextVisible(false);
|
||||
bar->setFixedHeight(72);
|
||||
layout->addWidget(bar, 0, Qt::AlignTop);
|
||||
|
||||
layout->addStretch();
|
||||
|
||||
reboot = new QPushButton(tr("Reboot"));
|
||||
reboot->setObjectName("navBtn");
|
||||
reboot->setStyleSheet("padding-left: 60px; padding-right: 60px;");
|
||||
QObject::connect(reboot, &QPushButton::clicked, [=]() {
|
||||
Hardware::reboot();
|
||||
});
|
||||
layout->addWidget(reboot, 0, Qt::AlignLeft);
|
||||
reboot->hide();
|
||||
|
||||
layout->addStretch();
|
||||
}
|
||||
|
||||
addWidget(prompt);
|
||||
addWidget(wifi);
|
||||
addWidget(progress);
|
||||
|
||||
// Initialize the countdown timer and value
|
||||
countdownValue = 5; // 5 seconds countdown
|
||||
countdownTimer = new QTimer(this);
|
||||
countdownTimer->setInterval(1000); // 1 second interval
|
||||
|
||||
// Connect the timer's timeout signal to update the countdown and button text
|
||||
QObject::connect(countdownTimer, &QTimer::timeout, this, &Updater::updateCountdown);
|
||||
|
||||
// Start the countdown
|
||||
countdownTimer->start();
|
||||
|
||||
// Set initial button text
|
||||
install->setText(tr("Install (5)"));
|
||||
|
||||
setStyleSheet(R"(
|
||||
* {
|
||||
color: white;
|
||||
outline: none;
|
||||
font-family: Inter;
|
||||
}
|
||||
Updater {
|
||||
color: white;
|
||||
background-color: black;
|
||||
}
|
||||
QPushButton#navBtn {
|
||||
height: 160;
|
||||
font-size: 55px;
|
||||
font-weight: 400;
|
||||
border-radius: 10px;
|
||||
background-color: #333333;
|
||||
}
|
||||
QPushButton#navBtn:pressed {
|
||||
background-color: #444444;
|
||||
}
|
||||
QProgressBar {
|
||||
border: none;
|
||||
background-color: #292929;
|
||||
}
|
||||
QProgressBar::chunk {
|
||||
background-color: #364DEF;
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
void Updater::updateCountdown() {
|
||||
countdownValue--;
|
||||
if (countdownValue > 0) {
|
||||
install->setText(tr("Install (%1)").arg(countdownValue));
|
||||
} else {
|
||||
countdownTimer->stop();
|
||||
installUpdate(); // Assuming this is the method that starts the update
|
||||
}
|
||||
}
|
||||
|
||||
void Updater::installUpdate() {
|
||||
setCurrentWidget(progress);
|
||||
QObject::connect(&proc, &QProcess::readyReadStandardOutput, this, &Updater::readProgress);
|
||||
QObject::connect(&proc, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &Updater::updateFinished);
|
||||
proc.setProcessChannelMode(QProcess::ForwardedErrorChannel);
|
||||
proc.start(updater, {"--swap", manifest});
|
||||
}
|
||||
|
||||
void Updater::readProgress() {
|
||||
auto lines = QString(proc.readAllStandardOutput());
|
||||
for (const QString &line : lines.trimmed().split("\n")) {
|
||||
auto parts = line.split(":");
|
||||
if (parts.size() == 2) {
|
||||
text->setText(parts[0]);
|
||||
bar->setValue((int)parts[1].toDouble());
|
||||
} else {
|
||||
qDebug() << line;
|
||||
}
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void Updater::updateFinished(int exitCode, QProcess::ExitStatus exitStatus) {
|
||||
qDebug() << "finished with " << exitCode;
|
||||
if (exitCode == 0) {
|
||||
Hardware::reboot();
|
||||
} else {
|
||||
text->setText(tr("Update failed"));
|
||||
reboot->show();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
initApp(argc, argv);
|
||||
QApplication a(argc, argv);
|
||||
Updater updater(argv[1], argv[2]);
|
||||
setMainWindow(&updater);
|
||||
a.installEventFilter(&updater);
|
||||
return a.exec();
|
||||
}
|
||||
32
selfdrive/ui/qt/setup/updater.h
Executable file
32
selfdrive/ui/qt/setup/updater.h
Executable file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <QLabel>
|
||||
#include <QProcess>
|
||||
#include <QPushButton>
|
||||
#include <QProgressBar>
|
||||
#include <QStackedWidget>
|
||||
#include <QWidget>
|
||||
|
||||
class Updater : public QStackedWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Updater(const QString &updater_path, const QString &manifest_path, QWidget *parent = 0);
|
||||
|
||||
private slots:
|
||||
void installUpdate();
|
||||
void readProgress();
|
||||
void updateFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||
|
||||
private:
|
||||
QProcess proc;
|
||||
QString updater, manifest;
|
||||
|
||||
QLabel *text;
|
||||
QProgressBar *bar;
|
||||
QPushButton *reboot;
|
||||
QWidget *prompt, *wifi, *progress;
|
||||
QTimer *countdownTimer;
|
||||
int countdownValue;
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user