Params: python-like interface (#20506)

* rebase master

* delete outdated test_params.c

* putBool & more robust getBool

* putBool(SshEnabled)
old-commit-hash: 98e55996f67aaaf715c941d417ae4d3b0187f388
This commit is contained in:
Dean Lee
2021-03-30 18:54:59 +08:00
committed by GitHub
parent 60b3018b96
commit 405df8b165
22 changed files with 111 additions and 252 deletions
+6 -14
View File
@@ -10,13 +10,6 @@
#include "ui.hpp"
#include "paint.hpp"
int write_param_float(float param, const char* param_name, bool persistent_param) {
char s[16];
int size = snprintf(s, sizeof(s), "%f", param);
return Params(persistent_param).write_db_value(param_name, s, size < sizeof(s) ? size : sizeof(s));
}
// Projects a point in car to space to the corresponding point in full frame
// image space.
static bool calib_frame_to_full_frame(const UIState *s, float in_x, float in_y, float in_z, vertex_data *out) {
@@ -279,14 +272,13 @@ static void update_alert(UIState *s) {
static void update_params(UIState *s) {
const uint64_t frame = s->sm->frame;
UIScene &scene = s->scene;
Params params;
if (frame % (5*UI_FREQ) == 0) {
read_param(&scene.is_metric, "IsMetric");
scene.is_metric = params.getBool("IsMetric");
} else if (frame % (6*UI_FREQ) == 0) {
scene.athenaStatus = NET_DISCONNECTED;
uint64_t last_ping = 0;
if (read_param(&last_ping, "LastAthenaPingTime") == 0) {
scene.athenaStatus = nanos_since_boot() - last_ping < 70e9 ? NET_CONNECTED : NET_ERROR;
if (auto last_ping = params.get<float>("LastAthenaPingTime"); last_ping) {
scene.athenaStatus = nanos_since_boot() - *last_ping < 70e9 ? NET_CONNECTED : NET_ERROR;
}
}
}
@@ -329,8 +321,8 @@ static void update_status(UIState *s) {
s->status = STATUS_DISENGAGED;
s->scene.started_frame = s->sm->frame;
read_param(&s->scene.is_rhd, "IsRHD");
read_param(&s->scene.end_to_end, "EndToEndToggle");
s->scene.is_rhd = Params().getBool("IsRHD");
s->scene.end_to_end = Params().getBool("EndToEndToggle");
s->sidebar_collapsed = true;
s->scene.alert_size = cereal::ControlsState::AlertSize::NONE;
s->vipc_client = s->scene.driver_view ? s->vipc_client_front : s->vipc_client_rear;