mirror of
https://github.com/esphome/esphome.git
synced 2026-06-01 01:19:45 +08:00
[lvgl] Use stack buffer for event code formatting, document justified str_sprintf usage (#13220)
Co-authored-by: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com>
This commit is contained in:
@@ -413,6 +413,7 @@ class TextValidator(LValidator):
|
|||||||
str_args = [str(x) for x in value[CONF_ARGS]]
|
str_args = [str(x) for x in value[CONF_ARGS]]
|
||||||
arg_expr = cg.RawExpression(",".join(str_args))
|
arg_expr = cg.RawExpression(",".join(str_args))
|
||||||
format_str = cpp_string_escape(format_str)
|
format_str = cpp_string_escape(format_str)
|
||||||
|
# str_sprintf justified: user-defined format, can't optimize without permanent RAM cost
|
||||||
sprintf_str = f"str_sprintf({format_str}, {arg_expr}).c_str()"
|
sprintf_str = f"str_sprintf({format_str}, {arg_expr}).c_str()"
|
||||||
if nanval := value.get(CONF_IF_NAN):
|
if nanval := value.get(CONF_IF_NAN):
|
||||||
nanval = cpp_string_escape(nanval)
|
nanval = cpp_string_escape(nanval)
|
||||||
|
|||||||
@@ -65,7 +65,10 @@ std::string lv_event_code_name_for(uint8_t event_code) {
|
|||||||
if (event_code < sizeof(EVENT_NAMES) / sizeof(EVENT_NAMES[0])) {
|
if (event_code < sizeof(EVENT_NAMES) / sizeof(EVENT_NAMES[0])) {
|
||||||
return EVENT_NAMES[event_code];
|
return EVENT_NAMES[event_code];
|
||||||
}
|
}
|
||||||
return str_sprintf("%2d", event_code);
|
// max 4 bytes: "%u" with uint8_t (max 255, 3 digits) + null
|
||||||
|
char buf[4];
|
||||||
|
snprintf(buf, sizeof(buf), "%u", event_code);
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rounder_cb(lv_disp_drv_t *disp_drv, lv_area_t *area) {
|
static void rounder_cb(lv_disp_drv_t *disp_drv, lv_area_t *area) {
|
||||||
|
|||||||
Reference in New Issue
Block a user