mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 06:58:11 +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.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.const import CONF_ID, CONF_TIMEOUT
|
from esphome.const import CONF_ID, CONF_TIMEOUT
|
||||||
|
from esphome.cpp_generator import RawExpression
|
||||||
from esphome.cpp_types import nullptr
|
from esphome.cpp_types import nullptr
|
||||||
|
|
||||||
from .defines import (
|
from .defines import (
|
||||||
|
@ -26,6 +27,7 @@ from .lvcode import (
|
||||||
add_line_marks,
|
add_line_marks,
|
||||||
lv,
|
lv,
|
||||||
lv_add,
|
lv_add,
|
||||||
|
lv_expr,
|
||||||
lv_obj,
|
lv_obj,
|
||||||
lvgl_comp,
|
lvgl_comp,
|
||||||
)
|
)
|
||||||
|
@ -38,7 +40,13 @@ from .types import (
|
||||||
lv_disp_t,
|
lv_disp_t,
|
||||||
lv_obj_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(
|
async def action_to_code(
|
||||||
|
@ -48,9 +56,11 @@ async def action_to_code(
|
||||||
template_arg,
|
template_arg,
|
||||||
args,
|
args,
|
||||||
):
|
):
|
||||||
|
await wait_for_widgets()
|
||||||
async with LambdaContext(parameters=args, where=action_id) as context:
|
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:
|
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())
|
var = cg.new_Pvariable(action_id, template_arg, await context.get_lambda())
|
||||||
return var
|
return var
|
||||||
|
|
|
@ -294,6 +294,13 @@ void LvglComponent::loop() {
|
||||||
}
|
}
|
||||||
lv_timer_handler_run_in_period(5);
|
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
|
#ifdef USE_LVGL_IMAGE
|
||||||
lv_img_dsc_t *lv_img_from(image::Image *src, lv_img_dsc_t *img_dsc) {
|
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_api_event; // NOLINT
|
||||||
extern lv_event_code_t lv_update_event; // NOLINT
|
extern lv_event_code_t lv_update_event; // NOLINT
|
||||||
|
extern bool lv_is_pre_initialise();
|
||||||
#ifdef USE_LVGL_COLOR
|
#ifdef USE_LVGL_COLOR
|
||||||
inline lv_color_t lv_color_from(Color color) { return lv_color_make(color.red, color.green, color.blue); }
|
inline lv_color_t lv_color_from(Color color) { return lv_color_make(color.red, color.green, color.blue); }
|
||||||
#endif // USE_LVGL_COLOR
|
#endif // USE_LVGL_COLOR
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import asyncio
|
||||||
import sys
|
import sys
|
||||||
from typing import Any, Union
|
from typing import Any, Union
|
||||||
|
|
||||||
|
@ -223,6 +224,11 @@ async def get_widget_(wid: Widget):
|
||||||
return await FakeAwaitable(get_widget_generator(wid))
|
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]:
|
async def get_widgets(config: Union[dict, list], id: str = CONF_ID) -> list[Widget]:
|
||||||
if not config:
|
if not config:
|
||||||
return []
|
return []
|
||||||
|
|
|
@ -3,7 +3,7 @@ import functools
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
|
|
||||||
from ..defines import CONF_MAIN, literal
|
from ..defines import CONF_MAIN
|
||||||
from ..lvcode import lv
|
from ..lvcode import lv
|
||||||
from ..types import LvType
|
from ..types import LvType
|
||||||
from . import Widget, WidgetType
|
from . import Widget, WidgetType
|
||||||
|
@ -38,11 +38,13 @@ LINE_SCHEMA = {
|
||||||
|
|
||||||
class LineType(WidgetType):
|
class LineType(WidgetType):
|
||||||
def __init__(self):
|
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):
|
async def to_code(self, w: Widget, config):
|
||||||
"""For a line object, create and add the points"""
|
"""For a line object, create and add the points"""
|
||||||
data = literal(config[CONF_POINTS])
|
if data := config.get(CONF_POINTS):
|
||||||
points = cg.static_const_array(config[CONF_POINT_LIST_ID], data)
|
points = cg.static_const_array(config[CONF_POINT_LIST_ID], data)
|
||||||
lv.line_set_points(w.obj, points, len(data))
|
lv.line_set_points(w.obj, points, len(data))
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ from ..defines import (
|
||||||
TYPE_FLEX,
|
TYPE_FLEX,
|
||||||
literal,
|
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 ..lv_validation import lv_bool, lv_pct, lv_text
|
||||||
from ..lvcode import (
|
from ..lvcode import (
|
||||||
EVENT_ARG,
|
EVENT_ARG,
|
||||||
|
@ -72,6 +72,7 @@ async def msgbox_to_code(conf):
|
||||||
*buttonmatrix_spec.get_uses(),
|
*buttonmatrix_spec.get_uses(),
|
||||||
*button_spec.get_uses(),
|
*button_spec.get_uses(),
|
||||||
)
|
)
|
||||||
|
lvgl_components_required.add("BUTTONMATRIX")
|
||||||
messagebox_id = conf[CONF_ID]
|
messagebox_id = conf[CONF_ID]
|
||||||
outer = lv_Pvariable(lv_obj_t, messagebox_id.id)
|
outer = lv_Pvariable(lv_obj_t, messagebox_id.id)
|
||||||
buttonmatrix = new_Pvariable(
|
buttonmatrix = new_Pvariable(
|
||||||
|
|
|
@ -379,6 +379,7 @@ lvgl:
|
||||||
format: "bar value %f"
|
format: "bar value %f"
|
||||||
args: [x]
|
args: [x]
|
||||||
- line:
|
- line:
|
||||||
|
id: lv_line_id
|
||||||
align: center
|
align: center
|
||||||
points:
|
points:
|
||||||
- 5, 5
|
- 5, 5
|
||||||
|
@ -387,7 +388,10 @@ lvgl:
|
||||||
- 180, 60
|
- 180, 60
|
||||||
- 240, 10
|
- 240, 10
|
||||||
on_click:
|
on_click:
|
||||||
lvgl.page.next:
|
- lvgl.widget.update:
|
||||||
|
id: lv_line_id
|
||||||
|
line_color: 0xFFFF
|
||||||
|
- lvgl.page.next:
|
||||||
- switch:
|
- switch:
|
||||||
align: right_mid
|
align: right_mid
|
||||||
- checkbox:
|
- checkbox:
|
||||||
|
|
Loading…
Reference in a new issue