mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
[lvgl] Bug fixes (#7338)
This commit is contained in:
parent
ab620acd4f
commit
5cc8dbace4
7 changed files with 41 additions and 10 deletions
|
@ -5,6 +5,7 @@ from esphome import automation
|
|||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_ID, CONF_TIMEOUT
|
||||
from esphome.cpp_generator import RawExpression
|
||||
from esphome.cpp_types import nullptr
|
||||
|
||||
from .defines import (
|
||||
|
@ -26,6 +27,7 @@ from .lvcode import (
|
|||
add_line_marks,
|
||||
lv,
|
||||
lv_add,
|
||||
lv_expr,
|
||||
lv_obj,
|
||||
lvgl_comp,
|
||||
)
|
||||
|
@ -38,7 +40,13 @@ from .types import (
|
|||
lv_disp_t,
|
||||
lv_obj_t,
|
||||
)
|
||||
from .widgets import Widget, get_widgets, lv_scr_act, set_obj_properties
|
||||
from .widgets import (
|
||||
Widget,
|
||||
get_widgets,
|
||||
lv_scr_act,
|
||||
set_obj_properties,
|
||||
wait_for_widgets,
|
||||
)
|
||||
|
||||
|
||||
async def action_to_code(
|
||||
|
@ -48,10 +56,12 @@ async def action_to_code(
|
|||
template_arg,
|
||||
args,
|
||||
):
|
||||
await wait_for_widgets()
|
||||
async with LambdaContext(parameters=args, where=action_id) as context:
|
||||
with LvConditional(lv_expr.is_pre_initialise()):
|
||||
context.add(RawExpression("return"))
|
||||
for widget in widgets:
|
||||
with LvConditional(widget.obj != nullptr):
|
||||
await action(widget)
|
||||
await action(widget)
|
||||
var = cg.new_Pvariable(action_id, template_arg, await context.get_lambda())
|
||||
return var
|
||||
|
||||
|
|
|
@ -294,6 +294,13 @@ void LvglComponent::loop() {
|
|||
}
|
||||
lv_timer_handler_run_in_period(5);
|
||||
}
|
||||
bool lv_is_pre_initialise() {
|
||||
if (!lv_is_initialized()) {
|
||||
ESP_LOGE(TAG, "LVGL call before component is initialised");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef USE_LVGL_IMAGE
|
||||
lv_img_dsc_t *lv_img_from(image::Image *src, lv_img_dsc_t *img_dsc) {
|
||||
|
|
|
@ -40,6 +40,7 @@ namespace lvgl {
|
|||
|
||||
extern lv_event_code_t lv_api_event; // NOLINT
|
||||
extern lv_event_code_t lv_update_event; // NOLINT
|
||||
extern bool lv_is_pre_initialise();
|
||||
#ifdef USE_LVGL_COLOR
|
||||
inline lv_color_t lv_color_from(Color color) { return lv_color_make(color.red, color.green, color.blue); }
|
||||
#endif // USE_LVGL_COLOR
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import asyncio
|
||||
import sys
|
||||
from typing import Any, Union
|
||||
|
||||
|
@ -223,6 +224,11 @@ async def get_widget_(wid: Widget):
|
|||
return await FakeAwaitable(get_widget_generator(wid))
|
||||
|
||||
|
||||
async def wait_for_widgets():
|
||||
while not Widget.widgets_completed:
|
||||
await asyncio.sleep(0)
|
||||
|
||||
|
||||
async def get_widgets(config: Union[dict, list], id: str = CONF_ID) -> list[Widget]:
|
||||
if not config:
|
||||
return []
|
||||
|
|
|
@ -3,7 +3,7 @@ import functools
|
|||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
|
||||
from ..defines import CONF_MAIN, literal
|
||||
from ..defines import CONF_MAIN
|
||||
from ..lvcode import lv
|
||||
from ..types import LvType
|
||||
from . import Widget, WidgetType
|
||||
|
@ -38,13 +38,15 @@ LINE_SCHEMA = {
|
|||
|
||||
class LineType(WidgetType):
|
||||
def __init__(self):
|
||||
super().__init__(CONF_LINE, LvType("lv_line_t"), (CONF_MAIN,), LINE_SCHEMA)
|
||||
super().__init__(
|
||||
CONF_LINE, LvType("lv_line_t"), (CONF_MAIN,), LINE_SCHEMA, modify_schema={}
|
||||
)
|
||||
|
||||
async def to_code(self, w: Widget, config):
|
||||
"""For a line object, create and add the points"""
|
||||
data = literal(config[CONF_POINTS])
|
||||
points = cg.static_const_array(config[CONF_POINT_LIST_ID], data)
|
||||
lv.line_set_points(w.obj, points, len(data))
|
||||
if data := config.get(CONF_POINTS):
|
||||
points = cg.static_const_array(config[CONF_POINT_LIST_ID], data)
|
||||
lv.line_set_points(w.obj, points, len(data))
|
||||
|
||||
|
||||
line_spec = LineType()
|
||||
|
|
|
@ -13,7 +13,7 @@ from ..defines import (
|
|||
TYPE_FLEX,
|
||||
literal,
|
||||
)
|
||||
from ..helpers import add_lv_use
|
||||
from ..helpers import add_lv_use, lvgl_components_required
|
||||
from ..lv_validation import lv_bool, lv_pct, lv_text
|
||||
from ..lvcode import (
|
||||
EVENT_ARG,
|
||||
|
@ -72,6 +72,7 @@ async def msgbox_to_code(conf):
|
|||
*buttonmatrix_spec.get_uses(),
|
||||
*button_spec.get_uses(),
|
||||
)
|
||||
lvgl_components_required.add("BUTTONMATRIX")
|
||||
messagebox_id = conf[CONF_ID]
|
||||
outer = lv_Pvariable(lv_obj_t, messagebox_id.id)
|
||||
buttonmatrix = new_Pvariable(
|
||||
|
|
|
@ -379,6 +379,7 @@ lvgl:
|
|||
format: "bar value %f"
|
||||
args: [x]
|
||||
- line:
|
||||
id: lv_line_id
|
||||
align: center
|
||||
points:
|
||||
- 5, 5
|
||||
|
@ -387,7 +388,10 @@ lvgl:
|
|||
- 180, 60
|
||||
- 240, 10
|
||||
on_click:
|
||||
lvgl.page.next:
|
||||
- lvgl.widget.update:
|
||||
id: lv_line_id
|
||||
line_color: 0xFFFF
|
||||
- lvgl.page.next:
|
||||
- switch:
|
||||
align: right_mid
|
||||
- checkbox:
|
||||
|
|
Loading…
Reference in a new issue