mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-09-14 19:43:53 +08:00
Merge branch 'devel' of https://github.com/commaai/openpilot into devel-en
This commit is contained in:
+13
-3
@@ -1,5 +1,15 @@
|
||||
Import('env', 'common', 'messaging', 'gpucommon', 'visionipc', 'cereal')
|
||||
Import('env', 'arch', 'common', 'messaging', 'gpucommon', 'visionipc', 'cereal')
|
||||
|
||||
env.Program('_ui', ['ui.cc', 'slplay.c', '#phonelibs/nanovg/nanovg.c'],
|
||||
src = ['ui.cc', 'paint.cc', '#phonelibs/nanovg/nanovg.c']
|
||||
libs = [common, 'zmq', 'czmq', 'capnp', 'capnp_c', 'm', cereal, 'json', messaging, 'OpenCL', gpucommon, visionipc]
|
||||
|
||||
if arch == "aarch64":
|
||||
src += ['sound.cc', 'slplay.c']
|
||||
libs += ['EGL', 'GLESv3', 'gnustl_shared', 'log', 'utils', 'gui', 'hardware', 'ui', 'CB', 'gsl', 'adreno_utils', 'OpenSLES', 'cutils', 'uuid']
|
||||
else:
|
||||
src += ['linux.cc']
|
||||
libs += ['EGL', 'pthread', 'X11-xcb', 'xcb', 'X11', 'glfw']
|
||||
|
||||
env.Program('_ui', src,
|
||||
LINKFLAGS=['-Wl,-rpath=/system/lib64,-rpath=/system/comma/usr/lib'],
|
||||
LIBS=[common, 'zmq', 'czmq', 'capnp', 'capnp_c', 'm', 'GLESv3', 'EGL', cereal, 'gnustl_shared', 'log', 'utils', 'gui', 'hardware', 'ui', 'json', messaging, 'CB', 'OpenCL', 'gsl', 'adreno_utils', 'OpenSLES', 'cutils', 'uuid', gpucommon, visionipc])
|
||||
LIBS=libs)
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ui.hpp"
|
||||
|
||||
#define GLFW_INCLUDE_ES2
|
||||
#define GLFW_INCLUDE_GLEXT
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
typedef struct FramebufferState FramebufferState;
|
||||
typedef struct TouchState TouchState;
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <X11/Xlib-xcb.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
FramebufferState* framebuffer_init(
|
||||
const char* name, int32_t layer, int alpha,
|
||||
int *out_w, int *out_h) {
|
||||
glfwInit();
|
||||
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
glfwWindowHint(GLFW_RESIZABLE, 0);
|
||||
GLFWwindow* window;
|
||||
window = glfwCreateWindow(1920, 1080, "ui", NULL, NULL);
|
||||
if (!window) {
|
||||
printf("glfwCreateWindow failed\n");
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(0);
|
||||
|
||||
// clear screen
|
||||
glClearColor(0.2f, 0.2f, 0.2f, 1.0f );
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
framebuffer_swap((FramebufferState*)window);
|
||||
|
||||
if (out_w) *out_w = 1920;
|
||||
if (out_h) *out_h = 1080;
|
||||
|
||||
return (FramebufferState*)window;
|
||||
}
|
||||
|
||||
void framebuffer_set_power(FramebufferState *s, int mode) {
|
||||
}
|
||||
|
||||
void framebuffer_swap(FramebufferState *s) {
|
||||
glfwSwapBuffers((GLFWwindow*)s);
|
||||
}
|
||||
|
||||
void touch_init(TouchState *s) {
|
||||
printf("touch_init\n");
|
||||
}
|
||||
|
||||
int touch_poll(TouchState *s, int* out_x, int* out_y, int timeout) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int touch_read(TouchState *s, int* out_x, int* out_y) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "sound.hpp"
|
||||
|
||||
void ui_sound_init() {}
|
||||
void ui_sound_destroy() {}
|
||||
|
||||
void set_volume(int volume) {}
|
||||
|
||||
void play_alert_sound(AudibleAlert alert) {}
|
||||
void stop_alert_sound(AudibleAlert alert) {}
|
||||
|
||||
#include "common/visionimg.h"
|
||||
#include <sys/mman.h>
|
||||
|
||||
GLuint visionimg_to_gl(const VisionImg *img, EGLImageKHR *pkhr, void **pph) {
|
||||
unsigned int texture;
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, *pph);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
*pkhr = (EGLImageKHR *)1; // not NULL
|
||||
return texture;
|
||||
}
|
||||
|
||||
void visionimg_destroy_gl(EGLImageKHR khr, void *ph) {
|
||||
// empty
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,85 @@
|
||||
#include <stdlib.h>
|
||||
#include "sound.hpp"
|
||||
|
||||
#include "common/swaglog.h"
|
||||
|
||||
typedef struct {
|
||||
AudibleAlert alert;
|
||||
const char* uri;
|
||||
bool loop;
|
||||
} sound_file;
|
||||
|
||||
extern "C"{
|
||||
#include "slplay.h"
|
||||
}
|
||||
|
||||
void set_volume(int volume) {
|
||||
char volume_change_cmd[64];
|
||||
sprintf(volume_change_cmd, "service call audio 3 i32 3 i32 %d i32 1 &", volume);
|
||||
|
||||
// 5 second timeout at 60fps
|
||||
int volume_changed = system(volume_change_cmd);
|
||||
}
|
||||
|
||||
|
||||
sound_file sound_table[] = {
|
||||
{ cereal_CarControl_HUDControl_AudibleAlert_chimeDisengage, "../assets/sounds/disengaged.wav", false },
|
||||
{ cereal_CarControl_HUDControl_AudibleAlert_chimeEngage, "../assets/sounds/engaged.wav", false },
|
||||
{ cereal_CarControl_HUDControl_AudibleAlert_chimeWarning1, "../assets/sounds/warning_1.wav", false },
|
||||
{ cereal_CarControl_HUDControl_AudibleAlert_chimeWarning2, "../assets/sounds/warning_2.wav", false },
|
||||
{ cereal_CarControl_HUDControl_AudibleAlert_chimeWarningRepeat, "../assets/sounds/warning_repeat.wav", true },
|
||||
{ cereal_CarControl_HUDControl_AudibleAlert_chimeError, "../assets/sounds/error.wav", false },
|
||||
{ cereal_CarControl_HUDControl_AudibleAlert_chimePrompt, "../assets/sounds/error.wav", false },
|
||||
{ cereal_CarControl_HUDControl_AudibleAlert_none, NULL, false },
|
||||
};
|
||||
|
||||
sound_file* get_sound_file(AudibleAlert alert) {
|
||||
for (sound_file *s = sound_table; s->alert != cereal_CarControl_HUDControl_AudibleAlert_none; s++) {
|
||||
if (s->alert == alert) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void play_alert_sound(AudibleAlert alert) {
|
||||
sound_file* sound = get_sound_file(alert);
|
||||
char* error = NULL;
|
||||
|
||||
slplay_play(sound->uri, sound->loop, &error);
|
||||
if(error) {
|
||||
LOGW("error playing sound: %s", error);
|
||||
}
|
||||
}
|
||||
|
||||
void stop_alert_sound(AudibleAlert alert) {
|
||||
sound_file* sound = get_sound_file(alert);
|
||||
char* error = NULL;
|
||||
|
||||
slplay_stop_uri(sound->uri, &error);
|
||||
if(error) {
|
||||
LOGW("error stopping sound: %s", error);
|
||||
}
|
||||
}
|
||||
|
||||
void ui_sound_init() {
|
||||
char *error = NULL;
|
||||
slplay_setup(&error);
|
||||
if (error) goto fail;
|
||||
|
||||
for (sound_file *s = sound_table; s->alert != cereal_CarControl_HUDControl_AudibleAlert_none; s++) {
|
||||
slplay_create_player_for_uri(s->uri, &error);
|
||||
if (error) goto fail;
|
||||
}
|
||||
return;
|
||||
|
||||
fail:
|
||||
LOGW(error);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void ui_sound_destroy() {
|
||||
slplay_destroy();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef __SOUND_HPP
|
||||
#define __SOUND_HPP
|
||||
|
||||
#include "cereal/gen/c/log.capnp.h"
|
||||
|
||||
typedef enum cereal_CarControl_HUDControl_AudibleAlert AudibleAlert;
|
||||
|
||||
void ui_sound_init();
|
||||
void ui_sound_destroy();
|
||||
|
||||
void set_volume(int volume);
|
||||
|
||||
void play_alert_sound(AudibleAlert alert);
|
||||
void stop_alert_sound(AudibleAlert alert);
|
||||
|
||||
#endif
|
||||
|
||||
+50
-1760
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,253 @@
|
||||
#ifndef _UI_H
|
||||
#define _UI_H
|
||||
|
||||
#include <GLES3/gl3.h>
|
||||
#include <EGL/egl.h>
|
||||
|
||||
#include "nanovg.h"
|
||||
|
||||
#include "common/mat.h"
|
||||
#include "common/visionipc.h"
|
||||
#include "common/framebuffer.h"
|
||||
#include "common/modeldata.h"
|
||||
#include "messaging.hpp"
|
||||
|
||||
#include "cereal/gen/c/log.capnp.h"
|
||||
|
||||
#include "sound.hpp"
|
||||
|
||||
#define STATUS_STOPPED 0
|
||||
#define STATUS_DISENGAGED 1
|
||||
#define STATUS_ENGAGED 2
|
||||
#define STATUS_WARNING 3
|
||||
#define STATUS_ALERT 4
|
||||
|
||||
#define ALERTSIZE_NONE 0
|
||||
#define ALERTSIZE_SMALL 1
|
||||
#define ALERTSIZE_MID 2
|
||||
#define ALERTSIZE_FULL 3
|
||||
|
||||
#ifndef QCOM
|
||||
#define UI_60FPS
|
||||
#endif
|
||||
|
||||
#define UI_BUF_COUNT 4
|
||||
//#define SHOW_SPEEDLIMIT 1
|
||||
//#define DEBUG_TURN
|
||||
|
||||
const int vwp_w = 1920;
|
||||
const int vwp_h = 1080;
|
||||
const int nav_w = 640;
|
||||
const int nav_ww= 760;
|
||||
const int sbr_w = 300;
|
||||
const int bdr_s = 30;
|
||||
const int box_x = sbr_w+bdr_s;
|
||||
const int box_y = bdr_s;
|
||||
const int box_w = vwp_w-sbr_w-(bdr_s*2);
|
||||
const int box_h = vwp_h-(bdr_s*2);
|
||||
const int viz_w = vwp_w-(bdr_s*2);
|
||||
const int header_h = 420;
|
||||
const int footer_h = 280;
|
||||
const int footer_y = vwp_h-bdr_s-footer_h;
|
||||
|
||||
const int UI_FREQ = 30; // Hz
|
||||
|
||||
const int MODEL_PATH_MAX_VERTICES_CNT = 98;
|
||||
const int MODEL_LANE_PATH_CNT = 3;
|
||||
const int TRACK_POINTS_MAX_CNT = 50 * 2;
|
||||
|
||||
const int SET_SPEED_NA = 255;
|
||||
|
||||
const uint8_t bg_colors[][4] = {
|
||||
[STATUS_STOPPED] = {0x07, 0x23, 0x39, 0xff},
|
||||
[STATUS_DISENGAGED] = {0x17, 0x33, 0x49, 0xff},
|
||||
[STATUS_ENGAGED] = {0x17, 0x86, 0x44, 0xff},
|
||||
[STATUS_WARNING] = {0xDA, 0x6F, 0x25, 0xff},
|
||||
[STATUS_ALERT] = {0xC9, 0x22, 0x31, 0xff},
|
||||
};
|
||||
|
||||
|
||||
typedef struct UIScene {
|
||||
int frontview;
|
||||
int fullview;
|
||||
|
||||
int transformed_width, transformed_height;
|
||||
|
||||
ModelData model;
|
||||
|
||||
float mpc_x[50];
|
||||
float mpc_y[50];
|
||||
|
||||
bool world_objects_visible;
|
||||
mat4 extrinsic_matrix; // Last row is 0 so we can use mat4.
|
||||
|
||||
float v_cruise;
|
||||
uint64_t v_cruise_update_ts;
|
||||
float v_ego;
|
||||
bool decel_for_model;
|
||||
|
||||
float speedlimit;
|
||||
bool speedlimit_valid;
|
||||
bool map_valid;
|
||||
|
||||
float curvature;
|
||||
int engaged;
|
||||
bool engageable;
|
||||
bool monitoring_active;
|
||||
|
||||
bool uilayout_sidebarcollapsed;
|
||||
bool uilayout_mapenabled;
|
||||
// responsive layout
|
||||
int ui_viz_rx;
|
||||
int ui_viz_rw;
|
||||
int ui_viz_ro;
|
||||
|
||||
int lead_status;
|
||||
float lead_d_rel, lead_y_rel, lead_v_rel;
|
||||
|
||||
int front_box_x, front_box_y, front_box_width, front_box_height;
|
||||
|
||||
uint64_t alert_ts;
|
||||
char alert_text1[1024];
|
||||
char alert_text2[1024];
|
||||
uint8_t alert_size;
|
||||
float alert_blinkingrate;
|
||||
|
||||
float awareness_status;
|
||||
|
||||
// Used to show gps planner status
|
||||
bool gps_planner_active;
|
||||
} UIScene;
|
||||
|
||||
typedef struct {
|
||||
float x, y;
|
||||
}vertex_data;
|
||||
|
||||
typedef struct {
|
||||
vertex_data v[MODEL_PATH_MAX_VERTICES_CNT];
|
||||
int cnt;
|
||||
} model_path_vertices_data;
|
||||
|
||||
typedef struct {
|
||||
vertex_data v[TRACK_POINTS_MAX_CNT];
|
||||
int cnt;
|
||||
} track_vertices_data;
|
||||
|
||||
|
||||
typedef struct UIState {
|
||||
pthread_mutex_t lock;
|
||||
pthread_cond_t bg_cond;
|
||||
|
||||
// framebuffer
|
||||
FramebufferState *fb;
|
||||
int fb_w, fb_h;
|
||||
EGLDisplay display;
|
||||
EGLSurface surface;
|
||||
|
||||
// NVG
|
||||
NVGcontext *vg;
|
||||
|
||||
// fonts and images
|
||||
int font_courbd;
|
||||
int font_sans_regular;
|
||||
int font_sans_semibold;
|
||||
int font_sans_bold;
|
||||
int img_wheel;
|
||||
int img_turn;
|
||||
int img_face;
|
||||
int img_map;
|
||||
|
||||
// sockets
|
||||
Context *ctx;
|
||||
SubSocket *model_sock;
|
||||
SubSocket *controlsstate_sock;
|
||||
SubSocket *livecalibration_sock;
|
||||
SubSocket *radarstate_sock;
|
||||
SubSocket *map_data_sock;
|
||||
SubSocket *uilayout_sock;
|
||||
Poller * poller;
|
||||
|
||||
int active_app;
|
||||
|
||||
// vision state
|
||||
bool vision_connected;
|
||||
bool vision_connect_firstrun;
|
||||
int ipc_fd;
|
||||
|
||||
VIPCBuf bufs[UI_BUF_COUNT];
|
||||
VIPCBuf front_bufs[UI_BUF_COUNT];
|
||||
int cur_vision_idx;
|
||||
int cur_vision_front_idx;
|
||||
|
||||
GLuint frame_program;
|
||||
GLuint frame_texs[UI_BUF_COUNT];
|
||||
EGLImageKHR khr[UI_BUF_COUNT];
|
||||
void *priv_hnds[UI_BUF_COUNT];
|
||||
GLuint frame_front_texs[UI_BUF_COUNT];
|
||||
EGLImageKHR khr_front[UI_BUF_COUNT];
|
||||
void *priv_hnds_front[UI_BUF_COUNT];
|
||||
|
||||
GLint frame_pos_loc, frame_texcoord_loc;
|
||||
GLint frame_texture_loc, frame_transform_loc;
|
||||
|
||||
GLuint line_program;
|
||||
GLint line_pos_loc, line_color_loc;
|
||||
GLint line_transform_loc;
|
||||
|
||||
int rgb_width, rgb_height, rgb_stride;
|
||||
size_t rgb_buf_len;
|
||||
mat4 rgb_transform;
|
||||
|
||||
int rgb_front_width, rgb_front_height, rgb_front_stride;
|
||||
size_t rgb_front_buf_len;
|
||||
|
||||
UIScene scene;
|
||||
bool awake;
|
||||
|
||||
// timeouts
|
||||
int awake_timeout;
|
||||
int volume_timeout;
|
||||
int controls_timeout;
|
||||
int alert_sound_timeout;
|
||||
int speed_lim_off_timeout;
|
||||
int is_metric_timeout;
|
||||
int longitudinal_control_timeout;
|
||||
int limit_set_speed_timeout;
|
||||
|
||||
bool controls_seen;
|
||||
|
||||
int status;
|
||||
bool is_metric;
|
||||
bool longitudinal_control;
|
||||
bool limit_set_speed;
|
||||
float speed_lim_off;
|
||||
bool is_ego_over_limit;
|
||||
char alert_type[64];
|
||||
AudibleAlert alert_sound;
|
||||
int alert_size;
|
||||
float alert_blinking_alpha;
|
||||
bool alert_blinked;
|
||||
|
||||
float light_sensor;
|
||||
|
||||
int touch_fd;
|
||||
|
||||
// Hints for re-calculations and redrawing
|
||||
bool model_changed;
|
||||
bool livempc_or_radarstate_changed;
|
||||
|
||||
GLuint frame_vao[2], frame_vbo[2], frame_ibo[2];
|
||||
mat4 rear_frame_mat, front_frame_mat;
|
||||
|
||||
model_path_vertices_data model_path_vertices[MODEL_LANE_PATH_CNT * 2];
|
||||
|
||||
track_vertices_data track_vertices[2];
|
||||
} UIState;
|
||||
|
||||
// API
|
||||
void ui_draw_vision_alert(UIState *s, int va_size, int va_color,
|
||||
const char* va_text1, const char* va_text2);
|
||||
void ui_draw(UIState *s);
|
||||
void ui_nvg_init(UIState *s);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user