Driveline: write labels only on change (idle 9.7 fps -> 0); perf: panel vsync counter + esp_timer reporting
Firmware / build (push) Successful in 4m2s
Firmware / build (push) Successful in 4m2s
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "driveline_screen.h"
|
||||
#include "uart_manager.h"
|
||||
#include <string.h>
|
||||
#include "display/lvgl_v8_port.h"
|
||||
#include "drivers/can_driver.h"
|
||||
#include "tuning_screen.h"
|
||||
@@ -67,12 +68,29 @@ static lv_obj_t* makeChip(lv_obj_t* parent, const char* text) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a chip's text and colour in one go.
|
||||
* @brief lv_label_set_text() only if the text differs. lv_label_set_text()
|
||||
* re-lays-out and invalidates the label even when the string is the
|
||||
* same, and this screen refreshes at 10 Hz - with constant data that was
|
||||
* ~40 kpx redrawn 10x a second for nothing, a third of core 1 and 50 ms/s
|
||||
* of PSRAM writes (perf baseline 2026-09-27).
|
||||
*/
|
||||
static void setText(lv_obj_t* lbl, const char* text) {
|
||||
if (lbl == NULL) return;
|
||||
const char* cur = lv_label_get_text(lbl);
|
||||
if (cur != NULL && strcmp(cur, text) == 0) return;
|
||||
lv_label_set_text(lbl, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a chip's text and colour, touching the object only on a change
|
||||
* (a style write invalidates the object even for an identical value).
|
||||
*/
|
||||
static void setChip(lv_obj_t* chip, const char* text, lv_color_t colour) {
|
||||
if (chip == NULL) return;
|
||||
lv_label_set_text(chip, text);
|
||||
lv_obj_set_style_text_color(chip, colour, 0);
|
||||
setText(chip, text);
|
||||
if (lv_color_to32(lv_obj_get_style_text_color(chip, 0)) != lv_color_to32(colour)) {
|
||||
lv_obj_set_style_text_color(chip, colour, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -292,13 +310,13 @@ void tick() {
|
||||
// quiet with the car rather than freezing the last frame. 0x3B4 sends its
|
||||
// ignition nibble on-change, so this reset is effectively instant.
|
||||
if (!can_up || !dl.ignition_on) {
|
||||
lv_label_set_text(g_gear_lbl, "--");
|
||||
lv_label_set_text(g_coolant_lbl, "--");
|
||||
lv_label_set_text(g_gearbox_lbl, "--");
|
||||
lv_label_set_text(g_rpm_lbl, "----");
|
||||
lv_label_set_text(g_torque_lbl, "--");
|
||||
lv_label_set_text(g_pedal_lbl, "--");
|
||||
lv_label_set_text(g_shaft_lbl, "--");
|
||||
setText(g_gear_lbl, "--");
|
||||
setText(g_coolant_lbl, "--");
|
||||
setText(g_gearbox_lbl, "--");
|
||||
setText(g_rpm_lbl, "----");
|
||||
setText(g_torque_lbl, "--");
|
||||
setText(g_pedal_lbl, "--");
|
||||
setText(g_shaft_lbl, "--");
|
||||
lv_bar_set_value(g_rpm_bar, 0, LV_ANIM_OFF);
|
||||
lv_obj_add_flag(g_mismatch_lbl, LV_OBJ_FLAG_HIDDEN);
|
||||
// Leave the ignition chip telling the truth; mute the rest, since their
|
||||
@@ -319,37 +337,37 @@ void tick() {
|
||||
// ---- gear (composed: P/R/N, or D/S/M + engaged number) ---------------
|
||||
if ((gear_position_t)dl.lever != GEAR_UNKNOWN) {
|
||||
composeGear(dl, buf, sizeof(buf));
|
||||
lv_label_set_text(g_gear_lbl, buf);
|
||||
setText(g_gear_lbl, buf);
|
||||
} else {
|
||||
lv_label_set_text(g_gear_lbl, "--");
|
||||
setText(g_gear_lbl, "--");
|
||||
}
|
||||
|
||||
// ---- temperatures (only when the signal is real) ---------------------
|
||||
if (flags & VALID_FLAG_COOLANT_TEMP) {
|
||||
snprintf(buf, sizeof(buf), "%d.%d°C", coolant / 10, abs(coolant % 10));
|
||||
lv_label_set_text(g_coolant_lbl, buf);
|
||||
setText(g_coolant_lbl, buf);
|
||||
}
|
||||
if (flags & VALID_FLAG_GEARBOX_TEMP) {
|
||||
snprintf(buf, sizeof(buf), "%d.%d°C", gearbox / 10, abs(gearbox % 10));
|
||||
lv_label_set_text(g_gearbox_lbl, buf);
|
||||
setText(g_gearbox_lbl, buf);
|
||||
}
|
||||
|
||||
// ---- speeds ----------------------------------------------------------
|
||||
snprintf(buf, sizeof(buf), "%u", dl.engine_rpm);
|
||||
lv_label_set_text(g_rpm_lbl, buf);
|
||||
setText(g_rpm_lbl, buf);
|
||||
lv_bar_set_value(g_rpm_bar, dl.engine_rpm > RPM_MAX ? RPM_MAX : dl.engine_rpm, LV_ANIM_OFF);
|
||||
|
||||
// Torque is signed (negative under overrun/braking); one decimal, matching
|
||||
// the 0.5 Nm resolution of the field.
|
||||
snprintf(buf, sizeof(buf), "%d.%d", dl.engine_torque_x10 / 10, abs(dl.engine_torque_x10 % 10));
|
||||
lv_label_set_text(g_torque_lbl, buf);
|
||||
setText(g_torque_lbl, buf);
|
||||
|
||||
snprintf(buf, sizeof(buf), "%u", dl.pedal_percent);
|
||||
lv_label_set_text(g_pedal_lbl, buf);
|
||||
setText(g_pedal_lbl, buf);
|
||||
|
||||
// Provisional rpm from the single-point Launch factor (see automotive_data.h).
|
||||
snprintf(buf, sizeof(buf), "%u", can_output_shaft_rpm(dl.output_shaft_raw));
|
||||
lv_label_set_text(g_shaft_lbl, buf);
|
||||
setText(g_shaft_lbl, buf);
|
||||
|
||||
// ---- status chips ----------------------------------------------------
|
||||
setChip(g_ign_chip, dl.ignition_on ? "IGN ON" : "IGN OFF",
|
||||
|
||||
Reference in New Issue
Block a user