mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-02 03:52:11 +08:00
Refactor alert blinking (#19583)
* add function get_alert_alpha() * continue simplify * reset alpha to 1.0 if blink_rate is 0 * review * sine wave * rebase master * use time * use cos old-commit-hash: de309b156d2e9b9c2b771ccdd84915708f64338a
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include "common/util.h"
|
||||
#include "common/timing.h"
|
||||
#include <algorithm>
|
||||
|
||||
#define NANOVG_GLES3_IMPLEMENTATION
|
||||
@@ -344,6 +345,10 @@ static void ui_draw_vision_footer(UIState *s) {
|
||||
ui_draw_vision_face(s);
|
||||
}
|
||||
|
||||
static float get_alert_alpha(float blink_rate) {
|
||||
return 0.375 * cos((millis_since_boot() / 1000) * 2 * M_PI * blink_rate) + 0.625;
|
||||
}
|
||||
|
||||
static void ui_draw_vision_alert(UIState *s) {
|
||||
static std::map<cereal::ControlsState::AlertSize, const int> alert_size_map = {
|
||||
{cereal::ControlsState::AlertSize::SMALL, 241},
|
||||
@@ -353,7 +358,7 @@ static void ui_draw_vision_alert(UIState *s) {
|
||||
bool longAlert1 = scene->alert_text1.length() > 15;
|
||||
|
||||
NVGcolor color = bg_colors[s->status];
|
||||
color.a *= s->alert_blinking_alpha;
|
||||
color.a *= get_alert_alpha(scene->alert_blinking_rate);
|
||||
int alr_s = alert_size_map[scene->alert_size];
|
||||
|
||||
const int alr_x = scene->viz_rect.x - bdr_s;
|
||||
|
||||
+1
-20
@@ -151,6 +151,7 @@ void update_sockets(UIState *s) {
|
||||
scene.alert_text2 = scene.controls_state.getAlertText2();
|
||||
scene.alert_size = scene.controls_state.getAlertSize();
|
||||
scene.alert_type = scene.controls_state.getAlertType();
|
||||
scene.alert_blinking_rate = scene.controls_state.getAlertBlinkingRate();
|
||||
auto alertStatus = scene.controls_state.getAlertStatus();
|
||||
if (alertStatus == cereal::ControlsState::AlertStatus::USER_PROMPT) {
|
||||
s->status = STATUS_WARNING;
|
||||
@@ -159,24 +160,6 @@ void update_sockets(UIState *s) {
|
||||
} else {
|
||||
s->status = scene.controls_state.getEnabled() ? STATUS_ENGAGED : STATUS_DISENGAGED;
|
||||
}
|
||||
|
||||
float alert_blinkingrate = scene.controls_state.getAlertBlinkingRate();
|
||||
if (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*alert_blinkingrate);
|
||||
} else {
|
||||
s->alert_blinked = false;
|
||||
}
|
||||
} else {
|
||||
if (s->alert_blinking_alpha > 0.25) {
|
||||
s->alert_blinking_alpha -= (0.05*alert_blinkingrate);
|
||||
} else {
|
||||
s->alert_blinking_alpha += 0.25;
|
||||
s->alert_blinked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sm.updated("radarState")) {
|
||||
auto data = sm["radarState"].getRadarState();
|
||||
@@ -289,8 +272,6 @@ void ui_update(UIState *s) {
|
||||
|
||||
s->active_app = cereal::UiLayoutState::App::NONE;
|
||||
s->scene.sidebar_collapsed = true;
|
||||
s->alert_blinked = false;
|
||||
s->alert_blinking_alpha = 1.0;
|
||||
s->scene.alert_size = cereal::ControlsState::AlertSize::NONE;
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -115,6 +115,7 @@ typedef struct UIScene {
|
||||
std::string alert_text1;
|
||||
std::string alert_text2;
|
||||
std::string alert_type;
|
||||
float alert_blinking_rate;
|
||||
cereal::ControlsState::AlertSize alert_size;
|
||||
|
||||
cereal::HealthData::HwType hwType;
|
||||
@@ -187,9 +188,6 @@ typedef struct UIState {
|
||||
bool longitudinal_control;
|
||||
uint64_t started_frame;
|
||||
|
||||
bool alert_blinked;
|
||||
float alert_blinking_alpha;
|
||||
|
||||
Rect video_rect;
|
||||
} UIState;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user