mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 22:48:10 +01:00
[lvgl] Bug fixes: (#7341)
This commit is contained in:
parent
71d6bbc7e6
commit
60fced53c2
8 changed files with 49 additions and 8 deletions
|
@ -157,7 +157,7 @@ async def lvgl_update_to_code(config, action_id, template_arg, args):
|
||||||
widgets = await get_widgets(config)
|
widgets = await get_widgets(config)
|
||||||
w = widgets[0]
|
w = widgets[0]
|
||||||
disp = f"{w.obj}->get_disp()"
|
disp = f"{w.obj}->get_disp()"
|
||||||
async with LambdaContext(parameters=args, where=action_id) as context:
|
async with LambdaContext(LVGL_COMP_ARG, where=action_id) as context:
|
||||||
await disp_update(disp, config)
|
await disp_update(disp, config)
|
||||||
var = cg.new_Pvariable(action_id, template_arg, await context.get_lambda())
|
var = cg.new_Pvariable(action_id, template_arg, await context.get_lambda())
|
||||||
await cg.register_parented(var, w.var)
|
await cg.register_parented(var, w.var)
|
||||||
|
|
|
@ -505,4 +505,10 @@ DEFAULT_ESPHOME_FONT = "esphome_lv_default_font"
|
||||||
|
|
||||||
|
|
||||||
def join_enums(enums, prefix=""):
|
def join_enums(enums, prefix=""):
|
||||||
return literal("|".join(f"(int){prefix}{e.upper()}" for e in enums))
|
enums = list(enums)
|
||||||
|
enums.sort()
|
||||||
|
# If a prefix is provided, prepend each constant with the prefix, and assume that all the constants are within the
|
||||||
|
# same namespace, otherwise cast to int to avoid triggering warnings about mixing enum types.
|
||||||
|
if prefix:
|
||||||
|
return literal("|".join(f"{prefix}{e.upper()}" for e in enums))
|
||||||
|
return literal("|".join(f"(int){e.upper()}" for e in enums))
|
||||||
|
|
|
@ -50,6 +50,7 @@ async def to_code(config):
|
||||||
"value", MockObj("v") * MockObj(widget.get_scale()), config[CONF_ANIMATED]
|
"value", MockObj("v") * MockObj(widget.get_scale()), config[CONF_ANIMATED]
|
||||||
)
|
)
|
||||||
lv.event_send(widget.obj, API_EVENT, cg.nullptr)
|
lv.event_send(widget.obj, API_EVENT, cg.nullptr)
|
||||||
|
control.add(var.publish_state(widget.get_value()))
|
||||||
async with LambdaContext(EVENT_ARG) as event:
|
async with LambdaContext(EVENT_ARG) as event:
|
||||||
event.add(var.publish_state(widget.get_value()))
|
event.add(var.publish_state(widget.get_value()))
|
||||||
event_code = (
|
event_code = (
|
||||||
|
|
|
@ -43,6 +43,7 @@ async def to_code(config):
|
||||||
async with LambdaContext([(cg.uint16, "v")]) as control:
|
async with LambdaContext([(cg.uint16, "v")]) as control:
|
||||||
await widget.set_property("selected", "v", animated=config[CONF_ANIMATED])
|
await widget.set_property("selected", "v", animated=config[CONF_ANIMATED])
|
||||||
lv.event_send(widget.obj, API_EVENT, cg.nullptr)
|
lv.event_send(widget.obj, API_EVENT, cg.nullptr)
|
||||||
|
control.add(selector.publish_index(widget.get_value()))
|
||||||
async with LvContext(paren) as ctx:
|
async with LvContext(paren) as ctx:
|
||||||
lv_add(selector.set_control_lambda(await control.get_lambda()))
|
lv_add(selector.set_control_lambda(await control.get_lambda()))
|
||||||
ctx.add(
|
ctx.add(
|
||||||
|
|
|
@ -3,7 +3,7 @@ from esphome.components.switch import Switch, new_switch, switch_schema
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.cpp_generator import MockObj
|
from esphome.cpp_generator import MockObj
|
||||||
|
|
||||||
from ..defines import CONF_LVGL_ID, CONF_WIDGET
|
from ..defines import CONF_LVGL_ID, CONF_WIDGET, literal
|
||||||
from ..lvcode import (
|
from ..lvcode import (
|
||||||
API_EVENT,
|
API_EVENT,
|
||||||
EVENT_ARG,
|
EVENT_ARG,
|
||||||
|
@ -44,6 +44,7 @@ async def to_code(config):
|
||||||
cond.else_()
|
cond.else_()
|
||||||
widget.clear_state(LV_STATE.CHECKED)
|
widget.clear_state(LV_STATE.CHECKED)
|
||||||
lv.event_send(widget.obj, API_EVENT, cg.nullptr)
|
lv.event_send(widget.obj, API_EVENT, cg.nullptr)
|
||||||
|
control.add(switch.publish_state(literal("v")))
|
||||||
async with LvContext(paren) as ctx:
|
async with LvContext(paren) as ctx:
|
||||||
lv_add(switch.set_control_lambda(await control.get_lambda()))
|
lv_add(switch.set_control_lambda(await control.get_lambda()))
|
||||||
ctx.add(
|
ctx.add(
|
||||||
|
|
|
@ -36,6 +36,7 @@ async def to_code(config):
|
||||||
async with LambdaContext([(cg.std_string, "text_value")]) as control:
|
async with LambdaContext([(cg.std_string, "text_value")]) as control:
|
||||||
await widget.set_property("text", "text_value.c_str())")
|
await widget.set_property("text", "text_value.c_str())")
|
||||||
lv.event_send(widget.obj, API_EVENT, None)
|
lv.event_send(widget.obj, API_EVENT, None)
|
||||||
|
control.add(textvar.publish_state(widget.get_value()))
|
||||||
async with LambdaContext(EVENT_ARG) as lamb:
|
async with LambdaContext(EVENT_ARG) as lamb:
|
||||||
lv_add(textvar.publish_state(widget.get_value()))
|
lv_add(textvar.publish_state(widget.get_value()))
|
||||||
async with LvContext(paren):
|
async with LvContext(paren):
|
||||||
|
|
|
@ -118,7 +118,14 @@ class Widget:
|
||||||
def clear_flag(self, flag):
|
def clear_flag(self, flag):
|
||||||
return lv_obj.clear_flag(self.obj, literal(flag))
|
return lv_obj.clear_flag(self.obj, literal(flag))
|
||||||
|
|
||||||
async def set_property(self, prop, value, animated: bool = None):
|
async def set_property(self, prop, value, animated: bool = None, lv_name=None):
|
||||||
|
"""
|
||||||
|
Set a property of the widget.
|
||||||
|
:param prop: The property name
|
||||||
|
:param value: The value
|
||||||
|
:param animated: If the change should be animated
|
||||||
|
:param lv_name: The base type of the widget e.g. "obj"
|
||||||
|
"""
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
value = value.get(prop)
|
value = value.get(prop)
|
||||||
if isinstance(ALL_STYLES.get(prop), LValidator):
|
if isinstance(ALL_STYLES.get(prop), LValidator):
|
||||||
|
@ -131,11 +138,12 @@ class Widget:
|
||||||
value = value.total_milliseconds
|
value = value.total_milliseconds
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
value = literal(value)
|
value = literal(value)
|
||||||
|
lv_name = lv_name or self.type.lv_name
|
||||||
if animated is None or self.type.animated is not True:
|
if animated is None or self.type.animated is not True:
|
||||||
lv.call(f"{self.type.lv_name}_set_{prop}", self.obj, value)
|
lv.call(f"{lv_name}_set_{prop}", self.obj, value)
|
||||||
else:
|
else:
|
||||||
lv.call(
|
lv.call(
|
||||||
f"{self.type.lv_name}_set_{prop}",
|
f"{lv_name}_set_{prop}",
|
||||||
self.obj,
|
self.obj,
|
||||||
value,
|
value,
|
||||||
literal("LV_ANIM_ON" if animated else "LV_ANIM_OFF"),
|
literal("LV_ANIM_ON" if animated else "LV_ANIM_OFF"),
|
||||||
|
@ -319,8 +327,15 @@ async def set_obj_properties(w: Widget, config):
|
||||||
lv_obj.set_flex_align(w.obj, main, cross, track)
|
lv_obj.set_flex_align(w.obj, main, cross, track)
|
||||||
parts = collect_parts(config)
|
parts = collect_parts(config)
|
||||||
for part, states in parts.items():
|
for part, states in parts.items():
|
||||||
|
part = "LV_PART_" + part.upper()
|
||||||
for state, props in states.items():
|
for state, props in states.items():
|
||||||
lv_state = join_enums((f"LV_STATE_{state}", f"LV_PART_{part}"))
|
state = "LV_STATE_" + state.upper()
|
||||||
|
if state == "LV_STATE_DEFAULT":
|
||||||
|
lv_state = literal(part)
|
||||||
|
elif part == "LV_PART_MAIN":
|
||||||
|
lv_state = literal(state)
|
||||||
|
else:
|
||||||
|
lv_state = join_enums((state, part))
|
||||||
for style_id in props.get(CONF_STYLES, ()):
|
for style_id in props.get(CONF_STYLES, ()):
|
||||||
lv_obj.add_style(w.obj, MockObj(style_id), lv_state)
|
lv_obj.add_style(w.obj, MockObj(style_id), lv_state)
|
||||||
for prop, value in {
|
for prop, value in {
|
||||||
|
@ -384,7 +399,7 @@ async def set_obj_properties(w: Widget, config):
|
||||||
w.add_state(state)
|
w.add_state(state)
|
||||||
cond.else_()
|
cond.else_()
|
||||||
w.clear_state(state)
|
w.clear_state(state)
|
||||||
await w.set_property(CONF_SCROLLBAR_MODE, config)
|
await w.set_property(CONF_SCROLLBAR_MODE, config, lv_name="obj")
|
||||||
|
|
||||||
|
|
||||||
async def add_widgets(parent: Widget, config: dict):
|
async def add_widgets(parent: Widget, config: dict):
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
lvgl:
|
lvgl:
|
||||||
log_level: TRACE
|
log_level: TRACE
|
||||||
bg_color: light_blue
|
bg_color: light_blue
|
||||||
|
disp_bg_color: 0xffff00
|
||||||
|
disp_bg_image: cat_image
|
||||||
theme:
|
theme:
|
||||||
obj:
|
obj:
|
||||||
border_width: 1
|
border_width: 1
|
||||||
|
@ -78,6 +80,9 @@ lvgl:
|
||||||
on_click:
|
on_click:
|
||||||
then:
|
then:
|
||||||
- lvgl.animimg.stop: anim_img
|
- lvgl.animimg.stop: anim_img
|
||||||
|
- lvgl.update:
|
||||||
|
disp_bg_color: 0xffff00
|
||||||
|
disp_bg_image: cat_image
|
||||||
- label:
|
- label:
|
||||||
text: "Hello shiny day"
|
text: "Hello shiny day"
|
||||||
text_color: 0xFFFFFF
|
text_color: 0xFFFFFF
|
||||||
|
@ -304,6 +309,17 @@ lvgl:
|
||||||
src: cat_image
|
src: cat_image
|
||||||
align: top_left
|
align: top_left
|
||||||
y: 50
|
y: 50
|
||||||
|
- tileview:
|
||||||
|
id: tileview_id
|
||||||
|
scrollbar_mode: active
|
||||||
|
tiles:
|
||||||
|
- id: page_1
|
||||||
|
row: 0
|
||||||
|
column: 0
|
||||||
|
dir: HOR
|
||||||
|
widgets:
|
||||||
|
- obj:
|
||||||
|
bg_color: 0x000000
|
||||||
|
|
||||||
- id: page2
|
- id: page2
|
||||||
widgets:
|
widgets:
|
||||||
|
|
Loading…
Reference in a new issue