mirror of https://github.com/commaai/openpilot.git
UI: move c-capnp to c++ (#1455)
* ui:move c-capnp to c++
* move Subsockets into vector
* rename reader to msg
include cereal/gen/cpp/log.capnp
* fix some errors
restore some changes
restore previous
* cleanup codes
cleanup codes
* remove unused variable alert_size
* handle capnproto's enum in a robust way
add break to default
* switch -> std:map
* use static std::map instead of switch
do cleanup
* fix wrong variable name
* use FlatArrayMessageReader instead of custom MessageReader
remove messagehelp.h
Revert "use FlatArrayMessageReader instead of custom MessageReader"
This reverts commit 57d8b6b1e2b4bad908246f35eb068535b1627167.
use FlatArrayMessageReader instead of custom MessageReader
add header file
remove capnp_c lib,add kj lib
include serialize.h
fix
remove duplicate includes
old-commit-hash: ee725534bb
This commit is contained in:
parent
8450ae3541
commit
90af65c41c
|
@ -1,7 +1,7 @@
|
|||
Import('env', 'arch', 'common', 'messaging', 'gpucommon', 'visionipc', 'cereal')
|
||||
|
||||
src = ['ui.cc', 'paint.cc', 'sidebar.cc', '#phonelibs/nanovg/nanovg.c']
|
||||
libs = [common, 'zmq', 'czmq', 'capnp', 'capnp_c', 'm', cereal, messaging, gpucommon, visionipc]
|
||||
libs = [common, 'zmq', 'czmq', 'capnp', 'kj', 'm', cereal, messaging, gpucommon, visionipc]
|
||||
|
||||
if arch == "aarch64":
|
||||
src += ['sound.cc', 'slplay.c']
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <assert.h>
|
||||
#include "ui.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
#include <map>
|
||||
#include "common/util.h"
|
||||
|
||||
#define NANOVG_GLES3_IMPLEMENTATION
|
||||
|
@ -27,13 +27,6 @@ const uint8_t alert_colors[][4] = {
|
|||
[STATUS_ALERT] = {0xC9, 0x22, 0x31, 0xf1},
|
||||
};
|
||||
|
||||
const int alert_sizes[] = {
|
||||
[ALERTSIZE_NONE] = 0,
|
||||
[ALERTSIZE_SMALL] = 241,
|
||||
[ALERTSIZE_MID] = 390,
|
||||
[ALERTSIZE_FULL] = vwp_h,
|
||||
};
|
||||
|
||||
// Projects a point in car to space to the corresponding point in full frame
|
||||
// image space.
|
||||
vec3 car_space_to_full_frame(const UIState *s, vec4 car_space_projective) {
|
||||
|
@ -670,18 +663,25 @@ static void ui_draw_vision_footer(UIState *s) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void ui_draw_vision_alert(UIState *s, int va_size, int va_color,
|
||||
void ui_draw_vision_alert(UIState *s, cereal::ControlsState::AlertSize va_size, int va_color,
|
||||
const char* va_text1, const char* va_text2) {
|
||||
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, vwp_h}};
|
||||
|
||||
const UIScene *scene = &s->scene;
|
||||
const bool hasSidebar = !scene->uilayout_sidebarcollapsed;
|
||||
const bool mapEnabled = scene->uilayout_mapenabled;
|
||||
bool longAlert1 = strlen(va_text1) > 15;
|
||||
|
||||
const uint8_t *color = alert_colors[va_color];
|
||||
const int alr_s = alert_sizes[va_size];
|
||||
int alr_s = alert_size_map[va_size];
|
||||
|
||||
const int alr_x = scene->ui_viz_rx-(mapEnabled?(hasSidebar?nav_w:(nav_ww)):0)-bdr_s;
|
||||
const int alr_w = scene->ui_viz_rw+(mapEnabled?(hasSidebar?nav_w:(nav_ww)):0)+(bdr_s*2);
|
||||
const int alr_h = alr_s+(va_size==ALERTSIZE_NONE?0:bdr_s);
|
||||
const int alr_h = alr_s+(va_size==cereal::ControlsState::AlertSize::NONE?0:bdr_s);
|
||||
const int alr_y = vwp_h-alr_h;
|
||||
|
||||
ui_draw_rect(s->vg, alr_x, alr_y, alr_w, alr_h, nvgRGBA(color[0],color[1],color[2],(color[3]*s->alert_blinking_alpha)));
|
||||
|
@ -693,12 +693,12 @@ void ui_draw_vision_alert(UIState *s, int va_size, int va_color,
|
|||
nvgFillColor(s->vg, COLOR_WHITE);
|
||||
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE);
|
||||
|
||||
if (va_size == ALERTSIZE_SMALL) {
|
||||
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== ALERTSIZE_MID) {
|
||||
} 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== ALERTSIZE_FULL) {
|
||||
} else if (va_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);
|
||||
|
@ -734,10 +734,10 @@ static void ui_draw_vision(UIState *s) {
|
|||
ui_draw_driver_view(s);
|
||||
}
|
||||
|
||||
if (scene->alert_size != ALERTSIZE_NONE) {
|
||||
if (scene->alert_size != cereal::ControlsState::AlertSize::NONE) {
|
||||
// Controls Alerts
|
||||
ui_draw_vision_alert(s, scene->alert_size, s->status,
|
||||
scene->alert_text1, scene->alert_text2);
|
||||
scene->alert_text1.c_str(), scene->alert_text2.c_str());
|
||||
} else {
|
||||
if (!scene->frontview){ui_draw_vision_footer(s);}
|
||||
}
|
||||
|
@ -759,7 +759,7 @@ void ui_draw(UIState *s) {
|
|||
glViewport(0, 0, s->fb_w, s->fb_h);
|
||||
nvgBeginFrame(s->vg, s->fb_w, s->fb_h, 1.0f);
|
||||
ui_draw_sidebar(s);
|
||||
if (s->started && s->active_app == cereal_UiLayoutState_App_none && s->status != STATUS_STOPPED && s->vision_seen) {
|
||||
if (s->started && s->active_app == cereal::UiLayoutState::App::NONE && s->status != STATUS_STOPPED && s->vision_seen) {
|
||||
ui_draw_vision(s);
|
||||
}
|
||||
nvgEndFrame(s->vg);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <map>
|
||||
#include "ui.hpp"
|
||||
|
||||
static void ui_draw_sidebar_background(UIState *s) {
|
||||
|
@ -9,28 +10,32 @@ static void ui_draw_sidebar_background(UIState *s) {
|
|||
}
|
||||
|
||||
static void ui_draw_sidebar_settings_button(UIState *s) {
|
||||
bool settingsActive = s->active_app == cereal_UiLayoutState_App_settings;
|
||||
bool settingsActive = s->active_app == cereal::UiLayoutState::App::SETTINGS;
|
||||
const int settings_btn_xr = !s->scene.uilayout_sidebarcollapsed ? settings_btn_x : -(sbr_w);
|
||||
|
||||
ui_draw_image(s->vg, settings_btn_xr, settings_btn_y, settings_btn_w, settings_btn_h, s->img_button_settings, settingsActive ? 1.0f : 0.65f);
|
||||
}
|
||||
|
||||
static void ui_draw_sidebar_home_button(UIState *s) {
|
||||
bool homeActive = s->active_app == cereal_UiLayoutState_App_home;
|
||||
bool homeActive = s->active_app == cereal::UiLayoutState::App::HOME;
|
||||
const int home_btn_xr = !s->scene.uilayout_sidebarcollapsed ? home_btn_x : -(sbr_w);
|
||||
|
||||
ui_draw_image(s->vg, home_btn_xr, home_btn_y, home_btn_w, home_btn_h, s->img_button_home, homeActive ? 1.0f : 0.65f);
|
||||
}
|
||||
|
||||
static void ui_draw_sidebar_network_strength(UIState *s) {
|
||||
static std::map<cereal::ThermalData::NetworkStrength, int> network_strength_map = {
|
||||
{cereal::ThermalData::NetworkStrength::UNKNOWN, 1},
|
||||
{cereal::ThermalData::NetworkStrength::POOR, 2},
|
||||
{cereal::ThermalData::NetworkStrength::MODERATE, 3},
|
||||
{cereal::ThermalData::NetworkStrength::GOOD, 4},
|
||||
{cereal::ThermalData::NetworkStrength::GREAT, 5}};
|
||||
const int network_img_h = 27;
|
||||
const int network_img_w = 176;
|
||||
const int network_img_x = !s->scene.uilayout_sidebarcollapsed ? 58 : -(sbr_w);
|
||||
const int network_img_y = 196;
|
||||
const int network_img = s->scene.networkType == cereal_ThermalData_NetworkType_none ?
|
||||
s->img_network[0] : s->img_network[s->scene.networkStrength + 1];
|
||||
|
||||
ui_draw_image(s->vg, network_img_x, network_img_y, network_img_w, network_img_h, network_img, 1.0f);
|
||||
const int img_idx = s->scene.networkType == cereal::ThermalData::NetworkType::NONE ? 0 : network_strength_map[s->scene.networkStrength];
|
||||
ui_draw_image(s->vg, network_img_x, network_img_y, network_img_w, network_img_h, s->img_network[img_idx], 1.0f);
|
||||
}
|
||||
|
||||
static void ui_draw_sidebar_battery_icon(UIState *s) {
|
||||
|
@ -39,8 +44,7 @@ static void ui_draw_sidebar_battery_icon(UIState *s) {
|
|||
const int battery_img_x = !s->scene.uilayout_sidebarcollapsed ? 160 : -(sbr_w);
|
||||
const int battery_img_y = 255;
|
||||
|
||||
int battery_img = strcmp(s->scene.batteryStatus, "Charging") == 0 ?
|
||||
s->img_battery_charging : s->img_battery;
|
||||
int battery_img = s->scene.batteryCharging ? s->img_battery_charging : s->img_battery;
|
||||
|
||||
ui_draw_rect(s->vg, battery_img_x + 6, battery_img_y + 5,
|
||||
((battery_img_w - 19) * (s->scene.batteryPercent * 0.01)), battery_img_h - 11, COLOR_WHITE);
|
||||
|
@ -49,22 +53,23 @@ static void ui_draw_sidebar_battery_icon(UIState *s) {
|
|||
}
|
||||
|
||||
static void ui_draw_sidebar_network_type(UIState *s) {
|
||||
static std::map<cereal::ThermalData::NetworkType, const char *> network_type_map = {
|
||||
{cereal::ThermalData::NetworkType::NONE, "--"},
|
||||
{cereal::ThermalData::NetworkType::WIFI, "WiFi"},
|
||||
{cereal::ThermalData::NetworkType::CELL2_G, "2G"},
|
||||
{cereal::ThermalData::NetworkType::CELL3_G, "3G"},
|
||||
{cereal::ThermalData::NetworkType::CELL4_G, "4G"},
|
||||
{cereal::ThermalData::NetworkType::CELL5_G, "5G"}};
|
||||
const int network_x = !s->scene.uilayout_sidebarcollapsed ? 50 : -(sbr_w);
|
||||
const int network_y = 273;
|
||||
const int network_w = 100;
|
||||
const int network_h = 100;
|
||||
const char *network_types[6] = {"--", "WiFi", "2G", "3G", "4G", "5G"};
|
||||
char network_type_str[32];
|
||||
|
||||
if (s->scene.networkType <= 5) {
|
||||
snprintf(network_type_str, sizeof(network_type_str), "%s", network_types[s->scene.networkType]);
|
||||
}
|
||||
|
||||
const char *network_type = network_type_map[s->scene.networkType];
|
||||
nvgFillColor(s->vg, COLOR_WHITE);
|
||||
nvgFontSize(s->vg, 48);
|
||||
nvgFontFaceId(s->vg, s->font_sans_regular);
|
||||
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE);
|
||||
nvgTextBox(s->vg, network_x, network_y, network_w, network_type_str, NULL);
|
||||
nvgTextBox(s->vg, network_x, network_y, network_w, network_type ? network_type : "--", NULL);
|
||||
}
|
||||
|
||||
static void ui_draw_sidebar_metric(UIState *s, const char* label_str, const char* value_str, const int severity, const int y_offset, const char* message_str) {
|
||||
|
@ -113,28 +118,21 @@ static void ui_draw_sidebar_metric(UIState *s, const char* label_str, const char
|
|||
}
|
||||
|
||||
static void ui_draw_sidebar_temp_metric(UIState *s) {
|
||||
int temp_severity;
|
||||
static std::map<cereal::ThermalData::ThermalStatus, const int> temp_severity_map = {
|
||||
{cereal::ThermalData::ThermalStatus::GREEN, 0},
|
||||
{cereal::ThermalData::ThermalStatus::YELLOW, 1},
|
||||
{cereal::ThermalData::ThermalStatus::RED, 2},
|
||||
{cereal::ThermalData::ThermalStatus::DANGER, 3}};
|
||||
char temp_label_str[32];
|
||||
char temp_value_str[32];
|
||||
char temp_value_unit[32];
|
||||
const int temp_y_offset = 0;
|
||||
|
||||
if (s->scene.thermalStatus == cereal_ThermalData_ThermalStatus_green) {
|
||||
temp_severity = 0;
|
||||
} else if (s->scene.thermalStatus == cereal_ThermalData_ThermalStatus_yellow) {
|
||||
temp_severity = 1;
|
||||
} else if (s->scene.thermalStatus == cereal_ThermalData_ThermalStatus_red) {
|
||||
temp_severity = 2;
|
||||
} else if (s->scene.thermalStatus == cereal_ThermalData_ThermalStatus_danger) {
|
||||
temp_severity = 3;
|
||||
}
|
||||
|
||||
snprintf(temp_value_str, sizeof(temp_value_str), "%d", s->scene.paTemp);
|
||||
snprintf(temp_value_unit, sizeof(temp_value_unit), "%s", "°C");
|
||||
snprintf(temp_label_str, sizeof(temp_label_str), "%s", "TEMP");
|
||||
strcat(temp_value_str, temp_value_unit);
|
||||
|
||||
ui_draw_sidebar_metric(s, temp_label_str, temp_value_str, temp_severity, temp_y_offset, NULL);
|
||||
ui_draw_sidebar_metric(s, temp_label_str, temp_value_str, temp_severity_map[s->scene.thermalStatus], temp_y_offset, NULL);
|
||||
}
|
||||
|
||||
static void ui_draw_sidebar_panda_metric(UIState *s) {
|
||||
|
@ -142,7 +140,7 @@ static void ui_draw_sidebar_panda_metric(UIState *s) {
|
|||
char panda_message_str[32];
|
||||
const int panda_y_offset = 32 + 148;
|
||||
|
||||
if (s->scene.hwType == cereal_HealthData_HwType_unknown) {
|
||||
if (s->scene.hwType == cereal::HealthData::HwType::UNKNOWN) {
|
||||
panda_severity = 2;
|
||||
snprintf(panda_message_str, sizeof(panda_message_str), "%s", "NO\nVEHICLE");
|
||||
} else {
|
||||
|
|
|
@ -28,19 +28,19 @@ void set_volume(int volume) {
|
|||
|
||||
|
||||
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_chimeWarning2Repeat, "../assets/sounds/warning_2.wav", true },
|
||||
{ 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 },
|
||||
{ cereal::CarControl::HUDControl::AudibleAlert::CHIME_DISENGAGE, "../assets/sounds/disengaged.wav", false },
|
||||
{ cereal::CarControl::HUDControl::AudibleAlert::CHIME_ENGAGE, "../assets/sounds/engaged.wav", false },
|
||||
{ cereal::CarControl::HUDControl::AudibleAlert::CHIME_WARNING1, "../assets/sounds/warning_1.wav", false },
|
||||
{ cereal::CarControl::HUDControl::AudibleAlert::CHIME_WARNING2, "../assets/sounds/warning_2.wav", false },
|
||||
{ cereal::CarControl::HUDControl::AudibleAlert::CHIME_WARNING2_REPEAT, "../assets/sounds/warning_2.wav", true },
|
||||
{ cereal::CarControl::HUDControl::AudibleAlert::CHIME_WARNING_REPEAT, "../assets/sounds/warning_repeat.wav", true },
|
||||
{ cereal::CarControl::HUDControl::AudibleAlert::CHIME_ERROR, "../assets/sounds/error.wav", false },
|
||||
{ cereal::CarControl::HUDControl::AudibleAlert::CHIME_PROMPT, "../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++) {
|
||||
for (sound_file *s = sound_table; s->alert != cereal::CarControl::HUDControl::AudibleAlert::NONE; s++) {
|
||||
if (s->alert == alert) {
|
||||
return s;
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ void ui_sound_init() {
|
|||
slplay_setup(&error);
|
||||
if (error) goto fail;
|
||||
|
||||
for (sound_file *s = sound_table; s->alert != cereal_CarControl_HUDControl_AudibleAlert_none; s++) {
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#ifndef __SOUND_HPP
|
||||
#define __SOUND_HPP
|
||||
|
||||
#include "cereal/gen/c/log.capnp.h"
|
||||
#include "cereal/gen/cpp/log.capnp.h"
|
||||
|
||||
typedef enum cereal_CarControl_HUDControl_AudibleAlert AudibleAlert;
|
||||
typedef cereal::CarControl::HUDControl::AudibleAlert AudibleAlert;
|
||||
|
||||
void ui_sound_init();
|
||||
void ui_sound_destroy();
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "ui.hpp"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
@ -5,9 +6,8 @@
|
|||
#include <assert.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#include <capnp/serialize.h>
|
||||
#include <czmq.h>
|
||||
|
||||
#include "common/util.h"
|
||||
#include "common/timing.h"
|
||||
#include "common/swaglog.h"
|
||||
|
@ -15,9 +15,6 @@
|
|||
#include "common/visionimg.h"
|
||||
#include "common/params.h"
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "sound.hpp"
|
||||
|
||||
static int last_brightness = -1;
|
||||
static void set_brightness(UIState *s, int brightness) {
|
||||
if (last_brightness != brightness && (s->awake || brightness == 0)) {
|
||||
|
@ -69,35 +66,21 @@ static void set_awake(UIState *s, bool awake) {
|
|||
}
|
||||
|
||||
static void update_offroad_layout_state(UIState *s) {
|
||||
struct capn rc;
|
||||
capn_init_malloc(&rc);
|
||||
struct capn_segment *cs = capn_root(&rc).seg;
|
||||
|
||||
cereal_UiLayoutState_ptr layoutp = cereal_new_UiLayoutState(cs);
|
||||
struct cereal_UiLayoutState layoutd = {
|
||||
.activeApp = (cereal_UiLayoutState_App)s->active_app,
|
||||
.sidebarCollapsed = s->scene.uilayout_sidebarcollapsed,
|
||||
};
|
||||
cereal_write_UiLayoutState(&layoutd, layoutp);
|
||||
LOGD("setting active app to %d with sidebar %d", layoutd.activeApp, layoutd.sidebarCollapsed);
|
||||
|
||||
cereal_Event_ptr eventp = cereal_new_Event(cs);
|
||||
struct cereal_Event event = {
|
||||
.logMonoTime = nanos_since_boot(),
|
||||
.which = cereal_Event_uiLayoutState,
|
||||
.uiLayoutState = layoutp,
|
||||
};
|
||||
cereal_write_Event(&event, eventp);
|
||||
capn_setp(capn_root(&rc), 0, eventp.p);
|
||||
uint8_t buf[4096];
|
||||
ssize_t rs = capn_write_mem(&rc, buf, sizeof(buf), 0);
|
||||
s->offroad_sock->send((char*)buf, rs);
|
||||
capn_free(&rc);
|
||||
capnp::MallocMessageBuilder msg;
|
||||
auto event = msg.initRoot<cereal::Event>();
|
||||
event.setLogMonoTime(nanos_since_boot());
|
||||
auto layout = event.initUiLayoutState();
|
||||
layout.setActiveApp(s->active_app);
|
||||
layout.setSidebarCollapsed(s->scene.uilayout_sidebarcollapsed);
|
||||
auto words = capnp::messageToFlatArray(msg);
|
||||
auto bytes = words.asBytes();
|
||||
s->offroad_sock->send((char*)bytes.begin(), bytes.size());
|
||||
LOGD("setting active app to %d with sidebar %d", (int)s->active_app, s->scene.uilayout_sidebarcollapsed);
|
||||
}
|
||||
|
||||
static void navigate_to_settings(UIState *s) {
|
||||
#ifdef QCOM
|
||||
s->active_app = cereal_UiLayoutState_App_settings;
|
||||
s->active_app = cereal::UiLayoutState::App::SETTINGS;
|
||||
update_offroad_layout_state(s);
|
||||
#else
|
||||
// computer UI doesn't have offroad settings
|
||||
|
@ -107,9 +90,9 @@ static void navigate_to_settings(UIState *s) {
|
|||
static void navigate_to_home(UIState *s) {
|
||||
#ifdef QCOM
|
||||
if (s->started) {
|
||||
s->active_app = cereal_UiLayoutState_App_none;
|
||||
s->active_app = cereal::UiLayoutState::App::NONE;
|
||||
} else {
|
||||
s->active_app = cereal_UiLayoutState_App_home;
|
||||
s->active_app = cereal::UiLayoutState::App::HOME;
|
||||
}
|
||||
update_offroad_layout_state(s);
|
||||
#else
|
||||
|
@ -140,7 +123,7 @@ static void handle_driver_view_touch(UIState *s, int touch_x, int touch_y) {
|
|||
|
||||
static void handle_vision_touch(UIState *s, int touch_x, int touch_y) {
|
||||
if (s->started && (touch_x >= s->scene.ui_viz_rx - bdr_s)
|
||||
&& (s->active_app != cereal_UiLayoutState_App_settings)) {
|
||||
&& (s->active_app != cereal::UiLayoutState::App::SETTINGS)) {
|
||||
if (!s->scene.frontview) {
|
||||
s->scene.uilayout_sidebarcollapsed = !s->scene.uilayout_sidebarcollapsed;
|
||||
} else {
|
||||
|
@ -339,19 +322,15 @@ static void ui_init_vision(UIState *s, const VisionStreamBufs back_bufs,
|
|||
s->limit_set_speed_timeout = UI_FREQ;
|
||||
}
|
||||
|
||||
static PathData read_path(cereal_ModelData_PathData_ptr pathp) {
|
||||
static PathData read_path(cereal::ModelData::PathData::Reader pathp) {
|
||||
PathData ret = {0};
|
||||
|
||||
struct cereal_ModelData_PathData pathd;
|
||||
cereal_read_ModelData_PathData(&pathd, pathp);
|
||||
ret.prob = pathp.getProb();
|
||||
ret.std = pathp.getStd();
|
||||
|
||||
ret.prob = pathd.prob;
|
||||
ret.std = pathd.std;
|
||||
|
||||
capn_list32 polyp = pathd.poly;
|
||||
capn_resolve(&polyp.p);
|
||||
auto polyp = pathp.getPoly();
|
||||
for (int i = 0; i < POLYFIT_DEGREE; i++) {
|
||||
ret.poly[i] = capn_to_f32(capn_get32(polyp, i));
|
||||
ret.poly[i] = polyp[i];
|
||||
}
|
||||
|
||||
// Compute points locations
|
||||
|
@ -362,20 +341,16 @@ static PathData read_path(cereal_ModelData_PathData_ptr pathp) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
static ModelData read_model(cereal_ModelData_ptr modelp) {
|
||||
struct cereal_ModelData modeld;
|
||||
cereal_read_ModelData(&modeld, modelp);
|
||||
|
||||
static ModelData read_model(cereal::ModelData::Reader model) {
|
||||
ModelData d = {0};
|
||||
|
||||
d.path = read_path(modeld.path);
|
||||
d.left_lane = read_path(modeld.leftLane);
|
||||
d.right_lane = read_path(modeld.rightLane);
|
||||
d.path = read_path(model.getPath());
|
||||
d.left_lane = read_path(model.getLeftLane());
|
||||
d.right_lane = read_path(model.getRightLane());
|
||||
|
||||
struct cereal_ModelData_LeadData leadd;
|
||||
cereal_read_ModelData_LeadData(&leadd, modeld.lead);
|
||||
auto leadd = model.getLead();
|
||||
d.lead = (LeadData){
|
||||
.dist = leadd.dist, .prob = leadd.prob, .std = leadd.std,
|
||||
.dist = leadd.getDist(), .prob = leadd.getProb(), .std = leadd.getStd(),
|
||||
};
|
||||
|
||||
return d;
|
||||
|
@ -387,207 +362,150 @@ static void update_status(UIState *s, int status) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void handle_message(UIState *s, Message * msg) {
|
||||
struct capn ctx;
|
||||
capn_init_mem(&ctx, (uint8_t*)msg->getData(), msg->getSize(), 0);
|
||||
|
||||
cereal_Event_ptr eventp;
|
||||
eventp.p = capn_getp(capn_root(&ctx), 0, 1);
|
||||
struct cereal_Event eventd;
|
||||
cereal_read_Event(&eventd, eventp);
|
||||
|
||||
if (eventd.which == cereal_Event_controlsState && s->started) {
|
||||
struct cereal_ControlsState datad;
|
||||
cereal_read_ControlsState(&datad, eventd.controlsState);
|
||||
void handle_message(UIState *s, Message* msg) {
|
||||
auto amsg = kj::heapArray<capnp::word>((msg->getSize() / sizeof(capnp::word)) + 1);
|
||||
memcpy(amsg.begin(), msg->getData(), msg->getSize());
|
||||
capnp::FlatArrayMessageReader cmsg(amsg);
|
||||
cereal::Event::Reader event = cmsg.getRoot<cereal::Event>();
|
||||
|
||||
auto which = event.which();
|
||||
UIScene &scene = s->scene;
|
||||
if (which == cereal::Event::CONTROLS_STATE && s->started) {
|
||||
auto data = event.getControlsState();
|
||||
|
||||
s->controls_timeout = 1 * UI_FREQ;
|
||||
s->scene.frontview = datad.rearViewCam;
|
||||
if (!s->scene.frontview){s->controls_seen = true;}
|
||||
scene.frontview = data.getRearViewCam();
|
||||
if (!scene.frontview){ s->controls_seen = true; }
|
||||
|
||||
if (datad.vCruise != s->scene.v_cruise) {
|
||||
s->scene.v_cruise_update_ts = eventd.logMonoTime;
|
||||
if (data.getVCruise() != scene.v_cruise) {
|
||||
scene.v_cruise_update_ts = event.getLogMonoTime();
|
||||
}
|
||||
s->scene.v_cruise = datad.vCruise;
|
||||
s->scene.v_ego = datad.vEgo;
|
||||
s->scene.curvature = datad.curvature;
|
||||
s->scene.engaged = datad.enabled;
|
||||
s->scene.engageable = datad.engageable;
|
||||
s->scene.gps_planner_active = datad.gpsPlannerActive;
|
||||
s->scene.monitoring_active = datad.driverMonitoringOn;
|
||||
scene.v_cruise = data.getVCruise();
|
||||
scene.v_ego = data.getVEgo();
|
||||
scene.curvature = data.getCurvature();
|
||||
scene.engaged = data.getEnabled();
|
||||
scene.engageable = data.getEngageable();
|
||||
scene.gps_planner_active = data.getGpsPlannerActive();
|
||||
scene.monitoring_active = data.getDriverMonitoringOn();
|
||||
|
||||
s->scene.decel_for_model = datad.decelForModel;
|
||||
|
||||
if (datad.alertSound != cereal_CarControl_HUDControl_AudibleAlert_none && datad.alertSound != s->alert_sound) {
|
||||
if (s->alert_sound != cereal_CarControl_HUDControl_AudibleAlert_none) {
|
||||
scene.decel_for_model = data.getDecelForModel();
|
||||
auto alert_sound = data.getAlertSound();
|
||||
const auto sound_none = cereal::CarControl::HUDControl::AudibleAlert::NONE;
|
||||
if (alert_sound != s->alert_sound){
|
||||
if (s->alert_sound != sound_none){
|
||||
stop_alert_sound(s->alert_sound);
|
||||
}
|
||||
play_alert_sound(datad.alertSound);
|
||||
|
||||
s->alert_sound = datad.alertSound;
|
||||
snprintf(s->alert_type, sizeof(s->alert_type), "%s", datad.alertType.str);
|
||||
} else if ((!datad.alertSound || datad.alertSound == cereal_CarControl_HUDControl_AudibleAlert_none)
|
||||
&& s->alert_sound != cereal_CarControl_HUDControl_AudibleAlert_none) {
|
||||
stop_alert_sound(s->alert_sound);
|
||||
s->alert_type[0] = '\0';
|
||||
s->alert_sound = cereal_CarControl_HUDControl_AudibleAlert_none;
|
||||
if (alert_sound != sound_none){
|
||||
play_alert_sound(alert_sound);
|
||||
s->alert_type = data.getAlertType();
|
||||
}
|
||||
s->alert_sound = alert_sound;
|
||||
}
|
||||
|
||||
if (datad.alertText1.str) {
|
||||
snprintf(s->scene.alert_text1, sizeof(s->scene.alert_text1), "%s", datad.alertText1.str);
|
||||
} else {
|
||||
s->scene.alert_text1[0] = '\0';
|
||||
}
|
||||
if (datad.alertText2.str) {
|
||||
snprintf(s->scene.alert_text2, sizeof(s->scene.alert_text2), "%s", datad.alertText2.str);
|
||||
} else {
|
||||
s->scene.alert_text2[0] = '\0';
|
||||
}
|
||||
|
||||
s->scene.alert_ts = eventd.logMonoTime;
|
||||
|
||||
s->scene.alert_size = datad.alertSize;
|
||||
if (datad.alertSize == cereal_ControlsState_AlertSize_none) {
|
||||
s->alert_size = ALERTSIZE_NONE;
|
||||
} else if (datad.alertSize == cereal_ControlsState_AlertSize_small) {
|
||||
s->alert_size = ALERTSIZE_SMALL;
|
||||
} else if (datad.alertSize == cereal_ControlsState_AlertSize_mid) {
|
||||
s->alert_size = ALERTSIZE_MID;
|
||||
} else if (datad.alertSize == cereal_ControlsState_AlertSize_full) {
|
||||
s->alert_size = ALERTSIZE_FULL;
|
||||
}
|
||||
|
||||
if (datad.alertStatus == cereal_ControlsState_AlertStatus_userPrompt) {
|
||||
scene.alert_text1 = data.getAlertText1();
|
||||
scene.alert_text2 = data.getAlertText2();
|
||||
scene.alert_ts = event.getLogMonoTime();
|
||||
scene.alert_size = data.getAlertSize();
|
||||
auto alertStatus = data.getAlertStatus();
|
||||
if (alertStatus == cereal::ControlsState::AlertStatus::USER_PROMPT) {
|
||||
update_status(s, STATUS_WARNING);
|
||||
} else if (datad.alertStatus == cereal_ControlsState_AlertStatus_critical) {
|
||||
} else if (alertStatus == cereal::ControlsState::AlertStatus::CRITICAL) {
|
||||
update_status(s, STATUS_ALERT);
|
||||
} else if (datad.enabled) {
|
||||
update_status(s, STATUS_ENGAGED);
|
||||
} else {
|
||||
update_status(s, STATUS_DISENGAGED);
|
||||
} else{
|
||||
update_status(s, scene.engaged ? STATUS_ENGAGED : STATUS_DISENGAGED);
|
||||
}
|
||||
|
||||
s->scene.alert_blinkingrate = datad.alertBlinkingRate;
|
||||
if (datad.alertBlinkingRate > 0.) {
|
||||
scene.alert_blinkingrate = data.getAlertBlinkingRate();
|
||||
if (scene.alert_blinkingrate > 0.) {
|
||||
if (s->alert_blinked) {
|
||||
if (s->alert_blinking_alpha > 0.0 && s->alert_blinking_alpha < 1.0) {
|
||||
s->alert_blinking_alpha += (0.05*datad.alertBlinkingRate);
|
||||
s->alert_blinking_alpha += (0.05*scene.alert_blinkingrate);
|
||||
} else {
|
||||
s->alert_blinked = false;
|
||||
}
|
||||
} else {
|
||||
if (s->alert_blinking_alpha > 0.25) {
|
||||
s->alert_blinking_alpha -= (0.05*datad.alertBlinkingRate);
|
||||
s->alert_blinking_alpha -= (0.05*scene.alert_blinkingrate);
|
||||
} else {
|
||||
s->alert_blinking_alpha += 0.25;
|
||||
s->alert_blinked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (eventd.which == cereal_Event_radarState) {
|
||||
struct cereal_RadarState datad;
|
||||
cereal_read_RadarState(&datad, eventd.radarState);
|
||||
struct cereal_RadarState_LeadData leaddatad;
|
||||
cereal_read_RadarState_LeadData(&leaddatad, datad.leadOne);
|
||||
s->scene.lead_status = leaddatad.status;
|
||||
s->scene.lead_d_rel = leaddatad.dRel;
|
||||
s->scene.lead_y_rel = leaddatad.yRel;
|
||||
s->scene.lead_v_rel = leaddatad.vRel;
|
||||
cereal_read_RadarState_LeadData(&leaddatad, datad.leadTwo);
|
||||
s->scene.lead_status2 = leaddatad.status;
|
||||
s->scene.lead_d_rel2 = leaddatad.dRel;
|
||||
s->scene.lead_y_rel2 = leaddatad.yRel;
|
||||
s->scene.lead_v_rel2 = leaddatad.vRel;
|
||||
s->livempc_or_radarstate_changed = true;
|
||||
} else if (eventd.which == cereal_Event_liveCalibration) {
|
||||
s->scene.world_objects_visible = true;
|
||||
struct cereal_LiveCalibrationData datad;
|
||||
cereal_read_LiveCalibrationData(&datad, eventd.liveCalibration);
|
||||
} else if (which == cereal::Event::RADAR_STATE) {
|
||||
auto data = event.getRadarState();
|
||||
|
||||
auto leaddatad = data.getLeadOne();
|
||||
scene.lead_status = leaddatad.getStatus();
|
||||
scene.lead_d_rel = leaddatad.getDRel();
|
||||
scene.lead_y_rel = leaddatad.getYRel();
|
||||
scene.lead_v_rel = leaddatad.getVRel();
|
||||
auto leaddatad2 = data.getLeadTwo();
|
||||
scene.lead_status2 = leaddatad2.getStatus();
|
||||
scene.lead_d_rel2 = leaddatad2.getDRel();
|
||||
scene.lead_y_rel2 = leaddatad2.getYRel();
|
||||
scene.lead_v_rel2 = leaddatad2.getVRel();
|
||||
|
||||
capn_list32 extrinsicl = datad.extrinsicMatrix;
|
||||
capn_resolve(&extrinsicl.p); // is this a bug?
|
||||
s->livempc_or_radarstate_changed = true;
|
||||
} else if (which == cereal::Event::LIVE_CALIBRATION) {
|
||||
scene.world_objects_visible = true;
|
||||
auto extrinsicl = event.getLiveCalibration().getExtrinsicMatrix();
|
||||
for (int i = 0; i < 3 * 4; i++) {
|
||||
s->scene.extrinsic_matrix.v[i] =
|
||||
capn_to_f32(capn_get32(extrinsicl, i));
|
||||
scene.extrinsic_matrix.v[i] = extrinsicl[i];
|
||||
}
|
||||
} else if (eventd.which == cereal_Event_model) {
|
||||
s->scene.model = read_model(eventd.model);
|
||||
} else if (which == cereal::Event::MODEL) {
|
||||
scene.model = read_model(event.getModel());
|
||||
s->model_changed = true;
|
||||
} else if (eventd.which == cereal_Event_liveMpc) {
|
||||
struct cereal_LiveMpcData datad;
|
||||
cereal_read_LiveMpcData(&datad, eventd.liveMpc);
|
||||
|
||||
capn_list32 x_list = datad.x;
|
||||
capn_resolve(&x_list.p);
|
||||
} else if (which == cereal::Event::LIVE_MPC) {
|
||||
auto data = event.getLiveMpc();
|
||||
|
||||
auto x_list = data.getX();
|
||||
auto y_list = data.getY();
|
||||
for (int i = 0; i < 50; i++){
|
||||
s->scene.mpc_x[i] = capn_to_f32(capn_get32(x_list, i));
|
||||
}
|
||||
|
||||
capn_list32 y_list = datad.y;
|
||||
capn_resolve(&y_list.p);
|
||||
|
||||
for (int i = 0; i < 50; i++){
|
||||
s->scene.mpc_y[i] = capn_to_f32(capn_get32(y_list, i));
|
||||
scene.mpc_x[i] = x_list[i];
|
||||
scene.mpc_y[i] = y_list[i];
|
||||
}
|
||||
s->livempc_or_radarstate_changed = true;
|
||||
} else if (eventd.which == cereal_Event_uiLayoutState) {
|
||||
struct cereal_UiLayoutState datad;
|
||||
cereal_read_UiLayoutState(&datad, eventd.uiLayoutState);
|
||||
s->active_app = datad.activeApp;
|
||||
s->scene.uilayout_sidebarcollapsed = datad.sidebarCollapsed;
|
||||
if (datad.mockEngaged != s->scene.uilayout_mockengaged) {
|
||||
s->scene.uilayout_mockengaged = datad.mockEngaged;
|
||||
} else if (which == cereal::Event::UI_LAYOUT_STATE) {
|
||||
auto data = event.getUiLayoutState();
|
||||
|
||||
s->active_app = data.getActiveApp();
|
||||
scene.uilayout_sidebarcollapsed = data.getSidebarCollapsed();
|
||||
if (data.getMockEngaged() != scene.uilayout_mockengaged) {
|
||||
scene.uilayout_mockengaged = data.getMockEngaged();
|
||||
}
|
||||
} else if (eventd.which == cereal_Event_liveMapData) {
|
||||
struct cereal_LiveMapData datad;
|
||||
cereal_read_LiveMapData(&datad, eventd.liveMapData);
|
||||
s->scene.map_valid = datad.mapValid;
|
||||
} else if (eventd.which == cereal_Event_thermal) {
|
||||
struct cereal_ThermalData datad;
|
||||
cereal_read_ThermalData(&datad, eventd.thermal);
|
||||
|
||||
s->scene.networkType = datad.networkType;
|
||||
s->scene.networkStrength = datad.networkStrength;
|
||||
s->scene.batteryPercent = datad.batteryPercent;
|
||||
snprintf(s->scene.batteryStatus, sizeof(s->scene.batteryStatus), "%s", datad.batteryStatus.str);
|
||||
s->scene.freeSpace = datad.freeSpace;
|
||||
s->scene.thermalStatus = datad.thermalStatus;
|
||||
s->scene.paTemp = datad.pa0;
|
||||
|
||||
s->thermal_started = datad.started;
|
||||
|
||||
} else if (eventd.which == cereal_Event_ubloxGnss) {
|
||||
struct cereal_UbloxGnss datad;
|
||||
cereal_read_UbloxGnss(&datad, eventd.ubloxGnss);
|
||||
if (datad.which == cereal_UbloxGnss_measurementReport) {
|
||||
struct cereal_UbloxGnss_MeasurementReport reportdatad;
|
||||
cereal_read_UbloxGnss_MeasurementReport(&reportdatad, datad.measurementReport);
|
||||
s->scene.satelliteCount = reportdatad.numMeas;
|
||||
} else if (which == cereal::Event::LIVE_MAP_DATA) {
|
||||
scene.map_valid = event.getLiveMapData().getMapValid();
|
||||
} else if (which == cereal::Event::THERMAL) {
|
||||
auto data = event.getThermal();
|
||||
|
||||
scene.networkType = data.getNetworkType();
|
||||
scene.networkStrength = data.getNetworkStrength();
|
||||
scene.batteryPercent = data.getBatteryPercent();
|
||||
scene.batteryCharging = data.getBatteryStatus() == "Charging";
|
||||
scene.freeSpace = data.getFreeSpace();
|
||||
scene.thermalStatus = data.getThermalStatus();
|
||||
scene.paTemp = data.getPa0();
|
||||
|
||||
s->thermal_started = data.getStarted();
|
||||
} else if (which == cereal::Event::UBLOX_GNSS) {
|
||||
auto data = event.getUbloxGnss();
|
||||
if (data.which() == cereal::UbloxGnss::MEASUREMENT_REPORT) {
|
||||
scene.satelliteCount = data.getMeasurementReport().getNumMeas();
|
||||
}
|
||||
} else if (eventd.which == cereal_Event_health) {
|
||||
struct cereal_HealthData datad;
|
||||
cereal_read_HealthData(&datad, eventd.health);
|
||||
|
||||
s->scene.hwType = datad.hwType;
|
||||
} else if (which == cereal::Event::HEALTH) {
|
||||
scene.hwType = event.getHealth().getHwType();
|
||||
s->hardware_timeout = 5*30; // 5 seconds at 30 fps
|
||||
} else if (eventd.which == cereal_Event_driverState) {
|
||||
struct cereal_DriverState datad;
|
||||
cereal_read_DriverState(&datad, eventd.driverState);
|
||||
|
||||
s->scene.face_prob = datad.faceProb;
|
||||
|
||||
capn_list32 fxy_list = datad.facePosition;
|
||||
capn_resolve(&fxy_list.p);
|
||||
s->scene.face_x = capn_to_f32(capn_get32(fxy_list, 0));
|
||||
s->scene.face_y = capn_to_f32(capn_get32(fxy_list, 1));
|
||||
} else if (eventd.which == cereal_Event_dMonitoringState) {
|
||||
struct cereal_DMonitoringState datad;
|
||||
cereal_read_DMonitoringState(&datad, eventd.dMonitoringState);
|
||||
|
||||
s->scene.is_rhd = datad.isRHD;
|
||||
s->scene.awareness_status = datad.awarenessStatus;
|
||||
s->preview_started = datad.isPreview;
|
||||
} else if (which == cereal::Event::DRIVER_STATE) {
|
||||
auto data = event.getDriverState();
|
||||
scene.face_prob = data.getFaceProb();
|
||||
auto fxy_list = data.getFacePosition();
|
||||
scene.face_x = fxy_list[0];
|
||||
scene.face_y = fxy_list[1];
|
||||
} else if (which == cereal::Event::D_MONITORING_STATE) {
|
||||
auto data = event.getDMonitoringState();
|
||||
scene.is_rhd = data.getIsRHD();
|
||||
scene.awareness_status = data.getAwarenessStatus();
|
||||
s->preview_started = data.getIsPreview();
|
||||
}
|
||||
|
||||
s->started = s->thermal_started || s->preview_started ;
|
||||
|
@ -598,17 +516,15 @@ void handle_message(UIState *s, Message * msg) {
|
|||
s->alert_sound_timeout = 0;
|
||||
s->vision_seen = false;
|
||||
s->controls_seen = false;
|
||||
s->active_app = cereal_UiLayoutState_App_home;
|
||||
s->active_app = cereal::UiLayoutState::App::HOME;
|
||||
update_offroad_layout_state(s);
|
||||
}
|
||||
} else if (s->status == STATUS_STOPPED) {
|
||||
update_status(s, STATUS_DISENGAGED);
|
||||
|
||||
s->active_app = cereal_UiLayoutState_App_none;
|
||||
s->active_app = cereal::UiLayoutState::App::NONE;
|
||||
update_offroad_layout_state(s);
|
||||
}
|
||||
|
||||
capn_free(&ctx);
|
||||
}
|
||||
|
||||
static void check_messages(UIState *s) {
|
||||
|
@ -619,12 +535,11 @@ static void check_messages(UIState *s) {
|
|||
break;
|
||||
|
||||
for (auto sock : polls){
|
||||
Message * msg = sock->receive();
|
||||
if (msg == NULL) continue;
|
||||
|
||||
handle_message(s, msg);
|
||||
|
||||
delete msg;
|
||||
Message *msg = sock->receive();
|
||||
if (msg) {
|
||||
handle_message(s, msg);
|
||||
delete msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -938,8 +853,6 @@ int is_leon() {
|
|||
return strstr(str, "letv") != NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int err;
|
||||
setpriority(PRIO_PROCESS, 0, -14);
|
||||
|
@ -1054,7 +967,7 @@ int main(int argc, char* argv[]) {
|
|||
if (s->hardware_timeout > 0) {
|
||||
s->hardware_timeout--;
|
||||
} else {
|
||||
s->scene.hwType = cereal_HealthData_HwType_unknown;
|
||||
s->scene.hwType = cereal::HealthData::HwType::UNKNOWN;
|
||||
}
|
||||
|
||||
// Don't waste resources on drawing in case screen is off
|
||||
|
@ -1076,17 +989,18 @@ int main(int argc, char* argv[]) {
|
|||
if (s->controls_timeout > 0) {
|
||||
s->controls_timeout--;
|
||||
} else {
|
||||
if (s->started && s->controls_seen && strcmp(s->scene.alert_text2, "Controls Unresponsive") != 0) {
|
||||
if (s->started && s->controls_seen && s->scene.alert_text2 != "Controls Unresponsive") {
|
||||
LOGE("Controls unresponsive");
|
||||
s->scene.alert_size = ALERTSIZE_FULL;
|
||||
s->scene.alert_size = cereal::ControlsState::AlertSize::FULL;
|
||||
update_status(s, STATUS_ALERT);
|
||||
|
||||
snprintf(s->scene.alert_text1, sizeof(s->scene.alert_text1), "%s", "TAKE CONTROL IMMEDIATELY");
|
||||
snprintf(s->scene.alert_text2, sizeof(s->scene.alert_text2), "%s", "Controls Unresponsive");
|
||||
ui_draw_vision_alert(s, s->scene.alert_size, s->status, s->scene.alert_text1, s->scene.alert_text2);
|
||||
s->scene.alert_text1 = "TAKE CONTROL IMMEDIATELY";
|
||||
s->scene.alert_text2 = "Controls Unresponsive";
|
||||
|
||||
ui_draw_vision_alert(s, s->scene.alert_size, s->status, s->scene.alert_text1.c_str(), s->scene.alert_text2.c_str());
|
||||
|
||||
s->alert_sound_timeout = 2 * UI_FREQ;
|
||||
s->alert_sound = cereal_CarControl_HUDControl_AudibleAlert_chimeWarningRepeat;
|
||||
s->alert_sound = cereal::CarControl::HUDControl::AudibleAlert::CHIME_WARNING_REPEAT;
|
||||
play_alert_sound(s->alert_sound);
|
||||
}
|
||||
|
||||
|
@ -1096,9 +1010,9 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
// stop playing alert sound
|
||||
if ((!s->started || (s->started && s->alert_sound_timeout == 0)) &&
|
||||
s->alert_sound != cereal_CarControl_HUDControl_AudibleAlert_none) {
|
||||
s->alert_sound != cereal::CarControl::HUDControl::AudibleAlert::NONE) {
|
||||
stop_alert_sound(s->alert_sound);
|
||||
s->alert_sound = cereal_CarControl_HUDControl_AudibleAlert_none;
|
||||
s->alert_sound = cereal::CarControl::HUDControl::AudibleAlert::NONE;
|
||||
}
|
||||
|
||||
read_param_bool_timeout(&s->is_metric, "IsMetric", &s->is_metric_timeout);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef _UI_H
|
||||
#define _UI_H
|
||||
|
||||
#include "cereal/gen/cpp/log.capnp.h"
|
||||
#ifdef __APPLE__
|
||||
#include <OpenGL/gl3.h>
|
||||
#define NANOVG_GL3_IMPLEMENTATION
|
||||
|
@ -14,7 +14,6 @@
|
|||
|
||||
#include <capnp/serialize.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "nanovg.h"
|
||||
|
||||
#include "common/mat.h"
|
||||
|
@ -23,8 +22,6 @@
|
|||
#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
|
||||
|
@ -37,11 +34,6 @@
|
|||
#define NET_DISCONNECTED 1
|
||||
#define NET_ERROR 2
|
||||
|
||||
#define ALERTSIZE_NONE 0
|
||||
#define ALERTSIZE_SMALL 1
|
||||
#define ALERTSIZE_MID 2
|
||||
#define ALERTSIZE_FULL 3
|
||||
|
||||
#define COLOR_BLACK nvgRGBA(0, 0, 0, 255)
|
||||
#define COLOR_BLACK_ALPHA(x) nvgRGBA(0, 0, 0, x)
|
||||
#define COLOR_WHITE nvgRGBA(255, 255, 255, 255)
|
||||
|
@ -148,9 +140,9 @@ typedef struct UIScene {
|
|||
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;
|
||||
std::string alert_text1;
|
||||
std::string alert_text2;
|
||||
cereal::ControlsState::AlertSize alert_size;
|
||||
float alert_blinkingrate;
|
||||
|
||||
float awareness_status;
|
||||
|
@ -158,14 +150,14 @@ typedef struct UIScene {
|
|||
// Used to show gps planner status
|
||||
bool gps_planner_active;
|
||||
|
||||
uint8_t networkType;
|
||||
uint8_t networkStrength;
|
||||
cereal::ThermalData::NetworkType networkType;
|
||||
cereal::ThermalData::NetworkStrength networkStrength;
|
||||
int batteryPercent;
|
||||
char batteryStatus[64];
|
||||
bool batteryCharging;
|
||||
float freeSpace;
|
||||
uint8_t thermalStatus;
|
||||
cereal::ThermalData::ThermalStatus thermalStatus;
|
||||
int paTemp;
|
||||
int hwType;
|
||||
cereal::HealthData::HwType hwType;
|
||||
int satelliteCount;
|
||||
uint8_t athenaStatus;
|
||||
} UIScene;
|
||||
|
@ -227,7 +219,7 @@ typedef struct UIState {
|
|||
Poller * poller;
|
||||
Poller * ublox_poller;
|
||||
|
||||
int active_app;
|
||||
cereal::UiLayoutState::App active_app;
|
||||
|
||||
// vision state
|
||||
bool vision_connected;
|
||||
|
@ -282,9 +274,8 @@ typedef struct UIState {
|
|||
bool limit_set_speed;
|
||||
float speed_lim_off;
|
||||
bool is_ego_over_limit;
|
||||
char alert_type[64];
|
||||
std::string alert_type;
|
||||
AudibleAlert alert_sound;
|
||||
int alert_size;
|
||||
float alert_blinking_alpha;
|
||||
bool alert_blinked;
|
||||
bool started;
|
||||
|
@ -308,7 +299,7 @@ typedef struct UIState {
|
|||
} UIState;
|
||||
|
||||
// API
|
||||
void ui_draw_vision_alert(UIState *s, int va_size, int va_color,
|
||||
void ui_draw_vision_alert(UIState *s, cereal::ControlsState::AlertSize va_size, int va_color,
|
||||
const char* va_text1, const char* va_text2);
|
||||
void ui_draw(UIState *s);
|
||||
void ui_draw_sidebar(UIState *s);
|
||||
|
|
Loading…
Reference in New Issue