mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-28 18:12:05 +08:00
cleanup camera malfunction alert (#2751)
* cleanup alert * move ui_draw_vision_alert out of ui_draw_vision old-commit-hash: 1ee8287705f48015652ef54b50f1b7d6197dd74c
This commit is contained in:
+29
-32
@@ -445,24 +445,22 @@ static void ui_draw_vision_footer(UIState *s) {
|
||||
ui_draw_vision_face(s);
|
||||
}
|
||||
|
||||
void ui_draw_vision_alert(UIState *s, cereal::ControlsState::AlertSize va_size, UIStatus va_color,
|
||||
const char* va_text1, const char* va_text2) {
|
||||
static void ui_draw_vision_alert(UIState *s) {
|
||||
static std::map<cereal::ControlsState::AlertSize, const int> alert_size_map = {
|
||||
{cereal::ControlsState::AlertSize::NONE, 0},
|
||||
{cereal::ControlsState::AlertSize::SMALL, 241},
|
||||
{cereal::ControlsState::AlertSize::MID, 390},
|
||||
{cereal::ControlsState::AlertSize::FULL, s->fb_h}};
|
||||
|
||||
const UIScene *scene = &s->scene;
|
||||
bool longAlert1 = strlen(va_text1) > 15;
|
||||
bool longAlert1 = scene->alert_text1.length() > 15;
|
||||
|
||||
NVGcolor color = bg_colors[va_color];
|
||||
NVGcolor color = bg_colors[s->status];
|
||||
color.a *= s->alert_blinking_alpha;
|
||||
int alr_s = alert_size_map[va_size];
|
||||
int alr_s = alert_size_map[scene->alert_size];
|
||||
|
||||
const int alr_x = scene->viz_rect.x - bdr_s;
|
||||
const int alr_w = scene->viz_rect.w + (bdr_s*2);
|
||||
const int alr_h = alr_s+(va_size==cereal::ControlsState::AlertSize::NONE?0:bdr_s);
|
||||
const int alr_h = alr_s+(scene->alert_size==cereal::ControlsState::AlertSize::NONE?0:bdr_s);
|
||||
const int alr_y = s->fb_h-alr_h;
|
||||
|
||||
ui_draw_rect(s->vg, alr_x, alr_y, alr_w, alr_h, color);
|
||||
@@ -474,20 +472,20 @@ void ui_draw_vision_alert(UIState *s, cereal::ControlsState::AlertSize va_size,
|
||||
nvgFillColor(s->vg, COLOR_WHITE);
|
||||
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE);
|
||||
|
||||
if (va_size == cereal::ControlsState::AlertSize::SMALL) {
|
||||
ui_draw_text(s->vg, alr_x+alr_w/2, alr_y+alr_h/2+15, va_text1, 40*2.5, COLOR_WHITE, s->font_sans_semibold);
|
||||
} else if (va_size == cereal::ControlsState::AlertSize::MID) {
|
||||
ui_draw_text(s->vg, alr_x+alr_w/2, alr_y+alr_h/2-45, va_text1, 48*2.5, COLOR_WHITE, s->font_sans_bold);
|
||||
ui_draw_text(s->vg, alr_x+alr_w/2, alr_y+alr_h/2+75, va_text2, 36*2.5, COLOR_WHITE, s->font_sans_regular);
|
||||
} else if (va_size == cereal::ControlsState::AlertSize::FULL) {
|
||||
if (scene->alert_size == cereal::ControlsState::AlertSize::SMALL) {
|
||||
ui_draw_text(s->vg, alr_x+alr_w/2, alr_y+alr_h/2+15, scene->alert_text1.c_str(), 40*2.5, COLOR_WHITE, s->font_sans_semibold);
|
||||
} else if (scene->alert_size == cereal::ControlsState::AlertSize::MID) {
|
||||
ui_draw_text(s->vg, alr_x+alr_w/2, alr_y+alr_h/2-45, scene->alert_text1.c_str(), 48*2.5, COLOR_WHITE, s->font_sans_bold);
|
||||
ui_draw_text(s->vg, alr_x+alr_w/2, alr_y+alr_h/2+75, scene->alert_text2.c_str(), 36*2.5, COLOR_WHITE, s->font_sans_regular);
|
||||
} else if (scene->alert_size == cereal::ControlsState::AlertSize::FULL) {
|
||||
nvgFontSize(s->vg, (longAlert1?72:96)*2.5);
|
||||
nvgFontFaceId(s->vg, s->font_sans_bold);
|
||||
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE);
|
||||
nvgTextBox(s->vg, alr_x, alr_y+(longAlert1?360:420), alr_w-60, va_text1, NULL);
|
||||
nvgTextBox(s->vg, alr_x, alr_y+(longAlert1?360:420), alr_w-60, scene->alert_text1.c_str(), NULL);
|
||||
nvgFontSize(s->vg, 48*2.5);
|
||||
nvgFontFaceId(s->vg, s->font_sans_regular);
|
||||
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BOTTOM);
|
||||
nvgTextBox(s->vg, alr_x, alr_h-(longAlert1?300:360), alr_w-60, va_text2, NULL);
|
||||
nvgTextBox(s->vg, alr_x, alr_h-(longAlert1?300:360), alr_w-60, scene->alert_text2.c_str(), NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,24 +505,19 @@ static void ui_draw_vision_frame(UIState *s) {
|
||||
|
||||
static void ui_draw_vision(UIState *s) {
|
||||
const UIScene *scene = &s->scene;
|
||||
|
||||
// Draw augmented elements
|
||||
if (!scene->frontview && scene->world_objects_visible) {
|
||||
ui_draw_world(s);
|
||||
}
|
||||
// Set Speed, Current Speed, Status/Events
|
||||
if (!scene->frontview) {
|
||||
// Draw augmented elements
|
||||
if (scene->world_objects_visible) {
|
||||
ui_draw_world(s);
|
||||
}
|
||||
// Set Speed, Current Speed, Status/Events
|
||||
ui_draw_vision_header(s);
|
||||
if (scene->alert_size == cereal::ControlsState::AlertSize::NONE) {
|
||||
ui_draw_vision_footer(s);
|
||||
}
|
||||
} else {
|
||||
ui_draw_driver_view(s);
|
||||
}
|
||||
|
||||
if (scene->alert_size != cereal::ControlsState::AlertSize::NONE) {
|
||||
ui_draw_vision_alert(s, scene->alert_size, s->status,
|
||||
scene->alert_text1.c_str(), scene->alert_text2.c_str());
|
||||
} else if (!scene->frontview) {
|
||||
ui_draw_vision_footer(s);
|
||||
}
|
||||
}
|
||||
|
||||
static void ui_draw_background(UIState *s) {
|
||||
@@ -540,12 +533,12 @@ void ui_draw(UIState *s) {
|
||||
s->scene.viz_rect.w -= sbr_w;
|
||||
}
|
||||
|
||||
const bool draw_vision = s->started && s->active_app == cereal::UiLayoutState::App::NONE &&
|
||||
s->status != STATUS_OFFROAD && s->vision_connected;
|
||||
const bool draw_vision = s->started && s->status != STATUS_OFFROAD &&
|
||||
s->active_app == cereal::UiLayoutState::App::NONE;
|
||||
|
||||
// GL drawing functions
|
||||
ui_draw_background(s);
|
||||
if (draw_vision) {
|
||||
if (draw_vision && s->vision_connected) {
|
||||
ui_draw_vision_frame(s);
|
||||
}
|
||||
glEnable(GL_BLEND);
|
||||
@@ -555,9 +548,13 @@ void ui_draw(UIState *s) {
|
||||
// NVG drawing functions - should be no GL inside NVG frame
|
||||
nvgBeginFrame(s->vg, s->fb_w, s->fb_h, 1.0f);
|
||||
ui_draw_sidebar(s);
|
||||
if (draw_vision) {
|
||||
if (draw_vision && s->vision_connected) {
|
||||
ui_draw_vision(s);
|
||||
}
|
||||
|
||||
if (draw_vision && s->scene.alert_size != cereal::ControlsState::AlertSize::NONE) {
|
||||
ui_draw_vision_alert(s);
|
||||
}
|
||||
nvgEndFrame(s->vg);
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
#pragma once
|
||||
#include "ui.hpp"
|
||||
|
||||
|
||||
void ui_draw_vision_alert(UIState *s, cereal::ControlsState::AlertSize va_size, UIStatus va_color,
|
||||
const char* va_text1, const char* va_text2);
|
||||
void ui_draw(UIState *s);
|
||||
void ui_draw_image(NVGcontext *vg, float x, float y, float w, float h, int image, float alpha);
|
||||
void ui_draw_rect(NVGcontext *vg, float x, float y, float w, float h, NVGcolor color, float r = 0, int width = 0);
|
||||
|
||||
+3
-5
@@ -283,17 +283,15 @@ void ui_update(UIState *s) {
|
||||
s->status = STATUS_ALERT;
|
||||
}
|
||||
|
||||
if (((s->sm)->rcv_frame("frame") > s->started_frame &&
|
||||
((s->sm)->frame - (s->sm)->rcv_frame("frame")) > 5*UI_FREQ) ||
|
||||
((s->sm)->frame - (s->sm)->rcv_frame("frame")) > 35*UI_FREQ) {
|
||||
const uint64_t frame_pkt = (s->sm)->rcv_frame("frame");
|
||||
const uint64_t frame_delayed = (s->sm)->frame - frame_pkt;
|
||||
if ((frame_pkt > s->started_frame && frame_delayed > 5 * UI_FREQ) || frame_delayed > 35 * UI_FREQ) {
|
||||
// controls is fine, but rear camera is lagging or died
|
||||
s->scene.alert_text1 = "Camera Malfunction";
|
||||
s->scene.alert_text2 = "Contact Support";
|
||||
s->scene.alert_size = cereal::ControlsState::AlertSize::FULL;
|
||||
s->status = STATUS_DISENGAGED;
|
||||
s->sound->stop();
|
||||
ui_draw_vision_alert(s, s->scene.alert_size, s->status,
|
||||
s->scene.alert_text1.c_str(), s->scene.alert_text2.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user