e68fad73b6
Firmware / build (push) Successful in 3m58s
Settings (replaces the SquareLine screen, now deleted): sidebar with Wi-Fi (switch, status card with failure reasons, networks nearby, full-screen password page), Updates (installed vs latest, Check, Install behind a confirm dialog) and System (CAN / link / perf overlay switches, live link, CAN, memory, uptime). Gauge Tuning: tabs Tachometer / Coolant gauge / Alerts / Simulation, 56 px -/+ rows with hints and real units, accelerating hold-to-repeat, per-tab Reset with confirm, save indicator, SIMULATION ON chip, swipe left to go back. WiFiManager rewritten without LVGL code: one remembered network (NVS "wifi"), auto-join at boot, scans only on request, no endless reconnect (keeps the ESP-NOW channel stable), failure reasons from the disconnect event, password never logged. Ota gains getStatus()/requestCheck()/ requestInstall() for the screen. CAN/UART switches become setEnabled(). Shared ui_kit (header, buttons, switches, confirm dialog); Montserrat 20/24 enabled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
589 lines
23 KiB
C++
589 lines
23 KiB
C++
/*
|
|
* Gauge Tuning Screen Module Implementation
|
|
*
|
|
* Four tabs (Tachometer / Coolant gauge / Alerts / Simulation), one value per
|
|
* row with a plain-language hint, car-sized -/+ buttons (hold to repeat,
|
|
* speeding up the longer you hold). Tabs are plain buttons + hidden panels:
|
|
* no sliding tabview animation, which re-renders the whole panel per frame.
|
|
*/
|
|
|
|
#include "tuning_screen.h"
|
|
#include "tunables.h"
|
|
#include "ui_kit.h"
|
|
#include "driveline_screen.h"
|
|
#include "display/lvgl_v8_port.h"
|
|
#include "esp_log.h"
|
|
|
|
namespace TuningScreen
|
|
{
|
|
using namespace UiKit;
|
|
|
|
// ============================================================================
|
|
// FIELD TABLE - one row per numeric tunable
|
|
// ============================================================================
|
|
|
|
typedef enum
|
|
{
|
|
F_TACH_PPR,
|
|
F_TACH_TRIM,
|
|
F_TACH_MAX_HZ,
|
|
F_TEMP_HZ,
|
|
F_TEMP_SLOPE,
|
|
F_TEMP_OFFSET,
|
|
F_TEMP_MIN,
|
|
F_TEMP_DUTY_MAX,
|
|
F_COOLANT_HOT,
|
|
F_GEARBOX_HOT,
|
|
F_BATT_LOW,
|
|
F_COUNT
|
|
} field_t;
|
|
|
|
typedef enum { TAB_TACH, TAB_COOLANT, TAB_ALERTS, TAB_SIM, TAB_COUNT } tab_t;
|
|
|
|
typedef struct
|
|
{
|
|
field_t id;
|
|
tab_t tab;
|
|
const char *name;
|
|
const char *hint;
|
|
int32_t step;
|
|
int32_t min;
|
|
int32_t max;
|
|
lv_obj_t *value_lbl;
|
|
} row_t;
|
|
|
|
static row_t g_rows[F_COUNT] = {
|
|
{F_TACH_PPR, TAB_TACH, "Pulses per revolution", "Pulses per engine revolution the Patrol tach expects", 1, 1, 32, NULL},
|
|
{F_TACH_TRIM, TAB_TACH, "Trim", "Fine correction if the needle reads high or low", 1, -50, 50, NULL},
|
|
{F_TACH_MAX_HZ, TAB_TACH, "Maximum output", "Highest tach frequency sent (0 = no limit)", 10, 0, 5000, NULL},
|
|
{F_TEMP_HZ, TAB_COOLANT, "PWM frequency", "Drive frequency of the coolant gauge signal", 50, 20, 20000, NULL},
|
|
{F_TEMP_SLOPE, TAB_COOLANT, "Slope", "Duty added per \xC2\xB0" "C of coolant", 5, 0, 5000, NULL},
|
|
{F_TEMP_OFFSET, TAB_COOLANT, "Offset", "Duty at 0 \xC2\xB0" "C (duty = slope x temp + offset)", 1, -1000, 1000, NULL},
|
|
{F_TEMP_MIN, TAB_COOLANT, "Minimum temperature", "Needle stays at rest below this", 1, -50, 200, NULL},
|
|
{F_TEMP_DUTY_MAX, TAB_COOLANT, "Duty limit", "Highest duty sent (255 = full scale)", 5, 0, 255, NULL},
|
|
{F_COOLANT_HOT, TAB_ALERTS, "Coolant too hot", "Alarm on Controller B at or above this temperature", 1, 0, 200, NULL},
|
|
{F_GEARBOX_HOT, TAB_ALERTS, "Gearbox oil too hot", "Alarm on Controller B at or above this temperature", 1, 0, 200, NULL},
|
|
{F_BATT_LOW, TAB_ALERTS, "Battery low", "Alarm on Controller B below this voltage", 10, 0, 3000, NULL},
|
|
};
|
|
|
|
static const char *TAB_NAMES[TAB_COUNT] = {"Tachometer", "Coolant gauge", "Alerts", "Simulation"};
|
|
|
|
static int32_t getField(const link_config_t &c, field_t f)
|
|
{
|
|
switch (f)
|
|
{
|
|
case F_TACH_PPR: return c.tach_ppr;
|
|
case F_TACH_TRIM: return c.tach_trim_pct;
|
|
case F_TACH_MAX_HZ: return c.tach_max_hz;
|
|
case F_TEMP_HZ: return c.temp_pwm_hz;
|
|
case F_TEMP_SLOPE: return c.temp_slope_x100;
|
|
case F_TEMP_OFFSET: return c.temp_offset;
|
|
case F_TEMP_MIN: return c.temp_min_c;
|
|
case F_TEMP_DUTY_MAX: return c.temp_duty_max;
|
|
case F_COOLANT_HOT: return c.coolant_hot_c;
|
|
case F_GEARBOX_HOT: return c.gearbox_hot_c;
|
|
case F_BATT_LOW: return c.battery_low_x100;
|
|
default: return 0;
|
|
}
|
|
}
|
|
|
|
static void setField(link_config_t &c, field_t f, int32_t v)
|
|
{
|
|
switch (f)
|
|
{
|
|
case F_TACH_PPR: c.tach_ppr = (uint8_t)v; break;
|
|
case F_TACH_TRIM: c.tach_trim_pct = (int8_t)v; break;
|
|
case F_TACH_MAX_HZ: c.tach_max_hz = (uint16_t)v; break;
|
|
case F_TEMP_HZ: c.temp_pwm_hz = (uint16_t)v; break;
|
|
case F_TEMP_SLOPE: c.temp_slope_x100 = (uint16_t)v; break;
|
|
case F_TEMP_OFFSET: c.temp_offset = (int16_t)v; break;
|
|
case F_TEMP_MIN: c.temp_min_c = (int16_t)v; break;
|
|
case F_TEMP_DUTY_MAX: c.temp_duty_max = (uint8_t)v; break;
|
|
case F_COOLANT_HOT: c.coolant_hot_c = (int16_t)v; break;
|
|
case F_GEARBOX_HOT: c.gearbox_hot_c = (int16_t)v; break;
|
|
case F_BATT_LOW: c.battery_low_x100 = (uint16_t)v; break;
|
|
default: break;
|
|
}
|
|
}
|
|
|
|
static void formatValue(field_t f, int32_t v, char *out, size_t n)
|
|
{
|
|
switch (f)
|
|
{
|
|
case F_TACH_TRIM: snprintf(out, n, "%+ld %%", (long)v); break;
|
|
case F_TACH_MAX_HZ: if (v == 0) snprintf(out, n, "no limit"); else snprintf(out, n, "%ld Hz", (long)v); break;
|
|
case F_TEMP_HZ: snprintf(out, n, "%ld Hz", (long)v); break;
|
|
case F_TEMP_SLOPE: snprintf(out, n, "%ld.%02ld", (long)(v / 100), (long)labs(v % 100)); break;
|
|
case F_TEMP_OFFSET: snprintf(out, n, "%+ld", (long)v); break;
|
|
case F_TEMP_MIN:
|
|
case F_COOLANT_HOT:
|
|
case F_GEARBOX_HOT: snprintf(out, n, "%ld \xC2\xB0" "C", (long)v); break;
|
|
case F_TEMP_DUTY_MAX: snprintf(out, n, "%ld / 255", (long)v); break;
|
|
case F_BATT_LOW: snprintf(out, n, "%ld.%02ld V", (long)(v / 100), (long)(v % 100)); break;
|
|
default: snprintf(out, n, "%ld", (long)v); break;
|
|
}
|
|
}
|
|
|
|
// ============================================================================
|
|
// MODULE STATE
|
|
// ============================================================================
|
|
|
|
static lv_obj_t *g_screen = NULL;
|
|
static lv_obj_t *g_tab_btn[TAB_COUNT];
|
|
static lv_obj_t *g_tab_page[TAB_COUNT];
|
|
static tab_t g_tab = TAB_TACH;
|
|
static lv_obj_t *g_reset_btn = NULL;
|
|
static lv_obj_t *g_sim_chip = NULL;
|
|
static lv_obj_t *g_save_lbl = NULL;
|
|
static lv_obj_t *g_tach_en_sw = NULL;
|
|
static lv_obj_t *g_temp_en_sw = NULL;
|
|
static lv_obj_t *g_ovr_rpm_sw = NULL;
|
|
static lv_obj_t *g_ovr_duty_sw = NULL;
|
|
static lv_obj_t *g_ovr_rpm_sl = NULL;
|
|
static lv_obj_t *g_ovr_duty_sl = NULL;
|
|
static lv_obj_t *g_ovr_rpm_lbl = NULL;
|
|
static lv_obj_t *g_ovr_duty_lbl = NULL;
|
|
static uint8_t g_shown_version = 0;
|
|
static bool g_refreshing = false; // suppress event handlers while we set widget values
|
|
static uint16_t g_repeats = 0; // long-press repeat count of the button being held
|
|
|
|
static const int32_t RPM_MAX = 6000, RPM_STEP = 100;
|
|
static const int32_t DUTY_MAX = 255, DUTY_STEP = 5;
|
|
|
|
// ============================================================================
|
|
// REFRESH
|
|
// ============================================================================
|
|
|
|
static void refreshSaveState()
|
|
{
|
|
link_config_t c = Tunables::get();
|
|
const char *txt;
|
|
lv_color_t col = UI_COL_MUTED;
|
|
if (g_tab == TAB_SIM)
|
|
txt = "Simulation values are never saved - a restart returns to live data";
|
|
else if (Tunables::isDirty())
|
|
txt = "Saving...";
|
|
else
|
|
{
|
|
txt = LV_SYMBOL_OK " All changes saved";
|
|
col = UI_COL_OK;
|
|
}
|
|
setText(g_save_lbl, txt);
|
|
setTextColor(g_save_lbl, col);
|
|
setVisible(g_sim_chip, c.override_mode != 0);
|
|
}
|
|
|
|
static void refreshFromTunables()
|
|
{
|
|
link_config_t c = Tunables::get();
|
|
g_refreshing = true;
|
|
|
|
char buf[32];
|
|
for (int i = 0; i < F_COUNT; i++)
|
|
{
|
|
if (g_rows[i].value_lbl == NULL)
|
|
continue;
|
|
formatValue(g_rows[i].id, getField(c, g_rows[i].id), buf, sizeof(buf));
|
|
setText(g_rows[i].value_lbl, buf);
|
|
}
|
|
|
|
setChecked(g_tach_en_sw, c.out_enable & OUT_ENABLE_TACH);
|
|
setChecked(g_temp_en_sw, c.out_enable & OUT_ENABLE_TEMP);
|
|
setChecked(g_ovr_rpm_sw, c.override_mode & OVERRIDE_TACH);
|
|
setChecked(g_ovr_duty_sw, c.override_mode & OVERRIDE_TEMP);
|
|
|
|
if (g_ovr_rpm_sl && !lv_obj_has_state(g_ovr_rpm_sl, LV_STATE_PRESSED))
|
|
lv_slider_set_value(g_ovr_rpm_sl, c.override_rpm, LV_ANIM_OFF);
|
|
if (g_ovr_duty_sl && !lv_obj_has_state(g_ovr_duty_sl, LV_STATE_PRESSED))
|
|
lv_slider_set_value(g_ovr_duty_sl, c.override_duty, LV_ANIM_OFF);
|
|
snprintf(buf, sizeof(buf), "%u rpm", c.override_rpm);
|
|
setText(g_ovr_rpm_lbl, buf);
|
|
snprintf(buf, sizeof(buf), "%u / 255", c.override_duty);
|
|
setText(g_ovr_duty_lbl, buf);
|
|
|
|
refreshSaveState();
|
|
g_shown_version = c.cfg_version;
|
|
g_refreshing = false;
|
|
}
|
|
|
|
// ============================================================================
|
|
// EVENT HANDLERS
|
|
// ============================================================================
|
|
|
|
typedef struct
|
|
{
|
|
row_t *row;
|
|
int dir;
|
|
} step_ctx_t;
|
|
static step_ctx_t g_step_ctx[F_COUNT][2];
|
|
|
|
/** 1x for taps and the first second of a hold, then 5x, then 10x. */
|
|
static int32_t holdMultiplier(lv_event_code_t code)
|
|
{
|
|
if (code == LV_EVENT_PRESSED)
|
|
{
|
|
g_repeats = 0;
|
|
return 0;
|
|
}
|
|
if (code == LV_EVENT_LONG_PRESSED_REPEAT)
|
|
{
|
|
g_repeats++;
|
|
return g_repeats > 25 ? 10 : g_repeats > 10 ? 5 : 1;
|
|
}
|
|
return 1; // CLICKED
|
|
}
|
|
|
|
static void onStep(lv_event_t *e)
|
|
{
|
|
lv_event_code_t code = lv_event_get_code(e);
|
|
int32_t mult = holdMultiplier(code);
|
|
if (mult == 0)
|
|
return;
|
|
if (code == LV_EVENT_CLICKED && g_repeats > 0)
|
|
return; // end of a hold, already applied
|
|
step_ctx_t *ctx = (step_ctx_t *)lv_event_get_user_data(e);
|
|
link_config_t c = Tunables::get();
|
|
int32_t v = getField(c, ctx->row->id) + ctx->dir * ctx->row->step * mult;
|
|
v = constrain(v, ctx->row->min, ctx->row->max);
|
|
setField(c, ctx->row->id, v);
|
|
Tunables::set(c); // bumps version -> CONFIG frame goes out; NVS write after 3 s idle
|
|
refreshFromTunables();
|
|
}
|
|
|
|
static void onEnableSwitch(lv_event_t *e)
|
|
{
|
|
if (g_refreshing)
|
|
return;
|
|
bool on = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
|
|
uint8_t bit = (uint8_t)(uintptr_t)lv_event_get_user_data(e);
|
|
link_config_t c = Tunables::get();
|
|
c.out_enable = on ? (c.out_enable | bit) : (c.out_enable & ~bit);
|
|
Tunables::set(c);
|
|
refreshFromTunables();
|
|
}
|
|
|
|
static void pushOverride()
|
|
{
|
|
uint8_t mode = 0;
|
|
if (lv_obj_has_state(g_ovr_rpm_sw, LV_STATE_CHECKED))
|
|
mode |= OVERRIDE_TACH;
|
|
if (lv_obj_has_state(g_ovr_duty_sw, LV_STATE_CHECKED))
|
|
mode |= OVERRIDE_TEMP;
|
|
Tunables::setOverride(mode, (uint16_t)lv_slider_get_value(g_ovr_rpm_sl),
|
|
(uint8_t)lv_slider_get_value(g_ovr_duty_sl)); // pushed to B, never saved
|
|
refreshFromTunables();
|
|
}
|
|
|
|
static void onOverrideSwitch(lv_event_t *e)
|
|
{
|
|
(void)e;
|
|
if (!g_refreshing)
|
|
pushOverride();
|
|
}
|
|
|
|
static void onOverrideSlider(lv_event_t *e)
|
|
{
|
|
if (g_refreshing)
|
|
return;
|
|
lv_event_code_t code = lv_event_get_code(e);
|
|
lv_obj_t *sl = lv_event_get_target(e);
|
|
// Readout follows the finger; push to B on release so we don't flood
|
|
// the link with CONFIG frames at touch rate.
|
|
if (code == LV_EVENT_VALUE_CHANGED)
|
|
{
|
|
char buf[24];
|
|
if (sl == g_ovr_rpm_sl)
|
|
{
|
|
snprintf(buf, sizeof(buf), "%d rpm", (int)lv_slider_get_value(sl));
|
|
setText(g_ovr_rpm_lbl, buf);
|
|
}
|
|
else
|
|
{
|
|
snprintf(buf, sizeof(buf), "%d / 255", (int)lv_slider_get_value(sl));
|
|
setText(g_ovr_duty_lbl, buf);
|
|
}
|
|
}
|
|
else if (code == LV_EVENT_RELEASED)
|
|
{
|
|
pushOverride();
|
|
}
|
|
}
|
|
|
|
/** Fine -/+ next to a slider; user data = +/-1, slider picked by the button's parent row. */
|
|
static void onSimStep(lv_event_t *e)
|
|
{
|
|
lv_event_code_t code = lv_event_get_code(e);
|
|
int32_t mult = holdMultiplier(code);
|
|
if (mult == 0 || (code == LV_EVENT_CLICKED && g_repeats > 0))
|
|
return;
|
|
int dir = (int)(intptr_t)lv_event_get_user_data(e);
|
|
lv_obj_t *btn = lv_event_get_target(e);
|
|
bool rpm = lv_obj_get_parent(btn) == lv_obj_get_parent(g_ovr_rpm_sl);
|
|
lv_obj_t *sl = rpm ? g_ovr_rpm_sl : g_ovr_duty_sl;
|
|
int32_t v = lv_slider_get_value(sl) + dir * (rpm ? RPM_STEP : DUTY_STEP) * mult;
|
|
lv_slider_set_value(sl, constrain(v, 0, rpm ? RPM_MAX : DUTY_MAX), LV_ANIM_OFF);
|
|
pushOverride();
|
|
}
|
|
|
|
static void onBack(lv_event_t *e)
|
|
{
|
|
(void)e;
|
|
Tunables::flush(); // write pending edits now rather than after the idle delay
|
|
DrivelineScreen::show();
|
|
}
|
|
|
|
static void onGesture(lv_event_t *e)
|
|
{
|
|
(void)e;
|
|
if (lv_indev_get_gesture_dir(lv_indev_get_act()) == LV_DIR_LEFT)
|
|
{
|
|
lv_indev_wait_release(lv_indev_get_act());
|
|
Tunables::flush();
|
|
DrivelineScreen::show();
|
|
}
|
|
}
|
|
|
|
static void onResetConfirmed(bool ok, void *user)
|
|
{
|
|
if (!ok)
|
|
return;
|
|
tab_t tab = (tab_t)(uintptr_t)user;
|
|
link_config_t d, c = Tunables::get();
|
|
link_config_defaults(&d);
|
|
for (int i = 0; i < F_COUNT; i++)
|
|
if (g_rows[i].tab == tab)
|
|
setField(c, g_rows[i].id, getField(d, g_rows[i].id));
|
|
uint8_t bit = tab == TAB_TACH ? OUT_ENABLE_TACH : tab == TAB_COOLANT ? OUT_ENABLE_TEMP : 0;
|
|
c.out_enable = (c.out_enable & ~bit) | (d.out_enable & bit);
|
|
Tunables::set(c);
|
|
refreshFromTunables();
|
|
}
|
|
|
|
static void onReset(lv_event_t *e)
|
|
{
|
|
(void)e;
|
|
char title[64];
|
|
snprintf(title, sizeof(title), "Reset %s?", TAB_NAMES[g_tab]);
|
|
confirm(title, "Every value on this tab goes back to its default. The other tabs are not touched.",
|
|
"Reset", onResetConfirmed, (void *)(uintptr_t)g_tab);
|
|
}
|
|
|
|
static void selectTab(tab_t t)
|
|
{
|
|
g_tab = t;
|
|
for (int i = 0; i < TAB_COUNT; i++)
|
|
{
|
|
bool on = (i == t);
|
|
setVisible(g_tab_page[i], on);
|
|
lv_obj_set_style_bg_color(g_tab_btn[i], on ? UI_COL_ACCENT : UI_COL_PANEL, 0);
|
|
lv_obj_set_style_text_color(g_tab_btn[i], on ? lv_color_hex(0x0B1620) : UI_COL_TEXT, 0);
|
|
}
|
|
setVisible(g_reset_btn, t != TAB_SIM);
|
|
refreshSaveState();
|
|
}
|
|
|
|
static void onTab(lv_event_t *e)
|
|
{
|
|
selectTab((tab_t)(uintptr_t)lv_event_get_user_data(e));
|
|
}
|
|
|
|
// ============================================================================
|
|
// BUILDERS
|
|
// ============================================================================
|
|
|
|
static lv_obj_t *makeStepBtn(lv_obj_t *parent, const char *txt, lv_event_cb_t cb, void *ctx)
|
|
{
|
|
lv_obj_t *b = button(parent, txt, 76, 56, BTN_SECONDARY, NULL, NULL);
|
|
lv_obj_set_style_text_font(lv_obj_get_child(b, 0), &lv_font_montserrat_24, 0);
|
|
lv_obj_add_event_cb(b, cb, LV_EVENT_PRESSED, ctx);
|
|
lv_obj_add_event_cb(b, cb, LV_EVENT_CLICKED, ctx);
|
|
lv_obj_add_event_cb(b, cb, LV_EVENT_LONG_PRESSED_REPEAT, ctx);
|
|
return b;
|
|
}
|
|
|
|
/** [name / hint] ... [-] value [+] */
|
|
static void makeRow(lv_obj_t *page, field_t f)
|
|
{
|
|
row_t *r = &g_rows[f];
|
|
lv_obj_t *row = box(page, LV_FLEX_FLOW_ROW);
|
|
lv_obj_set_size(row, LV_PCT(100), 62);
|
|
lv_obj_set_flex_align(row, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
lv_obj_set_style_pad_column(row, 12, 0);
|
|
|
|
lv_obj_t *txt = box(row, LV_FLEX_FLOW_COLUMN);
|
|
lv_obj_set_height(txt, LV_SIZE_CONTENT);
|
|
lv_obj_set_flex_grow(txt, 1);
|
|
lv_obj_set_style_pad_row(txt, 2, 0);
|
|
label(txt, r->name, &lv_font_montserrat_24, UI_COL_TEXT);
|
|
label(txt, r->hint, &lv_font_montserrat_14, UI_COL_MUTED);
|
|
|
|
g_step_ctx[f][0] = {r, -1};
|
|
g_step_ctx[f][1] = {r, +1};
|
|
makeStepBtn(row, LV_SYMBOL_MINUS, onStep, &g_step_ctx[f][0]);
|
|
r->value_lbl = label(row, "--", &lv_font_montserrat_30, UI_COL_TEXT);
|
|
lv_obj_set_style_text_align(r->value_lbl, LV_TEXT_ALIGN_CENTER, 0);
|
|
lv_obj_set_width(r->value_lbl, 190);
|
|
makeStepBtn(row, LV_SYMBOL_PLUS, onStep, &g_step_ctx[f][1]);
|
|
}
|
|
|
|
static lv_obj_t *makeSwitchRow(lv_obj_t *page, const char *name, const char *hint, lv_event_cb_t cb, void *user)
|
|
{
|
|
lv_obj_t *row = box(page, LV_FLEX_FLOW_ROW);
|
|
lv_obj_set_size(row, LV_PCT(100), 62);
|
|
lv_obj_set_flex_align(row, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
lv_obj_t *txt = box(row, LV_FLEX_FLOW_COLUMN);
|
|
lv_obj_set_size(txt, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
|
lv_obj_set_style_pad_row(txt, 2, 0);
|
|
label(txt, name, &lv_font_montserrat_24, UI_COL_TEXT);
|
|
label(txt, hint, &lv_font_montserrat_14, UI_COL_MUTED);
|
|
lv_obj_t *sw = toggle(row, cb, user);
|
|
lv_obj_set_style_pad_right(row, 70, 0); // line the switch up under the value column
|
|
return sw;
|
|
}
|
|
|
|
/** Simulation card: title + readout + switch, then [-] slider [+]. */
|
|
static lv_obj_t *makeSimCard(lv_obj_t *page, const char *title, int32_t max, lv_obj_t **sw, lv_obj_t **readout)
|
|
{
|
|
lv_obj_t *c = card(page);
|
|
lv_obj_set_size(c, LV_PCT(100), LV_SIZE_CONTENT);
|
|
lv_obj_set_flex_flow(c, LV_FLEX_FLOW_COLUMN);
|
|
lv_obj_set_style_pad_row(c, 14, 0);
|
|
|
|
lv_obj_t *top = box(c, LV_FLEX_FLOW_ROW);
|
|
lv_obj_set_size(top, LV_PCT(100), LV_SIZE_CONTENT);
|
|
lv_obj_set_flex_align(top, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
lv_obj_t *t = label(top, title, &lv_font_montserrat_24, UI_COL_TEXT);
|
|
lv_obj_set_flex_grow(t, 1);
|
|
*readout = label(top, "--", &lv_font_montserrat_30, UI_COL_TEXT);
|
|
lv_obj_set_style_pad_right(*readout, 24, 0);
|
|
*sw = toggle(top, onOverrideSwitch, NULL);
|
|
|
|
lv_obj_t *bottom = box(c, LV_FLEX_FLOW_ROW);
|
|
lv_obj_set_size(bottom, LV_PCT(100), LV_SIZE_CONTENT);
|
|
lv_obj_set_flex_align(bottom, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
lv_obj_set_style_pad_column(bottom, 24, 0);
|
|
makeStepBtn(bottom, LV_SYMBOL_MINUS, onSimStep, (void *)(intptr_t)-1);
|
|
lv_obj_t *sl = lv_slider_create(bottom);
|
|
lv_obj_set_height(sl, 16);
|
|
lv_obj_set_flex_grow(sl, 1);
|
|
lv_slider_set_range(sl, 0, max);
|
|
lv_obj_set_style_bg_color(sl, UI_COL_PANEL2, 0);
|
|
lv_obj_set_style_bg_color(sl, UI_COL_ACCENT, LV_PART_INDICATOR);
|
|
lv_obj_set_style_bg_color(sl, UI_COL_TEXT, LV_PART_KNOB);
|
|
lv_obj_set_style_pad_all(sl, 12, LV_PART_KNOB); // big knob
|
|
lv_obj_set_style_anim_time(sl, 0, 0);
|
|
lv_obj_clear_flag(sl, LV_OBJ_FLAG_GESTURE_BUBBLE); // dragging must not change screens
|
|
lv_obj_add_event_cb(sl, onOverrideSlider, LV_EVENT_VALUE_CHANGED, NULL);
|
|
lv_obj_add_event_cb(sl, onOverrideSlider, LV_EVENT_RELEASED, NULL);
|
|
lv_obj_set_style_pad_ver(bottom, 12, 0); // room for the knob
|
|
makeStepBtn(bottom, LV_SYMBOL_PLUS, onSimStep, (void *)(intptr_t)1);
|
|
return sl;
|
|
}
|
|
|
|
static lv_obj_t *makeTabPage()
|
|
{
|
|
lv_obj_t *p = box(g_screen, LV_FLEX_FLOW_COLUMN);
|
|
lv_obj_set_size(p, 1024 - 48, 600 - 150 - 36);
|
|
lv_obj_set_pos(p, 24, 150);
|
|
lv_obj_set_style_pad_row(p, 6, 0);
|
|
return p;
|
|
}
|
|
|
|
static void build()
|
|
{
|
|
if (g_screen != NULL)
|
|
return;
|
|
|
|
g_screen = screen();
|
|
lv_obj_add_event_cb(g_screen, onGesture, LV_EVENT_GESTURE, NULL);
|
|
header(g_screen, "GAUGE TUNING", onBack);
|
|
|
|
g_sim_chip = label(g_screen, "SIMULATION ON", &lv_font_montserrat_20, UI_COL_TEXT);
|
|
lv_obj_set_style_bg_color(g_sim_chip, UI_COL_WARN, 0);
|
|
lv_obj_set_style_bg_opa(g_sim_chip, LV_OPA_COVER, 0);
|
|
lv_obj_set_style_radius(g_sim_chip, 8, 0);
|
|
lv_obj_set_style_pad_hor(g_sim_chip, 12, 0);
|
|
lv_obj_set_style_pad_ver(g_sim_chip, 6, 0);
|
|
lv_obj_align(g_sim_chip, LV_ALIGN_TOP_LEFT, 290, 22);
|
|
lv_obj_add_flag(g_sim_chip, LV_OBJ_FLAG_HIDDEN);
|
|
|
|
g_reset_btn = button(g_screen, LV_SYMBOL_REFRESH " Reset tab", 190, 56, BTN_SECONDARY, onReset, NULL);
|
|
lv_obj_align(g_reset_btn, LV_ALIGN_TOP_RIGHT, -16 - 200 - 12, 10);
|
|
|
|
// tab bar
|
|
for (int i = 0; i < TAB_COUNT; i++)
|
|
{
|
|
g_tab_btn[i] = button(g_screen, TAB_NAMES[i], 232, 58, BTN_SECONDARY, onTab, (void *)(uintptr_t)i);
|
|
lv_obj_set_pos(g_tab_btn[i], 24 + i * (232 + 12), 80);
|
|
g_tab_page[i] = makeTabPage();
|
|
}
|
|
|
|
// ---- Tachometer ----
|
|
makeRow(g_tab_page[TAB_TACH], F_TACH_PPR);
|
|
makeRow(g_tab_page[TAB_TACH], F_TACH_TRIM);
|
|
makeRow(g_tab_page[TAB_TACH], F_TACH_MAX_HZ);
|
|
g_tach_en_sw = makeSwitchRow(g_tab_page[TAB_TACH], "Tachometer output", "IO7 on Controller B. Off = no signal",
|
|
onEnableSwitch, (void *)(uintptr_t)OUT_ENABLE_TACH);
|
|
|
|
// ---- Coolant gauge ----
|
|
makeRow(g_tab_page[TAB_COOLANT], F_TEMP_HZ);
|
|
makeRow(g_tab_page[TAB_COOLANT], F_TEMP_SLOPE);
|
|
makeRow(g_tab_page[TAB_COOLANT], F_TEMP_OFFSET);
|
|
makeRow(g_tab_page[TAB_COOLANT], F_TEMP_MIN);
|
|
makeRow(g_tab_page[TAB_COOLANT], F_TEMP_DUTY_MAX);
|
|
g_temp_en_sw = makeSwitchRow(g_tab_page[TAB_COOLANT], "Coolant gauge output", "IO8 on Controller B. Off = no signal",
|
|
onEnableSwitch, (void *)(uintptr_t)OUT_ENABLE_TEMP);
|
|
|
|
// ---- Alerts ----
|
|
makeRow(g_tab_page[TAB_ALERTS], F_COOLANT_HOT);
|
|
makeRow(g_tab_page[TAB_ALERTS], F_GEARBOX_HOT);
|
|
makeRow(g_tab_page[TAB_ALERTS], F_BATT_LOW);
|
|
|
|
// ---- Simulation ----
|
|
lv_obj_t *sim = g_tab_page[TAB_SIM];
|
|
lv_obj_set_style_pad_row(sim, 14, 0);
|
|
lv_obj_t *intro = label(sim,
|
|
"Forces fixed values on the gauge outputs so the needles can be calibrated "
|
|
"against the cluster. Switch off when done.",
|
|
&lv_font_montserrat_20, UI_COL_MUTED);
|
|
lv_label_set_long_mode(intro, LV_LABEL_LONG_WRAP);
|
|
lv_obj_set_width(intro, LV_PCT(100));
|
|
g_ovr_rpm_sl = makeSimCard(sim, "Force tachometer", RPM_MAX, &g_ovr_rpm_sw, &g_ovr_rpm_lbl);
|
|
g_ovr_duty_sl = makeSimCard(sim, "Force coolant gauge", DUTY_MAX, &g_ovr_duty_sw, &g_ovr_duty_lbl);
|
|
|
|
g_save_lbl = label(g_screen, "", &lv_font_montserrat_20, UI_COL_MUTED);
|
|
lv_obj_align(g_save_lbl, LV_ALIGN_BOTTOM_LEFT, 24, -8);
|
|
|
|
selectTab(TAB_TACH);
|
|
ESP_LOGI("Tuning", "Gauge tuning screen built");
|
|
}
|
|
|
|
// ============================================================================
|
|
// PUBLIC API
|
|
// ============================================================================
|
|
|
|
void show()
|
|
{
|
|
build();
|
|
refreshFromTunables();
|
|
lv_scr_load_anim(g_screen, LV_SCR_LOAD_ANIM_NONE, 0, 0, false); // instant: fades stutter at 1024x600
|
|
}
|
|
|
|
void tick()
|
|
{
|
|
if (g_screen == NULL || lv_scr_act() != g_screen)
|
|
return;
|
|
static uint32_t last = 0;
|
|
if (millis() - last < 500)
|
|
return;
|
|
last = millis();
|
|
lvgl_port_lock(-1);
|
|
if (Tunables::version() != g_shown_version)
|
|
refreshFromTunables(); // changed from the console
|
|
else
|
|
refreshSaveState(); // "Saving..." -> "saved" after the deferred write
|
|
lvgl_port_unlock();
|
|
}
|
|
|
|
} // namespace TuningScreen
|