[lvgl] Implement default group for encoders (#7242)

Co-authored-by: clydeps <U5yx99dok9>
This commit is contained in:
Clyde Stubbs 2024-08-12 13:56:54 +10:00 committed by GitHub
parent d04e706295
commit 34d435c996
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 6 deletions

View file

@ -47,6 +47,7 @@ from .types import (
IdleTrigger, IdleTrigger,
ObjUpdateAction, ObjUpdateAction,
lv_font_t, lv_font_t,
lv_group_t,
lv_style_t, lv_style_t,
lvgl_ns, lvgl_ns,
) )
@ -335,8 +336,9 @@ CONFIG_SCHEMA = (
cv.Optional(df.CONF_THEME): cv.Schema( cv.Optional(df.CONF_THEME): cv.Schema(
{cv.Optional(name): obj_schema(w) for name, w in WIDGET_TYPES.items()} {cv.Optional(name): obj_schema(w) for name, w in WIDGET_TYPES.items()}
), ),
cv.GenerateID(df.CONF_TOUCHSCREENS): touchscreen_schema, cv.Optional(df.CONF_TOUCHSCREENS, default=None): touchscreen_schema,
cv.GenerateID(df.CONF_ENCODERS): ENCODERS_CONFIG, cv.Optional(df.CONF_ENCODERS, default=None): ENCODERS_CONFIG,
cv.GenerateID(df.CONF_DEFAULT_GROUP): cv.declare_id(lv_group_t),
} }
) )
.extend(DISP_BG_SCHEMA) .extend(DISP_BG_SCHEMA)

View file

@ -386,6 +386,7 @@ CONF_COLOR_DEPTH = "color_depth"
CONF_CONTROL = "control" CONF_CONTROL = "control"
CONF_DEFAULT = "default" CONF_DEFAULT = "default"
CONF_DEFAULT_FONT = "default_font" CONF_DEFAULT_FONT = "default_font"
CONF_DEFAULT_GROUP = "default_group"
CONF_DIR = "dir" CONF_DIR = "dir"
CONF_DISPLAYS = "displays" CONF_DISPLAYS = "displays"
CONF_ENCODERS = "encoders" CONF_ENCODERS = "encoders"

View file

@ -5,6 +5,7 @@ import esphome.config_validation as cv
from esphome.const import CONF_GROUP, CONF_ID, CONF_SENSOR from esphome.const import CONF_GROUP, CONF_ID, CONF_SENSOR
from .defines import ( from .defines import (
CONF_DEFAULT_GROUP,
CONF_ENCODERS, CONF_ENCODERS,
CONF_ENTER_BUTTON, CONF_ENTER_BUTTON,
CONF_LEFT_BUTTON, CONF_LEFT_BUTTON,
@ -38,7 +39,10 @@ ENCODERS_CONFIG = cv.ensure_list(
async def encoders_to_code(var, config): async def encoders_to_code(var, config):
for enc_conf in config.get(CONF_ENCODERS, ()): default_group = lv_Pvariable(lv_group_t, config[CONF_DEFAULT_GROUP])
lv_assign(default_group, lv_expr.group_create())
lv.group_set_default(default_group)
for enc_conf in config[CONF_ENCODERS]:
lvgl_components_required.add("KEY_LISTENER") lvgl_components_required.add("KEY_LISTENER")
lpt = enc_conf[CONF_LONG_PRESS_TIME].total_milliseconds lpt = enc_conf[CONF_LONG_PRESS_TIME].total_milliseconds
lprt = enc_conf[CONF_LONG_PRESS_REPEAT_TIME].total_milliseconds lprt = enc_conf[CONF_LONG_PRESS_REPEAT_TIME].total_milliseconds
@ -60,6 +64,6 @@ async def encoders_to_code(var, config):
if group := enc_conf.get(CONF_GROUP): if group := enc_conf.get(CONF_GROUP):
group = lv_Pvariable(lv_group_t, group) group = lv_Pvariable(lv_group_t, group)
lv_assign(group, lv_expr.group_create()) lv_assign(group, lv_expr.group_create())
lv.indev_set_group(lv_expr.indev_drv_register(listener.get_drv()), group)
else: else:
lv.indev_drv_register(listener.get_drv()) group = default_group
lv.indev_set_group(lv_expr.indev_drv_register(listener.get_drv()), group)

View file

@ -34,7 +34,7 @@ def touchscreen_schema(config):
async def touchscreens_to_code(var, config): async def touchscreens_to_code(var, config):
for tconf in config.get(CONF_TOUCHSCREENS, ()): for tconf in config[CONF_TOUCHSCREENS]:
lvgl_components_required.add(CONF_TOUCHSCREEN) lvgl_components_required.add(CONF_TOUCHSCREEN)
touchscreen = await cg.get_variable(tconf[CONF_TOUCHSCREEN_ID]) touchscreen = await cg.get_variable(tconf[CONF_TOUCHSCREEN_ID])
lpt = tconf[CONF_LONG_PRESS_TIME].total_milliseconds lpt = tconf[CONF_LONG_PRESS_TIME].total_milliseconds