2020-06-15 16:26:38 -06:00
|
|
|
#pragma once
|
2020-08-20 09:16:44 -06:00
|
|
|
|
2020-09-03 17:32:55 -06:00
|
|
|
#include <atomic>
|
|
|
|
#include <map>
|
2021-01-11 07:52:58 -07:00
|
|
|
#include <memory>
|
2021-05-08 23:15:17 -06:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QTimer>
|
2020-08-20 09:16:44 -06:00
|
|
|
|
2020-01-17 12:05:23 -07:00
|
|
|
#include "nanovg.h"
|
|
|
|
|
2021-05-08 23:15:17 -06:00
|
|
|
#include "cereal/messaging/messaging.h"
|
|
|
|
#include "cereal/visionipc/visionipc.h"
|
|
|
|
#include "cereal/visionipc/visionipc_client.h"
|
2021-02-09 18:23:46 -07:00
|
|
|
#include "common/transformations/orientation.hpp"
|
2021-05-08 23:15:17 -06:00
|
|
|
#include "selfdrive/camerad/cameras/camera_common.h"
|
|
|
|
#include "selfdrive/common/glutil.h"
|
|
|
|
#include "selfdrive/common/mat.h"
|
|
|
|
#include "selfdrive/common/modeldata.h"
|
|
|
|
#include "selfdrive/common/params.h"
|
|
|
|
#include "selfdrive/common/util.h"
|
|
|
|
#include "selfdrive/common/visionimg.h"
|
2021-04-29 12:18:59 -06:00
|
|
|
|
2020-03-27 12:00:42 -06:00
|
|
|
#define COLOR_BLACK nvgRGBA(0, 0, 0, 255)
|
|
|
|
#define COLOR_BLACK_ALPHA(x) nvgRGBA(0, 0, 0, x)
|
2020-03-09 20:13:32 -06:00
|
|
|
#define COLOR_WHITE nvgRGBA(255, 255, 255, 255)
|
2020-03-27 12:00:42 -06:00
|
|
|
#define COLOR_WHITE_ALPHA(x) nvgRGBA(255, 255, 255, x)
|
2021-03-24 02:10:31 -06:00
|
|
|
#define COLOR_RED_ALPHA(x) nvgRGBA(201, 34, 49, x)
|
2020-03-09 20:13:32 -06:00
|
|
|
#define COLOR_YELLOW nvgRGBA(218, 202, 37, 255)
|
|
|
|
#define COLOR_RED nvgRGBA(201, 34, 49, 255)
|
|
|
|
|
2020-09-12 19:35:36 -06:00
|
|
|
typedef struct Rect {
|
|
|
|
int x, y, w, h;
|
|
|
|
int centerX() const { return x + w / 2; }
|
2021-01-08 12:30:37 -07:00
|
|
|
int centerY() const { return y + h / 2; }
|
2020-09-12 19:35:36 -06:00
|
|
|
int right() const { return x + w; }
|
|
|
|
int bottom() const { return y + h; }
|
|
|
|
bool ptInRect(int px, int py) const {
|
|
|
|
return px >= x && px < (x + w) && py >= y && py < (y + h);
|
|
|
|
}
|
|
|
|
} Rect;
|
2020-08-20 09:16:44 -06:00
|
|
|
|
2020-01-17 12:05:23 -07:00
|
|
|
const int bdr_s = 30;
|
|
|
|
const int header_h = 420;
|
|
|
|
const int footer_h = 280;
|
|
|
|
|
2020-09-03 17:32:55 -06:00
|
|
|
const int UI_FREQ = 20; // Hz
|
2020-01-17 12:05:23 -07:00
|
|
|
|
2020-09-03 17:32:55 -06:00
|
|
|
typedef enum UIStatus {
|
|
|
|
STATUS_DISENGAGED,
|
|
|
|
STATUS_ENGAGED,
|
|
|
|
STATUS_WARNING,
|
|
|
|
STATUS_ALERT,
|
|
|
|
} UIStatus;
|
|
|
|
|
2020-10-08 20:29:56 -06:00
|
|
|
static std::map<UIStatus, NVGcolor> bg_colors = {
|
|
|
|
{STATUS_DISENGAGED, nvgRGBA(0x17, 0x33, 0x49, 0xc8)},
|
|
|
|
{STATUS_ENGAGED, nvgRGBA(0x17, 0x86, 0x44, 0xf1)},
|
|
|
|
{STATUS_WARNING, nvgRGBA(0xDA, 0x6F, 0x25, 0xf1)},
|
|
|
|
{STATUS_ALERT, nvgRGBA(0xC9, 0x22, 0x31, 0xf1)},
|
2020-01-17 12:05:23 -07:00
|
|
|
};
|
|
|
|
|
2020-11-11 21:31:46 -07:00
|
|
|
typedef struct {
|
2021-01-06 03:34:52 -07:00
|
|
|
float x, y;
|
|
|
|
} vertex_data;
|
2020-01-17 12:05:23 -07:00
|
|
|
|
2021-01-06 03:34:52 -07:00
|
|
|
typedef struct {
|
2021-02-08 04:06:14 -07:00
|
|
|
vertex_data v[TRAJECTORY_SIZE * 2];
|
2021-01-06 03:34:52 -07:00
|
|
|
int cnt;
|
|
|
|
} line_vertices_data;
|
|
|
|
|
2020-11-11 21:31:46 -07:00
|
|
|
typedef struct UIScene {
|
2020-01-17 12:05:23 -07:00
|
|
|
|
2021-02-09 18:23:46 -07:00
|
|
|
mat3 view_from_calib;
|
2020-09-03 17:32:55 -06:00
|
|
|
bool world_objects_visible;
|
2020-01-17 12:05:23 -07:00
|
|
|
|
2020-06-05 16:33:45 -06:00
|
|
|
bool is_rhd;
|
2021-03-03 03:38:41 -07:00
|
|
|
bool driver_view;
|
2020-01-17 12:05:23 -07:00
|
|
|
|
2021-02-16 22:39:32 -07:00
|
|
|
cereal::PandaState::PandaType pandaType;
|
2020-06-05 16:33:45 -06:00
|
|
|
|
2021-02-05 15:15:02 -07:00
|
|
|
// gps
|
|
|
|
int satelliteCount;
|
|
|
|
|
2021-01-06 03:34:52 -07:00
|
|
|
// modelV2
|
2020-11-11 21:31:46 -07:00
|
|
|
float lane_line_probs[4];
|
|
|
|
float road_edge_stds[2];
|
2021-02-08 04:06:14 -07:00
|
|
|
line_vertices_data track_vertices;
|
2021-01-06 03:34:52 -07:00
|
|
|
line_vertices_data lane_line_vertices[4];
|
|
|
|
line_vertices_data road_edge_vertices[2];
|
2021-01-28 07:53:24 -07:00
|
|
|
|
|
|
|
// lead
|
|
|
|
vertex_data lead_vertices[2];
|
2021-03-03 09:40:50 -07:00
|
|
|
|
|
|
|
float light_sensor, accel_sensor, gyro_sensor;
|
2021-03-24 02:10:31 -06:00
|
|
|
bool started, ignition, is_metric, longitudinal_control, end_to_end;
|
2021-03-03 09:40:50 -07:00
|
|
|
uint64_t started_frame;
|
2020-01-17 12:05:23 -07:00
|
|
|
} UIScene;
|
|
|
|
|
|
|
|
typedef struct UIState {
|
2021-01-08 06:54:25 -07:00
|
|
|
VisionIpcClient * vipc_client;
|
2021-01-11 06:51:21 -07:00
|
|
|
VisionIpcClient * vipc_client_front;
|
|
|
|
VisionIpcClient * vipc_client_rear;
|
2021-01-08 06:54:25 -07:00
|
|
|
VisionBuf * last_frame;
|
|
|
|
|
2020-01-17 12:05:23 -07:00
|
|
|
// framebuffer
|
|
|
|
int fb_w, fb_h;
|
|
|
|
|
|
|
|
// NVG
|
|
|
|
NVGcontext *vg;
|
|
|
|
|
2021-01-16 14:50:06 -07:00
|
|
|
// images
|
|
|
|
std::map<std::string, int> images;
|
2020-01-17 12:05:23 -07:00
|
|
|
|
2021-04-29 12:18:59 -06:00
|
|
|
std::unique_ptr<SubMaster> sm;
|
2020-01-17 12:05:23 -07:00
|
|
|
|
2020-09-03 17:32:55 -06:00
|
|
|
UIStatus status;
|
|
|
|
UIScene scene;
|
2020-01-17 12:05:23 -07:00
|
|
|
|
2020-09-03 17:32:55 -06:00
|
|
|
// graphics
|
2021-01-12 07:43:34 -07:00
|
|
|
std::unique_ptr<GLShader> gl_shader;
|
2021-01-11 07:52:58 -07:00
|
|
|
std::unique_ptr<EGLImageTexture> texture[UI_BUF_COUNT];
|
2020-01-17 12:05:23 -07:00
|
|
|
|
2020-09-03 17:32:55 -06:00
|
|
|
GLuint frame_vao[2], frame_vbo[2], frame_ibo[2];
|
|
|
|
mat4 rear_frame_mat, front_frame_mat;
|
2020-01-17 12:05:23 -07:00
|
|
|
|
|
|
|
bool awake;
|
|
|
|
|
2021-02-01 17:10:15 -07:00
|
|
|
Rect video_rect, viz_rect;
|
2021-01-15 03:41:20 -07:00
|
|
|
float car_space_transform[6];
|
2021-04-07 11:12:35 -06:00
|
|
|
bool wide_camera;
|
|
|
|
float zoom;
|
2020-01-17 12:05:23 -07:00
|
|
|
} UIState;
|
|
|
|
|
2021-04-29 12:18:59 -06:00
|
|
|
|
|
|
|
class QUIState : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
QUIState(QObject* parent = 0);
|
|
|
|
|
|
|
|
// TODO: get rid of this, only use signal
|
|
|
|
inline static UIState ui_state = {0};
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void uiUpdate(const UIState &s);
|
|
|
|
void offroadTransition(bool offroad);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void update();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QTimer *timer;
|
|
|
|
bool started_prev = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// device management class
|
|
|
|
|
|
|
|
class Device : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
Device(QObject *parent = 0);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// auto brightness
|
|
|
|
const float accel_samples = 5*UI_FREQ;
|
|
|
|
|
|
|
|
bool awake;
|
|
|
|
int awake_timeout = 0;
|
|
|
|
float accel_prev = 0;
|
|
|
|
float gyro_prev = 0;
|
|
|
|
float brightness_b = 0;
|
|
|
|
float brightness_m = 0;
|
|
|
|
float last_brightness = 0;
|
|
|
|
FirstOrderFilter brightness_filter;
|
|
|
|
|
|
|
|
QTimer *timer;
|
|
|
|
|
|
|
|
void updateBrightness(const UIState &s);
|
|
|
|
void updateWakefulness(const UIState &s);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void displayPowerChanged(bool on);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void setAwake(bool on, bool reset);
|
|
|
|
void update(const UIState &s);
|
|
|
|
};
|