UI: add function ui_read_params (#19565)

* ui_read_params

* remove last_athena_ping from UIState

* use s->sm->frame
pull/19574/head
Dean Lee 4 years ago committed by GitHub
parent 389649d6ac
commit c1cde2d148
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      selfdrive/ui/ui.cc
  2. 1
      selfdrive/ui/ui.hpp

@ -29,7 +29,6 @@ void ui_init(UIState *s) {
s->started = false;
s->status = STATUS_OFFROAD;
s->scene.satelliteCount = -1;
read_param(&s->is_metric, "IsMetric");
s->fb = framebuffer_init("ui", 0, true, &s->fb_w, &s->fb_h);
assert(s->fb);
@ -238,8 +237,26 @@ void update_sockets(UIState *s) {
s->started = scene.thermal.getStarted() || scene.frontview;
}
void ui_update(UIState *s) {
static void ui_read_params(UIState *s) {
const uint64_t frame = s->sm->frame;
if (frame % (5*UI_FREQ) == 0) {
read_param(&s->is_metric, "IsMetric");
} else if (frame % (6*UI_FREQ) == 0) {
uint64_t last_athena_ping = 0;
int param_read = read_param(&last_athena_ping, "LastAthenaPingTime");
if (param_read != 0) { // Failed to read param
s->scene.athenaStatus = NET_DISCONNECTED;
} else if (nanos_since_boot() - last_athena_ping < 70e9) {
s->scene.athenaStatus = NET_CONNECTED;
} else {
s->scene.athenaStatus = NET_ERROR;
}
}
}
void ui_update(UIState *s) {
ui_read_params(s);
update_sockets(s);
ui_update_vision(s);
@ -293,18 +310,4 @@ void ui_update(UIState *s) {
s->sound->stop();
}
}
// Read params
if ((s->sm)->frame % (5*UI_FREQ) == 0) {
read_param(&s->is_metric, "IsMetric");
} else if ((s->sm)->frame % (6*UI_FREQ) == 0) {
int param_read = read_param(&s->last_athena_ping, "LastAthenaPingTime");
if (param_read != 0) { // Failed to read param
s->scene.athenaStatus = NET_DISCONNECTED;
} else if (nanos_since_boot() - s->last_athena_ping < 70e9) {
s->scene.athenaStatus = NET_CONNECTED;
} else {
s->scene.athenaStatus = NET_ERROR;
}
}
}

@ -192,7 +192,6 @@ typedef struct UIState {
bool ignition;
bool is_metric;
bool longitudinal_control;
uint64_t last_athena_ping;
uint64_t started_frame;
bool alert_blinked;

Loading…
Cancel
Save