|
|
|
@ -4,7 +4,6 @@ |
|
|
|
|
#include <thread> |
|
|
|
|
#include <exception> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <QDateTime> |
|
|
|
|
#include <QHBoxLayout> |
|
|
|
|
#include <QLayout> |
|
|
|
@ -17,6 +16,7 @@ |
|
|
|
|
#include "common/timing.h" |
|
|
|
|
#include "common/swaglog.h" |
|
|
|
|
#include "common/watchdog.h" |
|
|
|
|
#include "selfdrive/hardware/hw.h" |
|
|
|
|
|
|
|
|
|
#include "home.hpp" |
|
|
|
|
#include "paint.hpp" |
|
|
|
@ -26,7 +26,61 @@ |
|
|
|
|
|
|
|
|
|
#define BACKLIGHT_DT 0.25 |
|
|
|
|
#define BACKLIGHT_TS 2.00 |
|
|
|
|
#define BACKLIGHT_OFFROAD 512 |
|
|
|
|
#define BACKLIGHT_OFFROAD 50 |
|
|
|
|
|
|
|
|
|
// HomeWindow: the container for the offroad (OffroadHome) and onroad (GLWindow) UIs
|
|
|
|
|
|
|
|
|
|
HomeWindow::HomeWindow(QWidget* parent) : QWidget(parent) { |
|
|
|
|
layout = new QGridLayout; |
|
|
|
|
layout->setMargin(0); |
|
|
|
|
|
|
|
|
|
// onroad UI
|
|
|
|
|
glWindow = new GLWindow(this); |
|
|
|
|
layout->addWidget(glWindow, 0, 0); |
|
|
|
|
|
|
|
|
|
// draw offroad UI on top of onroad UI
|
|
|
|
|
home = new OffroadHome(); |
|
|
|
|
layout->addWidget(home, 0, 0); |
|
|
|
|
|
|
|
|
|
QObject::connect(glWindow, SIGNAL(offroadTransition(bool)), this, SLOT(setVisibility(bool))); |
|
|
|
|
QObject::connect(glWindow, SIGNAL(offroadTransition(bool)), this, SIGNAL(offroadTransition(bool))); |
|
|
|
|
QObject::connect(glWindow, SIGNAL(screen_shutoff()), this, SIGNAL(closeSettings())); |
|
|
|
|
QObject::connect(this, SIGNAL(openSettings()), home, SLOT(refresh())); |
|
|
|
|
|
|
|
|
|
setLayout(layout); |
|
|
|
|
setStyleSheet(R"( |
|
|
|
|
* { |
|
|
|
|
color: white; |
|
|
|
|
} |
|
|
|
|
)"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HomeWindow::setVisibility(bool offroad) { |
|
|
|
|
home->setVisible(offroad); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HomeWindow::mousePressEvent(QMouseEvent* e) { |
|
|
|
|
UIState* ui_state = &glWindow->ui_state; |
|
|
|
|
if (GLWindow::ui_state.scene.started && GLWindow::ui_state.scene.driver_view) { |
|
|
|
|
Params().write_db_value("IsDriverViewEnabled", "0", 1); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
glWindow->wake(); |
|
|
|
|
|
|
|
|
|
// Settings button click
|
|
|
|
|
if (!ui_state->sidebar_collapsed && settings_btn.ptInRect(e->x(), e->y())) { |
|
|
|
|
emit openSettings(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Vision click
|
|
|
|
|
if (ui_state->scene.started && (e->x() >= ui_state->viz_rect.x - bdr_s)) { |
|
|
|
|
ui_state->sidebar_collapsed = !ui_state->sidebar_collapsed; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// OffroadHome: the offroad home page
|
|
|
|
|
|
|
|
|
|
OffroadHome::OffroadHome(QWidget* parent) : QWidget(parent) { |
|
|
|
|
QVBoxLayout* main_layout = new QVBoxLayout(); |
|
|
|
@ -109,7 +163,6 @@ void OffroadHome::refresh() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (alerts_widget->updateAvailable) { |
|
|
|
|
// There is a new release
|
|
|
|
|
alert_notification->setText("UPDATE"); |
|
|
|
|
} else { |
|
|
|
|
int alerts = alerts_widget->alerts.size(); |
|
|
|
@ -135,55 +188,8 @@ void OffroadHome::refresh() { |
|
|
|
|
alert_notification->setStyleSheet(style); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
HomeWindow::HomeWindow(QWidget* parent) : QWidget(parent) { |
|
|
|
|
layout = new QGridLayout; |
|
|
|
|
layout->setMargin(0); |
|
|
|
|
|
|
|
|
|
// onroad UI
|
|
|
|
|
glWindow = new GLWindow(this); |
|
|
|
|
layout->addWidget(glWindow, 0, 0); |
|
|
|
|
|
|
|
|
|
// draw offroad UI on top of onroad UI
|
|
|
|
|
home = new OffroadHome(); |
|
|
|
|
layout->addWidget(home, 0, 0); |
|
|
|
|
QObject::connect(glWindow, SIGNAL(offroadTransition(bool)), this, SLOT(setVisibility(bool))); |
|
|
|
|
QObject::connect(glWindow, SIGNAL(offroadTransition(bool)), this, SIGNAL(offroadTransition(bool))); |
|
|
|
|
QObject::connect(glWindow, SIGNAL(screen_shutoff()), this, SIGNAL(closeSettings())); |
|
|
|
|
QObject::connect(this, SIGNAL(openSettings()), home, SLOT(refresh())); |
|
|
|
|
setLayout(layout); |
|
|
|
|
setStyleSheet(R"( |
|
|
|
|
* { |
|
|
|
|
color: white; |
|
|
|
|
} |
|
|
|
|
)"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HomeWindow::setVisibility(bool offroad) { |
|
|
|
|
home->setVisible(offroad); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HomeWindow::mousePressEvent(QMouseEvent* e) { |
|
|
|
|
UIState* ui_state = &glWindow->ui_state; |
|
|
|
|
if (GLWindow::ui_state.scene.started && GLWindow::ui_state.scene.driver_view) { |
|
|
|
|
Params().write_db_value("IsDriverViewEnabled", "0", 1); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
glWindow->wake(); |
|
|
|
|
|
|
|
|
|
// Settings button click
|
|
|
|
|
if (!ui_state->sidebar_collapsed && settings_btn.ptInRect(e->x(), e->y())) { |
|
|
|
|
emit openSettings(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Vision click
|
|
|
|
|
if (ui_state->scene.started && (e->x() >= ui_state->viz_rect.x - bdr_s)) { |
|
|
|
|
ui_state->sidebar_collapsed = !ui_state->sidebar_collapsed; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void handle_display_state(UIState* s, bool user_input) { |
|
|
|
|
static int awake_timeout = 0; // Somehow this only gets called on program start
|
|
|
|
|
static int awake_timeout = 0; |
|
|
|
|
awake_timeout = std::max(awake_timeout - 1, 0); |
|
|
|
|
|
|
|
|
|
if (user_input || s->scene.ignition || s->scene.started) { |
|
|
|
@ -194,17 +200,8 @@ static void handle_display_state(UIState* s, bool user_input) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void set_backlight(int brightness) { |
|
|
|
|
try { |
|
|
|
|
std::ofstream brightness_control("/sys/class/backlight/panel0-backlight/brightness"); |
|
|
|
|
if (brightness_control.is_open()) { |
|
|
|
|
brightness_control << brightness << "\n"; |
|
|
|
|
brightness_control.close(); |
|
|
|
|
} |
|
|
|
|
} catch (std::exception& e) { |
|
|
|
|
qDebug() << "Error setting brightness"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GLWindow: the onroad UI
|
|
|
|
|
|
|
|
|
|
GLWindow::GLWindow(QWidget* parent) : QOpenGLWidget(parent) { |
|
|
|
|
timer = new QTimer(this); |
|
|
|
@ -217,7 +214,7 @@ GLWindow::GLWindow(QWidget* parent) : QOpenGLWidget(parent) { |
|
|
|
|
result += read_param(&brightness_m, "BRIGHTNESS_M", true); |
|
|
|
|
if (result != 0) { |
|
|
|
|
brightness_b = 10.0; |
|
|
|
|
brightness_m = 1.0; |
|
|
|
|
brightness_m = 0.1; |
|
|
|
|
} |
|
|
|
|
smooth_brightness = BACKLIGHT_OFFROAD; |
|
|
|
|
} |
|
|
|
@ -235,6 +232,8 @@ void GLWindow::initializeGL() { |
|
|
|
|
std::cout << "OpenGL language version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; |
|
|
|
|
|
|
|
|
|
ui_state.sound = &sound; |
|
|
|
|
ui_state.fb_w = vwp_w; |
|
|
|
|
ui_state.fb_h = vwp_h; |
|
|
|
|
ui_init(&ui_state); |
|
|
|
|
|
|
|
|
|
wake(); |
|
|
|
@ -248,18 +247,23 @@ void GLWindow::backlightUpdate() { |
|
|
|
|
// Update brightness
|
|
|
|
|
float k = (BACKLIGHT_DT / BACKLIGHT_TS) / (1.0f + BACKLIGHT_DT / BACKLIGHT_TS); |
|
|
|
|
|
|
|
|
|
float clipped_brightness = ui_state.scene.started ? |
|
|
|
|
std::min(1023.0f, (ui_state.scene.light_sensor * brightness_m) + brightness_b) : BACKLIGHT_OFFROAD; |
|
|
|
|
float clipped_brightness = std::min(100.0f, (ui_state.scene.light_sensor * brightness_m) + brightness_b); |
|
|
|
|
if (!ui_state.scene.started) { |
|
|
|
|
clipped_brightness = BACKLIGHT_OFFROAD; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
smooth_brightness = clipped_brightness * k + smooth_brightness * (1.0f - k); |
|
|
|
|
|
|
|
|
|
int brightness = smooth_brightness; |
|
|
|
|
|
|
|
|
|
if (!ui_state.awake) { |
|
|
|
|
brightness = 0; |
|
|
|
|
emit screen_shutoff(); |
|
|
|
|
} |
|
|
|
|
std::thread{set_backlight, brightness}.detach(); |
|
|
|
|
|
|
|
|
|
if (brightness != last_brightness) { |
|
|
|
|
std::thread{Hardware::set_brightness, brightness}.detach(); |
|
|
|
|
} |
|
|
|
|
last_brightness = brightness; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GLWindow::timerUpdate() { |
|
|
|
@ -296,9 +300,7 @@ void GLWindow::paintGL() { |
|
|
|
|
double dt = cur_draw_t - prev_draw_t; |
|
|
|
|
if (dt > 66 && onroad){ |
|
|
|
|
// warn on sub 15fps
|
|
|
|
|
#ifdef QCOM2 |
|
|
|
|
LOGW("slow frame(%llu) time: %.2f", ui_state.sm->frame, dt); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
prev_draw_t = cur_draw_t; |
|
|
|
|
} |
|
|
|
@ -307,9 +309,3 @@ void GLWindow::paintGL() { |
|
|
|
|
void GLWindow::wake() { |
|
|
|
|
handle_display_state(&ui_state, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
FrameBuffer::FrameBuffer(const char *name, uint32_t layer, int alpha, int *out_w, int *out_h) { |
|
|
|
|
*out_w = vwp_w; |
|
|
|
|
*out_h = vwp_h; |
|
|
|
|
} |
|
|
|
|
FrameBuffer::~FrameBuffer() {} |
|
|
|
|