Skip to content

Commit

Permalink
Added tbui inforbar + preventing screen from turning of if dashcam is…
Browse files Browse the repository at this point in the history
… recording. (commaai#129)

* added recording bool

* Added recording state from bbuistate

* prevent UI from turning of if we are recording with dashcam

* Adding tbui.h

* Added the infobar from tbui.h

* I was missing
  • Loading branch information
tb205gti authored and BogGyver committed Nov 18, 2019
1 parent c224032 commit 958993d
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 5 deletions.
1 change: 1 addition & 0 deletions selfdrive/ui/bbuistate.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ typedef struct BBUIState {
bool chargingEnabled;
uint16_t fanSpeed;
bool keepEonOff;
bool recording;
} BBUIState;
9 changes: 6 additions & 3 deletions selfdrive/ui/dashcam.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,15 @@ static void screen_draw_button(UIState *s, int touch_x, int touch_y) {
}
}

void screen_toggle_record_state() {
void screen_toggle_record_state(UIState *s) {
if (captureState == CAPTURE_STATE_CAPTURING) {
s->b.recording = false;
stop_capture();
lock_current_video = false;
}
else {
//captureState = CAPTURE_STATE_CAPTURING;
s->b.recording = true;
start_capture();
}
}
Expand All @@ -298,13 +300,14 @@ void screen_toggle_lock() {
void dashcam( UIState *s, int touch_x, int touch_y ) {
screen_draw_button(s, touch_x, touch_y);
if (screen_button_clicked(touch_x,touch_y)) {
screen_toggle_record_state();
screen_toggle_record_state(s);
}
if (screen_lock_button_clicked(touch_x,touch_y,lock_button)) {
screen_toggle_lock();
}
if (!s->vision_connected) {
// Assume car is not in drive so stop recording
s->b.recording = false;
stop_capture();
}
}
}
72 changes: 72 additions & 0 deletions selfdrive/ui/tbui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

static void ui_draw_infobar(UIState *s) {
const UIScene *scene = &s->scene;
int ui_viz_rx = scene->ui_viz_rx;
bool hasSidebar = !s->scene.uilayout_sidebarcollapsed;
int rect_w = vwp_w - ui_viz_rx - bdr_s;
int rect_h = 60;
int rect_x = 0;
// rect_y = screen height - board - background height
int rect_y = vwp_h - bdr_s - (int) (rect_h/2) - 5;
rect_x = rect_x + ui_viz_rx;

int text_x = rect_w / 2;
text_x = text_x + ui_viz_rx;
int text_y = rect_y + 45;

// Get local time to display
char infobar[68];
time_t t = time(NULL);
struct tm tm = *localtime(&t);

char spd[5];
snprintf(spd, sizeof(spd), "%i ", (int) (s->scene.v_ego * 3.6 + 0.5));

char ang_steer[9];
snprintf(ang_steer, sizeof(ang_steer), "%s%03.1f°", s->b.angleSteers < 0? "-" : "+", fabs(s->b.angleSteers));

char lead_dist[8];
if (s->scene.lead_status) {
snprintf(lead_dist, sizeof(lead_dist), "%05.2fm", s->scene.lead_d_rel);
} else {
snprintf(lead_dist, sizeof(lead_dist), "%3s", "N/A");
}

char maxspeed_str[12];
float maxspeed = s->scene.v_cruise;
int maxspeed_calc = maxspeed + 0.5;
bool is_cruise_set = (maxspeed > 5 && maxspeed != 255);

if (s->scene.engaged && is_cruise_set) {
snprintf(maxspeed_str, sizeof(maxspeed_str), "(%d) Kmh", maxspeed_calc);
} else{
snprintf(maxspeed_str, sizeof(maxspeed_str), "%s", "(--) Kmh");
}

snprintf(
infobar,
sizeof(infobar),
"%04d/%02d/%02d %02d:%02d:%02d | %s %s | DST: %s | ANG: %s",
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec,
spd,
maxspeed_str,
lead_dist,
ang_steer
);

nvgBeginPath(s->vg);
nvgRoundedRect(s->vg, rect_x, rect_y, rect_w, rect_h, 5);
nvgFillColor(s->vg, nvgRGBA(0, 0, 0, 180));
nvgFill(s->vg);

nvgFontSize(s->vg, hasSidebar? 40:50);
nvgFontFace(s->vg, "courbd");
nvgFillColor(s->vg, nvgRGBA(255, 255, 255, 180));
nvgTextAlign(s->vg, NVG_ALIGN_CENTER);
nvgText(s->vg, text_x, text_y, infobar, NULL);
}
9 changes: 7 additions & 2 deletions selfdrive/ui/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ static void set_brightness(UIState *s, int brightness) {
static void set_awake(UIState *s, bool awake) {
if (awake) {
// 30 second timeout at 30 fps
if ((s->b.tri_state_switch == 3) || (s->b.keepEonOff)) {
if (((s->b.tri_state_switch == 3) || (s->b.keepEonOff)) && !s->b.recording) {
s->awake_timeout = 3*30;
} else {
s->awake_timeout = 30*30;
Expand All @@ -347,6 +347,7 @@ static void set_awake(UIState *s, bool awake) {

#include "dashcam.h"
#include "bbui.h"
#include "tbui.h"

static void set_volume(UIState *s, int volume) {
char volume_change_cmd[64];
Expand Down Expand Up @@ -1465,8 +1466,12 @@ static void ui_draw_vision_footer(UIState *s) {
#ifdef SHOW_SPEEDLIMIT
// ui_draw_vision_map(s);
#endif

ui_draw_infobar(s);
}



static void ui_draw_vision_alert(UIState *s, int va_size, int va_color,
const char* va_text1, const char* va_text2) {
const UIScene *scene = &s->scene;
Expand Down Expand Up @@ -2024,7 +2029,7 @@ static void ui_update(UIState *s) {
delete msg;
}

if ((awake) && (s->b.tri_state_switch != 3) && (!s->b.keepEonOff)){
if (((awake) && (s->b.tri_state_switch != 3) && (!s->b.keepEonOff)) || (s->b.recording)){
set_awake(s, true);
}
}
Expand Down

0 comments on commit 958993d

Please sign in to comment.