mirror of
https://github.com/esphome/esphome.git
synced 2025-10-31 23:21:54 +00:00
[lvgl] memset canvas buffer to prevent display of random garbage (#11582)
Co-authored-by: clydebarrow <2366188+clydebarrow@users.noreply.github.com>
This commit is contained in:
@@ -33,7 +33,7 @@ from ..lv_validation import (
|
|||||||
pixels,
|
pixels,
|
||||||
size,
|
size,
|
||||||
)
|
)
|
||||||
from ..lvcode import LocalVariable, lv, lv_assign
|
from ..lvcode import LocalVariable, lv, lv_assign, lv_expr
|
||||||
from ..schemas import STYLE_PROPS, STYLE_REMAP, TEXT_SCHEMA, point_schema
|
from ..schemas import STYLE_PROPS, STYLE_REMAP, TEXT_SCHEMA, point_schema
|
||||||
from ..types import LvType, ObjUpdateAction, WidgetType
|
from ..types import LvType, ObjUpdateAction, WidgetType
|
||||||
from . import Widget, get_widgets
|
from . import Widget, get_widgets
|
||||||
@@ -70,15 +70,18 @@ class CanvasType(WidgetType):
|
|||||||
width = config[CONF_WIDTH]
|
width = config[CONF_WIDTH]
|
||||||
height = config[CONF_HEIGHT]
|
height = config[CONF_HEIGHT]
|
||||||
use_alpha = "_ALPHA" if config[CONF_TRANSPARENT] else ""
|
use_alpha = "_ALPHA" if config[CONF_TRANSPARENT] else ""
|
||||||
lv.canvas_set_buffer(
|
buf_size = literal(
|
||||||
w.obj,
|
f"LV_CANVAS_BUF_SIZE_TRUE_COLOR{use_alpha}({width}, {height})"
|
||||||
lv.custom_mem_alloc(
|
|
||||||
literal(f"LV_CANVAS_BUF_SIZE_TRUE_COLOR{use_alpha}({width}, {height})")
|
|
||||||
),
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
literal(f"LV_IMG_CF_TRUE_COLOR{use_alpha}"),
|
|
||||||
)
|
)
|
||||||
|
with LocalVariable("buf", cg.void, lv_expr.custom_mem_alloc(buf_size)) as buf:
|
||||||
|
cg.add(cg.RawExpression(f"memset({buf}, 0, {buf_size});"))
|
||||||
|
lv.canvas_set_buffer(
|
||||||
|
w.obj,
|
||||||
|
buf,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
literal(f"LV_IMG_CF_TRUE_COLOR{use_alpha}"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
canvas_spec = CanvasType()
|
canvas_spec = CanvasType()
|
||||||
|
|||||||
Reference in New Issue
Block a user