diff --git a/selfdrive/ui/qt/home.cc b/selfdrive/ui/qt/home.cc index dc70c36..6fdd83a 100644 --- a/selfdrive/ui/qt/home.cc +++ b/selfdrive/ui/qt/home.cc @@ -44,7 +44,6 @@ HomeWindow::HomeWindow(QWidget* parent) : QWidget(parent) { slayout->addWidget(body); // CLEARPILOT - // show_ready = true; ready = new ReadyWindow(this); slayout->addWidget(ready); @@ -89,6 +88,7 @@ void HomeWindow::offroadTransition(bool offroad) { if (offroad) { sidebar->setVisible(false); slayout->setCurrentWidget(ready); + refresh(); // this->showDriverView(true, true); // Temp } else { sidebar->setVisible(false); @@ -190,42 +190,7 @@ OffroadHome::OffroadHome(QWidget* parent) : QFrame(parent) { home_layout->setContentsMargins(0, 0, 0, 0); home_layout->setSpacing(30); - // left: MapSettings/PrimeAdWidget - // QStackedWidget *left_widget = new QStackedWidget(this); -#ifdef ENABLE_MAPS - // left_widget->addWidget(new MapSettings); -#else - // left_widget->addWidget(new QWidget); -#endif - // left_widget->addWidget(new PrimeAdWidget); - // left_widget->addWidget(new DriveStats); - // left_widget->setStyleSheet("border-radius: 10px;"); - - // left_widget->setCurrentIndex(2); - // connect(uiState(), &UIState::primeChanged, [=](bool prime) { - // left_widget->setCurrentIndex(2); - // }); - - // home_layout->addWidget(left_widget, 1); - - // // right: ExperimentalModeButton, SetupWidget - // QWidget* right_widget = new QWidget(this); - // QVBoxLayout* right_column = new QVBoxLayout(right_widget); - // right_column->setContentsMargins(0, 0, 0, 0); - // right_widget->setFixedWidth(750); - // right_column->setSpacing(30); - - // ExperimentalModeButton *experimental_mode = new ExperimentalModeButton(this); - // CLEARPILOT TEMP - // QObject::connect(experimental_mode, &ExperimentalModeButton::openSettings, this, &OffroadHome::openSettings); - // QObject::connect(experimental_mode, &ExperimentalModeButton::openSettings, this, &OffroadHome::openSettings); - // right_column->addWidget(experimental_mode, 1); - - // SetupWidget *setup_widget = new SetupWidget; - // QObject::connect(setup_widget, &SetupWidget::openSettings, this, &OffroadHome::openSettings); - // right_column->addWidget(setup_widget, 1); - - // home_layout->addWidget(right_widget, 1); + // Clearpilot: removed home ui widgets } center_layout->addWidget(home_widget); @@ -262,12 +227,10 @@ OffroadHome::OffroadHome(QWidget* parent) : QFrame(parent) { )"); } +/* Refresh data on screen every 5 seconds. */ void OffroadHome::showEvent(QShowEvent *event) { refresh(); - // CLEARPILOT changed timeout to 2 min - // What does this even do? - timer->start(120 * 1000); - // slayout->addWidget(ready); + timer->start(5 * 1000); } void OffroadHome::hideEvent(QHideEvent *event) { @@ -303,4 +266,8 @@ void OffroadHome::refresh() { if (alerts) { alert_notif->setText(QString::number(alerts) + (alerts > 1 ? tr(" ALERTS") : tr(" ALERT"))); } + + if (ready->isVisible()) { + ready->refresh(); + } } diff --git a/selfdrive/ui/qt/ready.cc b/selfdrive/ui/qt/ready.cc index 1bd194b..bc55a7b 100644 --- a/selfdrive/ui/qt/ready.cc +++ b/selfdrive/ui/qt/ready.cc @@ -19,54 +19,46 @@ #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); + QGridLayout *layout = new QGridLayout(this); + layout->setSpacing(0); + layout->setMargin(0); - setAttribute(Qt::WA_OpaquePaintEvent); - - setStyleSheet(R"( - BodyWindow { - background-color: black; - } - )"); - - QObject::connect(uiState(), &UIState::uiUpdate, this, &ReadyWindow::updateState); + setAttribute(Qt::WA_OpaquePaintEvent); + setStyleSheet("ReadyWindow { background-color: black; }"); } void ReadyWindow::paintEvent(QPaintEvent *event) { - QPainter painter(this); + QPainter painter(this); + QPixmap *img_shown = nullptr; - QPixmap comma_img = loadPixmap("/data/openpilot/selfdrive/clearpilot/theme/clearpilot/images/ready.png"); - - // Calculate the top-left position to center the image in the window. - int x = (this->width() - comma_img.width()) / 2; - int y = ((this->height() - comma_img.height()) / 20) * 9; - - // Draw the pixmap at the calculated position. - painter.drawPixmap(x, y, comma_img); - - // TODO: Referencw widgets/offroad_alert.cc - // std::string bytes = params.get(key); - // if params value Offroad_TemperatureTooHigh is set with bytes > 0, then - // temp is too high. show hot.png. Add current temp to the right of the logo. - // otherwise, if offroad_alert widget would otherwise display, then ditch the ready.cc - // screen and go to home.cc. + 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::showEvent(QShowEvent *event) { -// refresh(); -// timer->start(120 * 1000); -} - -void ReadyWindow::hideEvent(QHideEvent *event) { -// timer->stop(); -} - -void ReadyWindow::updateState(const UIState &s) { -} - -void ReadyWindow::offroadTransition(bool offroad) { -} +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(); + } +} \ No newline at end of file diff --git a/selfdrive/ui/qt/ready.h b/selfdrive/ui/qt/ready.h index 6756f93..76b8119 100644 --- a/selfdrive/ui/qt/ready.h +++ b/selfdrive/ui/qt/ready.h @@ -14,17 +14,18 @@ #include "selfdrive/ui/ui.h" class ReadyWindow : public QWidget { - Q_OBJECT + Q_OBJECT public: - ReadyWindow(QWidget* parent = 0); + ReadyWindow(QWidget* parent = nullptr); private: - void paintEvent(QPaintEvent*) override; + void paintEvent(QPaintEvent *event) override; + void refresh(); + bool is_hot = false; + QString cur_temp; + QPixmap img_ready; + QPixmap img_hot; + private slots: - void updateState(const UIState &s); - void offroadTransition(bool onroad); - void showEvent(QShowEvent *event) override; - void hideEvent(QHideEvent *event) override; -// void refresh(); - -// QTimer* timer; -}; + void showEvent(QShowEvent *event) override; + void hideEvent(QHideEvent *event) override; +}; \ No newline at end of file