f60bdac268
Protocol v2 (shared header, byte-identical with the 1.3 repo): - typed DATA/CONFIG frames: 0xAA | ver | type | len | payload | XOR | 0x55 - gear split into lever (P/R/N/D/S/M) + target/engaged nibbles, engine rpm, alert bitmap decided here from tunable thresholds, link_config_t tunables - docs/UART_PROTOCOL.md rewritten for v2 Controller A modules: - tunables: gauge calibration + alert thresholds in NVS, 'cfg' serial console, bench override (never persisted) - espnow_link: every frame also broadcast on ESP-NOW ch 1; radio stays in STA (WiFiManager no longer powers it off) - uart_manager: DATA at 5 Hz + CONFIG on change/5 s on both transports - can_driver: publishes gear pieces and rpm, evaluates alerts - tuning_screen: hand-coded Gauge Tuning page (swipe right from Driveline), -/+ rows, enable switches, override sliders, Driveline/Defaults buttons UI: SquareLine Home screen (3 meters + battery) and meters_manager removed; Driveline is the boot screen; Settings back-gesture calls app_show_driveline(). tools/fix_penv_deps.ps1: repairs the shared PlatformIO penv after a 1.3 build. Bench-verified with Controller B: both transports alive, dedupe, override rpm 2000 -> 133.3 Hz tach output. Co-Authored-By: Claude <noreply@anthropic.com>
606 lines
22 KiB
C++
606 lines
22 KiB
C++
/*
|
|
* Gauge Tuning Screen Module Implementation
|
|
*/
|
|
|
|
#include "tuning_screen.h"
|
|
#include "tunables.h"
|
|
#include "driveline_screen.h"
|
|
#include "display/lvgl_v8_port.h"
|
|
#include "esp_log.h"
|
|
|
|
extern "C"
|
|
{
|
|
#include "ui.h"
|
|
}
|
|
|
|
namespace TuningScreen
|
|
{
|
|
|
|
// ============================================================================
|
|
// THEME
|
|
// ============================================================================
|
|
|
|
#define COL_BG lv_color_hex(0x101418)
|
|
#define COL_PANEL lv_color_hex(0x1B2128)
|
|
#define COL_TEXT lv_color_hex(0xE8EDF2)
|
|
#define COL_MUTED lv_color_hex(0x6E7B88)
|
|
#define COL_ACCENT lv_color_hex(0x3DA9FC)
|
|
#define COL_OK lv_color_hex(0x3DD68C)
|
|
#define COL_WARN lv_color_hex(0xE5484D)
|
|
|
|
// ============================================================================
|
|
// 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 struct
|
|
{
|
|
field_t id;
|
|
const char *name;
|
|
const char *unit;
|
|
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, "Pulses / rev", "", 1, 1, 32, NULL},
|
|
{F_TACH_TRIM, "Trim", "%", 1, -50, 50, NULL},
|
|
{F_TACH_MAX_HZ, "Max output", "Hz", 10, 0, 5000, NULL},
|
|
{F_TEMP_HZ, "PWM frequency", "Hz", 50, 20, 20000, NULL},
|
|
{F_TEMP_SLOPE, "Slope", "x100", 5, 0, 5000, NULL},
|
|
{F_TEMP_OFFSET, "Offset", "", 1, -1000, 1000, NULL},
|
|
{F_TEMP_MIN, "Min temp", "C", 1, -50, 200, NULL},
|
|
{F_TEMP_DUTY_MAX, "Duty clamp", "", 5, 0, 255, NULL},
|
|
{F_COOLANT_HOT, "Coolant hot", "C", 1, 0, 200, NULL},
|
|
{F_GEARBOX_HOT, "Gearbox hot", "C", 1, 0, 200, NULL},
|
|
{F_BATT_LOW, "Battery low", "x0.01V", 10, 0, 3000, NULL},
|
|
};
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
// ============================================================================
|
|
// MODULE STATE
|
|
// ============================================================================
|
|
|
|
static lv_obj_t *g_screen = 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 lv_obj_t *g_status_lbl = NULL;
|
|
static uint8_t g_shown_version = 0;
|
|
static bool g_refreshing = false; // suppress event handlers while we set widget values
|
|
|
|
// ============================================================================
|
|
// HELPERS
|
|
// ============================================================================
|
|
|
|
static void formatValue(const row_t &r, int32_t v, char *out, size_t n)
|
|
{
|
|
if (r.id == F_TEMP_SLOPE)
|
|
{
|
|
snprintf(out, n, "%ld.%02ld", (long)(v / 100), (long)labs(v % 100));
|
|
}
|
|
else if (r.id == F_BATT_LOW)
|
|
{
|
|
snprintf(out, n, "%ld.%02ld V", (long)(v / 100), (long)(v % 100));
|
|
}
|
|
else if (r.unit[0])
|
|
{
|
|
snprintf(out, n, "%ld %s", (long)v, r.unit);
|
|
}
|
|
else
|
|
{
|
|
snprintf(out, n, "%ld", (long)v);
|
|
}
|
|
}
|
|
|
|
static void refreshFromTunables()
|
|
{
|
|
link_config_t c = Tunables::get();
|
|
g_refreshing = true;
|
|
|
|
char buf[24];
|
|
for (int i = 0; i < F_COUNT; i++)
|
|
{
|
|
if (g_rows[i].value_lbl == NULL)
|
|
continue;
|
|
formatValue(g_rows[i], getField(c, g_rows[i].id), buf, sizeof(buf));
|
|
lv_label_set_text(g_rows[i].value_lbl, buf);
|
|
}
|
|
|
|
auto setSw = [](lv_obj_t *sw, bool on)
|
|
{
|
|
if (sw == NULL)
|
|
return;
|
|
if (on)
|
|
lv_obj_add_state(sw, LV_STATE_CHECKED);
|
|
else
|
|
lv_obj_clear_state(sw, LV_STATE_CHECKED);
|
|
};
|
|
setSw(g_tach_en_sw, c.out_enable & OUT_ENABLE_TACH);
|
|
setSw(g_temp_en_sw, c.out_enable & OUT_ENABLE_TEMP);
|
|
setSw(g_ovr_rpm_sw, c.override_mode & OVERRIDE_TACH);
|
|
setSw(g_ovr_duty_sw, c.override_mode & OVERRIDE_TEMP);
|
|
|
|
if (g_ovr_rpm_sl)
|
|
lv_slider_set_value(g_ovr_rpm_sl, c.override_rpm, LV_ANIM_OFF);
|
|
if (g_ovr_duty_sl)
|
|
lv_slider_set_value(g_ovr_duty_sl, c.override_duty, LV_ANIM_OFF);
|
|
if (g_ovr_rpm_lbl)
|
|
{
|
|
snprintf(buf, sizeof(buf), "%u rpm", c.override_rpm);
|
|
lv_label_set_text(g_ovr_rpm_lbl, buf);
|
|
}
|
|
if (g_ovr_duty_lbl)
|
|
{
|
|
snprintf(buf, sizeof(buf), "%u / 255", c.override_duty);
|
|
lv_label_set_text(g_ovr_duty_lbl, buf);
|
|
}
|
|
|
|
if (g_status_lbl)
|
|
{
|
|
snprintf(buf, sizeof(buf), "config v%u", c.cfg_version);
|
|
lv_label_set_text(g_status_lbl, buf);
|
|
lv_obj_set_style_text_color(g_status_lbl, c.override_mode ? COL_WARN : COL_MUTED, 0);
|
|
}
|
|
|
|
g_shown_version = c.cfg_version;
|
|
g_refreshing = false;
|
|
}
|
|
|
|
// ---- event handlers --------------------------------------------------------
|
|
|
|
// user_data = row pointer; the button's own user data (+1/-1) is in lv_event_get_user_data
|
|
typedef struct
|
|
{
|
|
row_t *row;
|
|
int dir;
|
|
} step_ctx_t;
|
|
static step_ctx_t g_step_ctx[F_COUNT][2];
|
|
|
|
static void onStep(lv_event_t *e)
|
|
{
|
|
lv_event_code_t code = lv_event_get_code(e);
|
|
if (code != LV_EVENT_CLICKED && code != LV_EVENT_LONG_PRESSED_REPEAT)
|
|
return;
|
|
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;
|
|
if (v < ctx->row->min)
|
|
v = ctx->row->min;
|
|
if (v > ctx->row->max)
|
|
v = ctx->row->max;
|
|
setField(c, ctx->row->id, v);
|
|
Tunables::set(c); // saves + bumps version -> CONFIG frame goes out
|
|
refreshFromTunables();
|
|
}
|
|
|
|
static void onEnableSwitch(lv_event_t *e)
|
|
{
|
|
if (g_refreshing || lv_event_get_code(e) != LV_EVENT_VALUE_CHANGED)
|
|
return;
|
|
lv_obj_t *sw = lv_event_get_target(e);
|
|
bool on = lv_obj_has_state(sw, 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()
|
|
{
|
|
link_config_t c = Tunables::get();
|
|
uint8_t mode = 0;
|
|
if (g_ovr_rpm_sw && lv_obj_has_state(g_ovr_rpm_sw, LV_STATE_CHECKED))
|
|
mode |= OVERRIDE_TACH;
|
|
if (g_ovr_duty_sw && lv_obj_has_state(g_ovr_duty_sw, LV_STATE_CHECKED))
|
|
mode |= OVERRIDE_TEMP;
|
|
uint16_t rpm = g_ovr_rpm_sl ? (uint16_t)lv_slider_get_value(g_ovr_rpm_sl) : c.override_rpm;
|
|
uint8_t duty = g_ovr_duty_sl ? (uint8_t)lv_slider_get_value(g_ovr_duty_sl) : c.override_duty;
|
|
Tunables::setOverride(mode, rpm, duty); // pushed to B, never saved
|
|
refreshFromTunables();
|
|
}
|
|
|
|
static void onOverrideSwitch(lv_event_t *e)
|
|
{
|
|
if (g_refreshing || lv_event_get_code(e) != LV_EVENT_VALUE_CHANGED)
|
|
return;
|
|
pushOverride();
|
|
}
|
|
|
|
static void onOverrideSlider(lv_event_t *e)
|
|
{
|
|
if (g_refreshing)
|
|
return;
|
|
lv_event_code_t code = lv_event_get_code(e);
|
|
// Update the readout while dragging; 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];
|
|
lv_obj_t *sl = lv_event_get_target(e);
|
|
if (sl == g_ovr_rpm_sl && g_ovr_rpm_lbl)
|
|
{
|
|
snprintf(buf, sizeof(buf), "%d rpm", (int)lv_slider_get_value(sl));
|
|
lv_label_set_text(g_ovr_rpm_lbl, buf);
|
|
}
|
|
else if (sl == g_ovr_duty_sl && g_ovr_duty_lbl)
|
|
{
|
|
snprintf(buf, sizeof(buf), "%d / 255", (int)lv_slider_get_value(sl));
|
|
lv_label_set_text(g_ovr_duty_lbl, buf);
|
|
}
|
|
}
|
|
else if (code == LV_EVENT_RELEASED)
|
|
{
|
|
pushOverride();
|
|
}
|
|
}
|
|
|
|
static void onBack(lv_event_t *e)
|
|
{
|
|
if (lv_event_get_code(e) != LV_EVENT_CLICKED)
|
|
return;
|
|
DrivelineScreen::show();
|
|
}
|
|
|
|
static void onReset(lv_event_t *e)
|
|
{
|
|
if (lv_event_get_code(e) != LV_EVENT_CLICKED)
|
|
return;
|
|
Tunables::resetDefaults();
|
|
refreshFromTunables();
|
|
}
|
|
|
|
// ---- builders --------------------------------------------------------------
|
|
|
|
static lv_obj_t *makePanel(lv_obj_t *parent, const char *title, lv_coord_t w)
|
|
{
|
|
lv_obj_t *p = lv_obj_create(parent);
|
|
lv_obj_set_size(p, w, LV_SIZE_CONTENT);
|
|
lv_obj_set_style_bg_color(p, COL_PANEL, 0);
|
|
lv_obj_set_style_border_width(p, 0, 0);
|
|
lv_obj_set_style_radius(p, 12, 0);
|
|
lv_obj_set_style_pad_all(p, 12, 0);
|
|
lv_obj_set_style_pad_row(p, 6, 0);
|
|
lv_obj_set_flex_flow(p, LV_FLEX_FLOW_COLUMN);
|
|
lv_obj_clear_flag(p, LV_OBJ_FLAG_SCROLLABLE);
|
|
|
|
lv_obj_t *t = lv_label_create(p);
|
|
lv_label_set_text(t, title);
|
|
lv_obj_set_style_text_font(t, &lv_font_montserrat_14, 0);
|
|
lv_obj_set_style_text_color(t, COL_ACCENT, 0);
|
|
lv_obj_set_style_pad_bottom(t, 4, 0);
|
|
return p;
|
|
}
|
|
|
|
static lv_obj_t *makeStepBtn(lv_obj_t *parent, const char *txt, step_ctx_t *ctx)
|
|
{
|
|
lv_obj_t *b = lv_btn_create(parent);
|
|
lv_obj_set_size(b, 44, 36);
|
|
lv_obj_set_style_bg_color(b, COL_BG, 0);
|
|
lv_obj_set_style_radius(b, 8, 0);
|
|
lv_obj_add_event_cb(b, onStep, LV_EVENT_CLICKED, ctx);
|
|
lv_obj_add_event_cb(b, onStep, LV_EVENT_LONG_PRESSED_REPEAT, ctx);
|
|
lv_obj_t *l = lv_label_create(b);
|
|
lv_label_set_text(l, txt);
|
|
lv_obj_set_style_text_font(l, &lv_font_montserrat_14, 0);
|
|
lv_obj_center(l);
|
|
return b;
|
|
}
|
|
|
|
static void makeRow(lv_obj_t *panel, field_t f)
|
|
{
|
|
row_t *r = &g_rows[f];
|
|
lv_obj_t *row = lv_obj_create(panel);
|
|
lv_obj_remove_style_all(row);
|
|
lv_obj_set_size(row, LV_PCT(100), 36);
|
|
lv_obj_set_flex_flow(row, LV_FLEX_FLOW_ROW);
|
|
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, 6, 0);
|
|
lv_obj_clear_flag(row, LV_OBJ_FLAG_SCROLLABLE);
|
|
|
|
lv_obj_t *name = lv_label_create(row);
|
|
lv_label_set_text(name, r->name);
|
|
lv_obj_set_style_text_font(name, &lv_font_montserrat_14, 0);
|
|
lv_obj_set_style_text_color(name, COL_MUTED, 0);
|
|
lv_obj_set_width(name, 118);
|
|
|
|
g_step_ctx[f][0] = {r, -1};
|
|
g_step_ctx[f][1] = {r, +1};
|
|
makeStepBtn(row, LV_SYMBOL_MINUS, &g_step_ctx[f][0]);
|
|
|
|
r->value_lbl = lv_label_create(row);
|
|
lv_label_set_text(r->value_lbl, "--");
|
|
lv_obj_set_style_text_font(r->value_lbl, &lv_font_montserrat_14, 0);
|
|
lv_obj_set_style_text_color(r->value_lbl, COL_TEXT, 0);
|
|
lv_obj_set_style_text_align(r->value_lbl, LV_TEXT_ALIGN_CENTER, 0);
|
|
lv_obj_set_width(r->value_lbl, 82);
|
|
|
|
makeStepBtn(row, LV_SYMBOL_PLUS, &g_step_ctx[f][1]);
|
|
}
|
|
|
|
static lv_obj_t *makeSwitchRow(lv_obj_t *panel, const char *text, lv_event_cb_t cb, void *user)
|
|
{
|
|
lv_obj_t *row = lv_obj_create(panel);
|
|
lv_obj_remove_style_all(row);
|
|
lv_obj_set_size(row, LV_PCT(100), 36);
|
|
lv_obj_set_flex_flow(row, LV_FLEX_FLOW_ROW);
|
|
lv_obj_set_flex_align(row, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
lv_obj_clear_flag(row, LV_OBJ_FLAG_SCROLLABLE);
|
|
|
|
lv_obj_t *l = lv_label_create(row);
|
|
lv_label_set_text(l, text);
|
|
lv_obj_set_style_text_font(l, &lv_font_montserrat_14, 0);
|
|
lv_obj_set_style_text_color(l, COL_MUTED, 0);
|
|
|
|
lv_obj_t *sw = lv_switch_create(row);
|
|
lv_obj_set_style_bg_color(sw, COL_ACCENT, (lv_style_selector_t)LV_PART_INDICATOR | (lv_style_selector_t)LV_STATE_CHECKED);
|
|
lv_obj_add_event_cb(sw, cb, LV_EVENT_VALUE_CHANGED, user);
|
|
return sw;
|
|
}
|
|
|
|
static lv_obj_t *makeSliderRow(lv_obj_t *panel, const char *text, int32_t max, lv_obj_t **readout)
|
|
{
|
|
lv_obj_t *head = lv_obj_create(panel);
|
|
lv_obj_remove_style_all(head);
|
|
lv_obj_set_size(head, LV_PCT(100), 20);
|
|
lv_obj_set_flex_flow(head, LV_FLEX_FLOW_ROW);
|
|
lv_obj_set_flex_align(head, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
lv_obj_clear_flag(head, LV_OBJ_FLAG_SCROLLABLE);
|
|
|
|
lv_obj_t *l = lv_label_create(head);
|
|
lv_label_set_text(l, text);
|
|
lv_obj_set_style_text_font(l, &lv_font_montserrat_14, 0);
|
|
lv_obj_set_style_text_color(l, COL_MUTED, 0);
|
|
|
|
*readout = lv_label_create(head);
|
|
lv_label_set_text(*readout, "--");
|
|
lv_obj_set_style_text_font(*readout, &lv_font_montserrat_14, 0);
|
|
lv_obj_set_style_text_color(*readout, COL_TEXT, 0);
|
|
|
|
lv_obj_t *sl = lv_slider_create(panel);
|
|
lv_obj_set_width(sl, LV_PCT(96));
|
|
lv_slider_set_range(sl, 0, max);
|
|
lv_obj_set_style_bg_color(sl, COL_BG, 0);
|
|
lv_obj_set_style_bg_color(sl, COL_ACCENT, LV_PART_INDICATOR);
|
|
lv_obj_set_style_bg_color(sl, COL_TEXT, LV_PART_KNOB);
|
|
lv_obj_add_event_cb(sl, onOverrideSlider, LV_EVENT_VALUE_CHANGED, NULL);
|
|
lv_obj_add_event_cb(sl, onOverrideSlider, LV_EVENT_RELEASED, NULL);
|
|
return sl;
|
|
}
|
|
|
|
static void build()
|
|
{
|
|
if (g_screen != NULL)
|
|
return;
|
|
|
|
g_screen = lv_obj_create(NULL);
|
|
lv_obj_set_style_bg_color(g_screen, COL_BG, 0);
|
|
lv_obj_clear_flag(g_screen, LV_OBJ_FLAG_SCROLLABLE);
|
|
// No swipe gesture on this screen: dragging the override sliders would
|
|
// otherwise change screens. Leave via the Driveline button (top right).
|
|
|
|
lv_obj_t *title = lv_label_create(g_screen);
|
|
lv_label_set_text(title, "GAUGE TUNING");
|
|
lv_obj_set_style_text_font(title, &lv_font_montserrat_30, 0);
|
|
lv_obj_set_style_text_color(title, COL_TEXT, 0);
|
|
lv_obj_align(title, LV_ALIGN_TOP_LEFT, 24, 16);
|
|
|
|
lv_obj_t *back = lv_btn_create(g_screen);
|
|
lv_obj_set_size(back, 150, 36);
|
|
lv_obj_align(back, LV_ALIGN_TOP_RIGHT, -24, 18);
|
|
lv_obj_set_style_bg_color(back, COL_ACCENT, 0);
|
|
lv_obj_add_event_cb(back, onBack, LV_EVENT_CLICKED, NULL);
|
|
lv_obj_t *bl = lv_label_create(back);
|
|
lv_label_set_text(bl, LV_SYMBOL_HOME " Driveline");
|
|
lv_obj_set_style_text_font(bl, &lv_font_montserrat_14, 0);
|
|
lv_obj_center(bl);
|
|
|
|
lv_obj_t *reset = lv_btn_create(g_screen);
|
|
lv_obj_set_size(reset, 150, 36);
|
|
lv_obj_align(reset, LV_ALIGN_TOP_RIGHT, -24 - 150 - 12, 18);
|
|
lv_obj_set_style_bg_color(reset, COL_PANEL, 0);
|
|
lv_obj_add_event_cb(reset, onReset, LV_EVENT_CLICKED, NULL);
|
|
lv_obj_t *rl = lv_label_create(reset);
|
|
lv_label_set_text(rl, LV_SYMBOL_REFRESH " Defaults");
|
|
lv_obj_set_style_text_font(rl, &lv_font_montserrat_14, 0);
|
|
lv_obj_center(rl);
|
|
|
|
// Three columns of panels
|
|
lv_obj_t *cols = lv_obj_create(g_screen);
|
|
lv_obj_remove_style_all(cols);
|
|
lv_obj_set_size(cols, 1024 - 48, 600 - 70 - 30);
|
|
lv_obj_align(cols, LV_ALIGN_TOP_LEFT, 24, 66);
|
|
lv_obj_set_flex_flow(cols, LV_FLEX_FLOW_ROW);
|
|
lv_obj_set_flex_align(cols, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START);
|
|
lv_obj_clear_flag(cols, LV_OBJ_FLAG_SCROLLABLE);
|
|
|
|
const lv_coord_t W = 320;
|
|
|
|
// ---- column 1: tach + alerts ----
|
|
lv_obj_t *c1 = lv_obj_create(cols);
|
|
lv_obj_remove_style_all(c1);
|
|
lv_obj_set_size(c1, W, LV_SIZE_CONTENT);
|
|
lv_obj_set_flex_flow(c1, LV_FLEX_FLOW_COLUMN);
|
|
lv_obj_set_style_pad_row(c1, 12, 0);
|
|
lv_obj_clear_flag(c1, LV_OBJ_FLAG_SCROLLABLE);
|
|
|
|
lv_obj_t *tach = makePanel(c1, "TACHOMETER(IO7)", W);
|
|
makeRow(tach, F_TACH_PPR);
|
|
makeRow(tach, F_TACH_TRIM);
|
|
makeRow(tach, F_TACH_MAX_HZ);
|
|
g_tach_en_sw = makeSwitchRow(tach, "Output enabled", onEnableSwitch, (void *)(uintptr_t)OUT_ENABLE_TACH);
|
|
|
|
lv_obj_t *alerts = makePanel(c1, "ALERT THRESHOLDS", W);
|
|
makeRow(alerts, F_COOLANT_HOT);
|
|
makeRow(alerts, F_GEARBOX_HOT);
|
|
makeRow(alerts, F_BATT_LOW);
|
|
|
|
// ---- column 2: coolant gauge ----
|
|
lv_obj_t *temp = makePanel(cols, "COOLANT GAUGE(IO8)", W);
|
|
makeRow(temp, F_TEMP_HZ);
|
|
makeRow(temp, F_TEMP_SLOPE);
|
|
makeRow(temp, F_TEMP_OFFSET);
|
|
makeRow(temp, F_TEMP_MIN);
|
|
makeRow(temp, F_TEMP_DUTY_MAX);
|
|
g_temp_en_sw = makeSwitchRow(temp, "Output enabled", onEnableSwitch, (void *)(uintptr_t)OUT_ENABLE_TEMP);
|
|
|
|
// lv_obj_t* note = lv_label_create(temp);
|
|
// lv_label_set_text(note, "duty = slope x T + offset\n(defaults: 1.5 x T + 50, from the\nCANNY program)");
|
|
// lv_obj_set_style_text_font(note, &lv_font_montserrat_14, 0);
|
|
// lv_obj_set_style_text_color(note, COL_MUTED, 0);
|
|
|
|
// ---- column 3: calibration override ----
|
|
lv_obj_t *ovr = makePanel(cols, "SIMULATION", 300);
|
|
g_ovr_rpm_sw = makeSwitchRow(ovr, "Force tach rpm", onOverrideSwitch, NULL);
|
|
g_ovr_rpm_sl = makeSliderRow(ovr, "RPM", 6000, &g_ovr_rpm_lbl);
|
|
g_ovr_duty_sw = makeSwitchRow(ovr, "Force coolant duty", onOverrideSwitch, NULL);
|
|
g_ovr_duty_sl = makeSliderRow(ovr, "Duty", 255, &g_ovr_duty_lbl);
|
|
|
|
// lv_obj_t* howto = lv_label_create(ovr);
|
|
// lv_label_set_text(howto,
|
|
// "Tach: force 1000 rpm, fix Pulses/rev until\n"
|
|
// "the needle reads 1000; force 3000, fix Trim.\n"
|
|
// "Temp: force a duty, note the needle, repeat;\n"
|
|
// "derive Slope/Offset from two marks.\n"
|
|
// "Switch overrides OFF when done.");
|
|
// lv_obj_set_style_text_font(howto, &lv_font_montserrat_14, 0);
|
|
// lv_obj_set_style_text_color(howto, COL_MUTED, 0);
|
|
|
|
// lv_obj_t *hint = lv_label_create(g_screen);
|
|
// lv_label_set_text(hint, LV_SYMBOL_LEFT " swipe left: back to Driveline");
|
|
// lv_obj_set_style_text_font(hint, &lv_font_montserrat_14, 0);
|
|
// lv_obj_set_style_text_color(hint, COL_MUTED, 0);
|
|
// lv_obj_align(hint, LV_ALIGN_BOTTOM_RIGHT, -24, -10);
|
|
|
|
g_status_lbl = lv_label_create(g_screen);
|
|
lv_label_set_text(g_status_lbl, "config v-");
|
|
lv_obj_set_style_text_font(g_status_lbl, &lv_font_montserrat_14, 0);
|
|
lv_obj_set_style_text_color(g_status_lbl, COL_MUTED, 0);
|
|
lv_obj_align(g_status_lbl, LV_ALIGN_BOTTOM_RIGHT, -24, -10);
|
|
|
|
ESP_LOGI("Tuning", "Gauge tuning screen built");
|
|
}
|
|
|
|
// ============================================================================
|
|
// PUBLIC API
|
|
// ============================================================================
|
|
|
|
void show()
|
|
{
|
|
build();
|
|
refreshFromTunables();
|
|
lv_scr_load_anim(g_screen, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0, false);
|
|
}
|
|
|
|
void tick()
|
|
{
|
|
if (g_screen == NULL || lv_scr_act() != g_screen)
|
|
return;
|
|
static uint32_t last = 0;
|
|
if (millis() - last < 500)
|
|
return;
|
|
last = millis();
|
|
if (Tunables::version() == g_shown_version)
|
|
return; // nothing changed elsewhere
|
|
lvgl_port_lock(-1);
|
|
refreshFromTunables();
|
|
lvgl_port_unlock();
|
|
}
|
|
|
|
} // namespace TuningScreen
|