76 lines
1.9 KiB
C++
Executable File
76 lines
1.9 KiB
C++
Executable File
#include "selfdrive/ui/qt/ready.h"
|
|
|
|
#include <cmath>
|
|
#include <algorithm>
|
|
|
|
#include <QPainter>
|
|
#include <QStackedLayout>
|
|
|
|
#include <QApplication>
|
|
#include <QGridLayout>
|
|
#include <QString>
|
|
#include <QTransform>
|
|
#include <QPixmap>
|
|
|
|
#include "common/params.h"
|
|
#include "common/timing.h"
|
|
|
|
#include "system/hardware/hw.h"
|
|
#include "selfdrive/ui/qt/qt_window.h"
|
|
#include "selfdrive/ui/qt/util.h"
|
|
|
|
|
|
ReadyWindow::ReadyWindow(QWidget *parent) : QWidget(parent) {
|
|
QGridLayout *layout = new QGridLayout(this);
|
|
layout->setSpacing(0);
|
|
layout->setMargin(0);
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
|
setStyleSheet("ReadyWindow { background-color: black; }");
|
|
|
|
timer = new QTimer(this);
|
|
timer->callOnTimeout(this, &ReadyWindow::refresh);
|
|
}
|
|
|
|
void ReadyWindow::showEvent(QShowEvent *event) {
|
|
refresh();
|
|
timer->start(5 * 1000);
|
|
}
|
|
|
|
void ReadyWindow::hideEvent(QHideEvent *event) {
|
|
timer->stop();
|
|
}
|
|
|
|
void ReadyWindow::paintEvent(QPaintEvent *event) {
|
|
QPainter painter(this);
|
|
QPixmap *img_shown = nullptr;
|
|
|
|
if (is_hot) {
|
|
if (img_hot.isNull()) {
|
|
img_hot.load("/data/openpilot/selfdrive/clearpilot/theme/clearpilot/images/hot.png");
|
|
}
|
|
img_shown = &img_hot;
|
|
} else {
|
|
if (img_ready.isNull()) {
|
|
img_ready.load("/data/openpilot/selfdrive/clearpilot/theme/clearpilot/images/ready.png");
|
|
}
|
|
img_shown = &img_ready;
|
|
}
|
|
|
|
int x = (width() - img_shown->width()) / 2;
|
|
int y = (height() - img_shown->height()) / 2;
|
|
painter.drawPixmap(x, y, *img_shown);
|
|
}
|
|
|
|
void ReadyWindow::refresh() {
|
|
std::string bytes = params.get("Offroad_TemperatureTooHigh");
|
|
if (!bytes.empty()) {
|
|
auto doc = QJsonDocument::fromJson(bytes.data());
|
|
is_hot = true;
|
|
cur_temp = doc["extra"].toString();
|
|
update();
|
|
} else if (is_hot) {
|
|
is_hot = false;
|
|
update();
|
|
}
|
|
} |