mirror of
https://github.com/esphome/esphome.git
synced 2025-04-16 07:40:29 +01:00
commit
b4cf437761
@ -311,6 +311,10 @@ APIError APINoiseFrameHelper::state_action_() {
|
|||||||
const std::string &name = App.get_name();
|
const std::string &name = App.get_name();
|
||||||
const uint8_t *name_ptr = reinterpret_cast<const uint8_t *>(name.c_str());
|
const uint8_t *name_ptr = reinterpret_cast<const uint8_t *>(name.c_str());
|
||||||
msg.insert(msg.end(), name_ptr, name_ptr + name.size() + 1);
|
msg.insert(msg.end(), name_ptr, name_ptr + name.size() + 1);
|
||||||
|
// node mac, terminated by null byte
|
||||||
|
const std::string &mac = get_mac_address();
|
||||||
|
const uint8_t *mac_ptr = reinterpret_cast<const uint8_t *>(mac.c_str());
|
||||||
|
msg.insert(msg.end(), mac_ptr, mac_ptr + mac.size() + 1);
|
||||||
|
|
||||||
aerr = write_frame_(msg.data(), msg.size());
|
aerr = write_frame_(msg.data(), msg.size());
|
||||||
if (aerr != APIError::OK)
|
if (aerr != APIError::OK)
|
||||||
|
@ -30,8 +30,12 @@ void AXS15231Touchscreen::setup() {
|
|||||||
this->interrupt_pin_->setup();
|
this->interrupt_pin_->setup();
|
||||||
this->attach_interrupt_(this->interrupt_pin_, gpio::INTERRUPT_FALLING_EDGE);
|
this->attach_interrupt_(this->interrupt_pin_, gpio::INTERRUPT_FALLING_EDGE);
|
||||||
}
|
}
|
||||||
|
if (this->x_raw_max_ == 0) {
|
||||||
this->x_raw_max_ = this->display_->get_native_width();
|
this->x_raw_max_ = this->display_->get_native_width();
|
||||||
|
}
|
||||||
|
if (this->y_raw_max_ == 0) {
|
||||||
this->y_raw_max_ = this->display_->get_native_height();
|
this->y_raw_max_ = this->display_->get_native_height();
|
||||||
|
}
|
||||||
ESP_LOGCONFIG(TAG, "AXS15231 Touchscreen setup complete");
|
ESP_LOGCONFIG(TAG, "AXS15231 Touchscreen setup complete");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +48,7 @@ void AXS15231Touchscreen::update_touches() {
|
|||||||
err = this->read(data, sizeof(data));
|
err = this->read(data, sizeof(data));
|
||||||
ERROR_CHECK(err);
|
ERROR_CHECK(err);
|
||||||
this->status_clear_warning();
|
this->status_clear_warning();
|
||||||
if (data[0] != 0) // no touches
|
if (data[0] != 0 || data[1] == 0) // no touches
|
||||||
return;
|
return;
|
||||||
uint16_t x = encode_uint16(data[2] & 0xF, data[3]);
|
uint16_t x = encode_uint16(data[2] & 0xF, data[3]);
|
||||||
uint16_t y = encode_uint16(data[4] & 0xF, data[5]);
|
uint16_t y = encode_uint16(data[4] & 0xF, data[5]);
|
||||||
|
@ -4,6 +4,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_ACTION, CONF_GROUP, CONF_ID, CONF_TIMEOUT
|
from esphome.const import CONF_ACTION, CONF_GROUP, CONF_ID, CONF_TIMEOUT
|
||||||
|
from esphome.core import Lambda
|
||||||
from esphome.cpp_generator import TemplateArguments, get_variable
|
from esphome.cpp_generator import TemplateArguments, get_variable
|
||||||
from esphome.cpp_types import nullptr
|
from esphome.cpp_types import nullptr
|
||||||
|
|
||||||
@ -64,7 +65,14 @@ async def action_to_code(
|
|||||||
action_id,
|
action_id,
|
||||||
template_arg,
|
template_arg,
|
||||||
args,
|
args,
|
||||||
|
config=None,
|
||||||
):
|
):
|
||||||
|
# Ensure all required ids have been processed, so our LambdaContext doesn't get context-switched.
|
||||||
|
if config:
|
||||||
|
for lamb in config.values():
|
||||||
|
if isinstance(lamb, Lambda):
|
||||||
|
for id_ in lamb.requires_ids:
|
||||||
|
await get_variable(id_)
|
||||||
await wait_for_widgets()
|
await wait_for_widgets()
|
||||||
async with LambdaContext(parameters=args, where=action_id) as context:
|
async with LambdaContext(parameters=args, where=action_id) as context:
|
||||||
for widget in widgets:
|
for widget in widgets:
|
||||||
@ -84,7 +92,9 @@ async def update_to_code(config, action_id, template_arg, args):
|
|||||||
lv.event_send(widget.obj, UPDATE_EVENT, nullptr)
|
lv.event_send(widget.obj, UPDATE_EVENT, nullptr)
|
||||||
|
|
||||||
widgets = await get_widgets(config[CONF_ID])
|
widgets = await get_widgets(config[CONF_ID])
|
||||||
return await action_to_code(widgets, do_update, action_id, template_arg, args)
|
return await action_to_code(
|
||||||
|
widgets, do_update, action_id, template_arg, args, config
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@automation.register_condition(
|
@automation.register_condition(
|
||||||
@ -348,4 +358,6 @@ async def obj_update_to_code(config, action_id, template_arg, args):
|
|||||||
await set_obj_properties(widget, config)
|
await set_obj_properties(widget, config)
|
||||||
|
|
||||||
widgets = await get_widgets(config[CONF_ID])
|
widgets = await get_widgets(config[CONF_ID])
|
||||||
return await action_to_code(widgets, do_update, action_id, template_arg, args)
|
return await action_to_code(
|
||||||
|
widgets, do_update, action_id, template_arg, args, config
|
||||||
|
)
|
||||||
|
@ -18,6 +18,7 @@ from .helpers import lvgl_components_required, requires_component
|
|||||||
from .lvcode import lv, lv_add, lv_assign, lv_expr, lv_Pvariable
|
from .lvcode import lv, lv_add, lv_assign, lv_expr, lv_Pvariable
|
||||||
from .schemas import ENCODER_SCHEMA
|
from .schemas import ENCODER_SCHEMA
|
||||||
from .types import lv_group_t, lv_indev_type_t, lv_key_t
|
from .types import lv_group_t, lv_indev_type_t, lv_key_t
|
||||||
|
from .widgets import get_widgets
|
||||||
|
|
||||||
ENCODERS_CONFIG = cv.ensure_list(
|
ENCODERS_CONFIG = cv.ensure_list(
|
||||||
ENCODER_SCHEMA.extend(
|
ENCODER_SCHEMA.extend(
|
||||||
@ -76,5 +77,5 @@ async def encoders_to_code(var, config, default_group):
|
|||||||
async def initial_focus_to_code(config):
|
async def initial_focus_to_code(config):
|
||||||
for enc_conf in config[CONF_ENCODERS]:
|
for enc_conf in config[CONF_ENCODERS]:
|
||||||
if default_focus := enc_conf.get(CONF_INITIAL_FOCUS):
|
if default_focus := enc_conf.get(CONF_INITIAL_FOCUS):
|
||||||
obj = await cg.get_variable(default_focus)
|
widget = await get_widgets(default_focus)
|
||||||
lv.group_focus_obj(obj)
|
lv.group_focus_obj(widget[0].obj)
|
||||||
|
@ -173,7 +173,8 @@ class LambdaContext(CodeContext):
|
|||||||
|
|
||||||
class LvContext(LambdaContext):
|
class LvContext(LambdaContext):
|
||||||
"""
|
"""
|
||||||
Code generation into the LVGL initialisation code (called in `setup()`)
|
Code generation into the LVGL initialisation code, called before setup() and loop()
|
||||||
|
Basically just does cg.add, so now fairly redundant.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
added_lambda_count = 0
|
added_lambda_count = 0
|
||||||
|
@ -63,10 +63,12 @@ inline void lv_disp_set_bg_image(lv_disp_t *disp, esphome::image::Image *image)
|
|||||||
inline void lv_obj_set_style_bg_img_src(lv_obj_t *obj, esphome::image::Image *image, lv_style_selector_t selector) {
|
inline void lv_obj_set_style_bg_img_src(lv_obj_t *obj, esphome::image::Image *image, lv_style_selector_t selector) {
|
||||||
lv_obj_set_style_bg_img_src(obj, image->get_lv_img_dsc(), selector);
|
lv_obj_set_style_bg_img_src(obj, image->get_lv_img_dsc(), selector);
|
||||||
}
|
}
|
||||||
|
#ifdef USE_LVGL_CANVAS
|
||||||
inline void lv_canvas_draw_img(lv_obj_t *canvas, lv_coord_t x, lv_coord_t y, image::Image *image,
|
inline void lv_canvas_draw_img(lv_obj_t *canvas, lv_coord_t x, lv_coord_t y, image::Image *image,
|
||||||
lv_draw_img_dsc_t *dsc) {
|
lv_draw_img_dsc_t *dsc) {
|
||||||
lv_canvas_draw_img(canvas, x, y, image->get_lv_img_dsc(), dsc);
|
lv_canvas_draw_img(canvas, x, y, image->get_lv_img_dsc(), dsc);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_LVGL_METER
|
#ifdef USE_LVGL_METER
|
||||||
inline lv_meter_indicator_t *lv_meter_add_needle_img(lv_obj_t *obj, lv_meter_scale_t *scale, esphome::image::Image *src,
|
inline lv_meter_indicator_t *lv_meter_add_needle_img(lv_obj_t *obj, lv_meter_scale_t *scale, esphome::image::Image *src,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
from esphome.components import number
|
from esphome.components import number
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
|
from esphome.const import CONF_RESTORE_VALUE
|
||||||
from esphome.cpp_generator import MockObj
|
from esphome.cpp_generator import MockObj
|
||||||
|
|
||||||
from ..defines import CONF_ANIMATED, CONF_UPDATE_ON_RELEASE, CONF_WIDGET
|
from ..defines import CONF_ANIMATED, CONF_UPDATE_ON_RELEASE, CONF_WIDGET
|
||||||
@ -10,21 +11,21 @@ from ..lvcode import (
|
|||||||
EVENT_ARG,
|
EVENT_ARG,
|
||||||
UPDATE_EVENT,
|
UPDATE_EVENT,
|
||||||
LambdaContext,
|
LambdaContext,
|
||||||
LvContext,
|
ReturnStatement,
|
||||||
lv,
|
lv,
|
||||||
lv_add,
|
|
||||||
lvgl_static,
|
lvgl_static,
|
||||||
)
|
)
|
||||||
from ..types import LV_EVENT, LvNumber, lvgl_ns
|
from ..types import LV_EVENT, LvNumber, lvgl_ns
|
||||||
from ..widgets import get_widgets, wait_for_widgets
|
from ..widgets import get_widgets, wait_for_widgets
|
||||||
|
|
||||||
LVGLNumber = lvgl_ns.class_("LVGLNumber", number.Number)
|
LVGLNumber = lvgl_ns.class_("LVGLNumber", number.Number, cg.Component)
|
||||||
|
|
||||||
CONFIG_SCHEMA = number.number_schema(LVGLNumber).extend(
|
CONFIG_SCHEMA = number.number_schema(LVGLNumber).extend(
|
||||||
{
|
{
|
||||||
cv.Required(CONF_WIDGET): cv.use_id(LvNumber),
|
cv.Required(CONF_WIDGET): cv.use_id(LvNumber),
|
||||||
cv.Optional(CONF_ANIMATED, default=True): animated,
|
cv.Optional(CONF_ANIMATED, default=True): animated,
|
||||||
cv.Optional(CONF_UPDATE_ON_RELEASE, default=False): cv.boolean,
|
cv.Optional(CONF_UPDATE_ON_RELEASE, default=False): cv.boolean,
|
||||||
|
cv.Optional(CONF_RESTORE_VALUE, default=False): cv.boolean,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,32 +33,34 @@ CONFIG_SCHEMA = number.number_schema(LVGLNumber).extend(
|
|||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
widget = await get_widgets(config, CONF_WIDGET)
|
widget = await get_widgets(config, CONF_WIDGET)
|
||||||
widget = widget[0]
|
widget = widget[0]
|
||||||
var = await number.new_number(
|
|
||||||
config,
|
|
||||||
max_value=widget.get_max(),
|
|
||||||
min_value=widget.get_min(),
|
|
||||||
step=widget.get_step(),
|
|
||||||
)
|
|
||||||
|
|
||||||
await wait_for_widgets()
|
await wait_for_widgets()
|
||||||
|
async with LambdaContext([], return_type=cg.float_) as value:
|
||||||
|
value.add(ReturnStatement(widget.get_value()))
|
||||||
async with LambdaContext([(cg.float_, "v")]) as control:
|
async with LambdaContext([(cg.float_, "v")]) as control:
|
||||||
await widget.set_property(
|
await widget.set_property(
|
||||||
"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:
|
|
||||||
event.add(var.publish_state(widget.get_value()))
|
|
||||||
event_code = (
|
event_code = (
|
||||||
LV_EVENT.VALUE_CHANGED
|
LV_EVENT.VALUE_CHANGED
|
||||||
if not config[CONF_UPDATE_ON_RELEASE]
|
if not config[CONF_UPDATE_ON_RELEASE]
|
||||||
else LV_EVENT.RELEASED
|
else LV_EVENT.RELEASED
|
||||||
)
|
)
|
||||||
async with LvContext():
|
var = await number.new_number(
|
||||||
lv_add(var.set_control_lambda(await control.get_lambda()))
|
config,
|
||||||
lv_add(
|
await control.get_lambda(),
|
||||||
|
await value.get_lambda(),
|
||||||
|
event_code,
|
||||||
|
config[CONF_RESTORE_VALUE],
|
||||||
|
max_value=widget.get_max(),
|
||||||
|
min_value=widget.get_min(),
|
||||||
|
step=widget.get_step(),
|
||||||
|
)
|
||||||
|
async with LambdaContext(EVENT_ARG) as event:
|
||||||
|
event.add(var.on_value())
|
||||||
|
await cg.register_component(var, config)
|
||||||
|
cg.add(
|
||||||
lvgl_static.add_event_cb(
|
lvgl_static.add_event_cb(
|
||||||
widget.obj, await event.get_lambda(), UPDATE_EVENT, event_code
|
widget.obj, await event.get_lambda(), UPDATE_EVENT, event_code
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
lv_add(var.publish_state(widget.get_value()))
|
|
||||||
|
@ -3,33 +3,46 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "esphome/components/number/number.h"
|
#include "esphome/components/number/number.h"
|
||||||
#include "esphome/core/automation.h"
|
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#include "esphome/core/preferences.h"
|
#include "esphome/core/preferences.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace lvgl {
|
namespace lvgl {
|
||||||
|
|
||||||
class LVGLNumber : public number::Number {
|
class LVGLNumber : public number::Number, public Component {
|
||||||
public:
|
public:
|
||||||
void set_control_lambda(std::function<void(float)> control_lambda) {
|
LVGLNumber(std::function<void(float)> control_lambda, std::function<float()> value_lambda, lv_event_code_t event,
|
||||||
this->control_lambda_ = std::move(control_lambda);
|
bool restore)
|
||||||
if (this->initial_state_.has_value()) {
|
: control_lambda_(std::move(control_lambda)),
|
||||||
this->control_lambda_(this->initial_state_.value());
|
value_lambda_(std::move(value_lambda)),
|
||||||
this->initial_state_.reset();
|
event_(event),
|
||||||
|
restore_(restore) {}
|
||||||
|
|
||||||
|
void setup() override {
|
||||||
|
float value = this->value_lambda_();
|
||||||
|
if (this->restore_) {
|
||||||
|
this->pref_ = global_preferences->make_preference<float>(this->get_object_id_hash());
|
||||||
|
if (this->pref_.load(&value)) {
|
||||||
|
this->control_lambda_(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this->publish_state(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_value() { this->publish_state(this->value_lambda_()); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void control(float value) override {
|
void control(float value) override {
|
||||||
if (this->control_lambda_ != nullptr) {
|
|
||||||
this->control_lambda_(value);
|
this->control_lambda_(value);
|
||||||
} else {
|
this->publish_state(value);
|
||||||
this->initial_state_ = value;
|
if (this->restore_)
|
||||||
|
this->pref_.save(&value);
|
||||||
}
|
}
|
||||||
}
|
std::function<void(float)> control_lambda_;
|
||||||
std::function<void(float)> control_lambda_{};
|
std::function<float()> value_lambda_;
|
||||||
optional<float> initial_state_{};
|
lv_event_code_t event_;
|
||||||
|
bool restore_;
|
||||||
|
ESPPreferenceObject pref_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace lvgl
|
} // namespace lvgl
|
||||||
|
@ -81,7 +81,9 @@ ENCODER_SCHEMA = cv.Schema(
|
|||||||
cv.declare_id(LVEncoderListener), requires_component("binary_sensor")
|
cv.declare_id(LVEncoderListener), requires_component("binary_sensor")
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_GROUP): cv.declare_id(lv_group_t),
|
cv.Optional(CONF_GROUP): cv.declare_id(lv_group_t),
|
||||||
cv.Optional(df.CONF_INITIAL_FOCUS): cv.use_id(lv_obj_t),
|
cv.Optional(df.CONF_INITIAL_FOCUS): cv.All(
|
||||||
|
LIST_ACTION_SCHEMA, cv.Length(min=1, max=1)
|
||||||
|
),
|
||||||
cv.Optional(df.CONF_LONG_PRESS_TIME, default="400ms"): PRESS_TIME,
|
cv.Optional(df.CONF_LONG_PRESS_TIME, default="400ms"): PRESS_TIME,
|
||||||
cv.Optional(df.CONF_LONG_PRESS_REPEAT_TIME, default="100ms"): PRESS_TIME,
|
cv.Optional(df.CONF_LONG_PRESS_REPEAT_TIME, default="100ms"): PRESS_TIME,
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
|
import esphome.codegen as cg
|
||||||
from esphome.components import select
|
from esphome.components import select
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.const import CONF_OPTIONS
|
from esphome.const import CONF_ID, CONF_OPTIONS, CONF_RESTORE_VALUE
|
||||||
|
|
||||||
from ..defines import CONF_ANIMATED, CONF_WIDGET, literal
|
from ..defines import CONF_ANIMATED, CONF_WIDGET, literal
|
||||||
from ..lvcode import LvContext
|
|
||||||
from ..types import LvSelect, lvgl_ns
|
from ..types import LvSelect, lvgl_ns
|
||||||
from ..widgets import get_widgets, wait_for_widgets
|
from ..widgets import get_widgets
|
||||||
|
|
||||||
LVGLSelect = lvgl_ns.class_("LVGLSelect", select.Select)
|
LVGLSelect = lvgl_ns.class_("LVGLSelect", select.Select, cg.Component)
|
||||||
|
|
||||||
CONFIG_SCHEMA = select.select_schema(LVGLSelect).extend(
|
CONFIG_SCHEMA = select.select_schema(LVGLSelect).extend(
|
||||||
{
|
{
|
||||||
cv.Required(CONF_WIDGET): cv.use_id(LvSelect),
|
cv.Required(CONF_WIDGET): cv.use_id(LvSelect),
|
||||||
cv.Optional(CONF_ANIMATED, default=False): cv.boolean,
|
cv.Optional(CONF_ANIMATED, default=False): cv.boolean,
|
||||||
|
cv.Optional(CONF_RESTORE_VALUE, default=False): cv.boolean,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,12 +22,9 @@ async def to_code(config):
|
|||||||
widget = await get_widgets(config, CONF_WIDGET)
|
widget = await get_widgets(config, CONF_WIDGET)
|
||||||
widget = widget[0]
|
widget = widget[0]
|
||||||
options = widget.config.get(CONF_OPTIONS, [])
|
options = widget.config.get(CONF_OPTIONS, [])
|
||||||
selector = await select.new_select(config, options=options)
|
animated = literal("LV_ANIM_ON" if config[CONF_ANIMATED] else "LV_ANIM_OFF")
|
||||||
await wait_for_widgets()
|
selector = cg.new_Pvariable(
|
||||||
async with LvContext() as ctx:
|
config[CONF_ID], widget.var, animated, config[CONF_RESTORE_VALUE]
|
||||||
ctx.add(
|
|
||||||
selector.set_widget(
|
|
||||||
widget.var,
|
|
||||||
literal("LV_ANIM_ON" if config[CONF_ANIMATED] else "LV_ANIM_OFF"),
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
await select.register_select(selector, config, options=options)
|
||||||
|
await cg.register_component(selector, config)
|
||||||
|
@ -11,12 +11,20 @@
|
|||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace lvgl {
|
namespace lvgl {
|
||||||
|
|
||||||
class LVGLSelect : public select::Select {
|
class LVGLSelect : public select::Select, public Component {
|
||||||
public:
|
public:
|
||||||
void set_widget(LvSelectable *widget, lv_anim_enable_t anim = LV_ANIM_OFF) {
|
LVGLSelect(LvSelectable *widget, lv_anim_enable_t anim, bool restore)
|
||||||
this->widget_ = widget;
|
: widget_(widget), anim_(anim), restore_(restore) {}
|
||||||
this->anim_ = anim;
|
|
||||||
|
void setup() override {
|
||||||
this->set_options_();
|
this->set_options_();
|
||||||
|
if (this->restore_) {
|
||||||
|
size_t index;
|
||||||
|
this->pref_ = global_preferences->make_preference<size_t>(this->get_object_id_hash());
|
||||||
|
if (this->pref_.load(&index))
|
||||||
|
this->widget_->set_selected_index(index, LV_ANIM_OFF);
|
||||||
|
}
|
||||||
|
this->publish();
|
||||||
lv_obj_add_event_cb(
|
lv_obj_add_event_cb(
|
||||||
this->widget_->obj,
|
this->widget_->obj,
|
||||||
[](lv_event_t *e) {
|
[](lv_event_t *e) {
|
||||||
@ -24,11 +32,6 @@ class LVGLSelect : public select::Select {
|
|||||||
it->set_options_();
|
it->set_options_();
|
||||||
},
|
},
|
||||||
LV_EVENT_REFRESH, this);
|
LV_EVENT_REFRESH, this);
|
||||||
if (this->initial_state_.has_value()) {
|
|
||||||
this->control(this->initial_state_.value());
|
|
||||||
this->initial_state_.reset();
|
|
||||||
}
|
|
||||||
this->publish();
|
|
||||||
auto lamb = [](lv_event_t *e) {
|
auto lamb = [](lv_event_t *e) {
|
||||||
auto *self = static_cast<LVGLSelect *>(e->user_data);
|
auto *self = static_cast<LVGLSelect *>(e->user_data);
|
||||||
self->publish();
|
self->publish();
|
||||||
@ -37,21 +40,25 @@ class LVGLSelect : public select::Select {
|
|||||||
lv_obj_add_event_cb(this->widget_->obj, lamb, lv_update_event, this);
|
lv_obj_add_event_cb(this->widget_->obj, lamb, lv_update_event, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void publish() { this->publish_state(this->widget_->get_selected_text()); }
|
void publish() {
|
||||||
|
this->publish_state(this->widget_->get_selected_text());
|
||||||
|
if (this->restore_) {
|
||||||
|
auto index = this->widget_->get_selected_index();
|
||||||
|
this->pref_.save(&index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void control(const std::string &value) override {
|
void control(const std::string &value) override {
|
||||||
if (this->widget_ != nullptr) {
|
|
||||||
this->widget_->set_selected_text(value, this->anim_);
|
this->widget_->set_selected_text(value, this->anim_);
|
||||||
} else {
|
this->publish();
|
||||||
this->initial_state_ = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void set_options_() { this->traits.set_options(this->widget_->get_options()); }
|
void set_options_() { this->traits.set_options(this->widget_->get_options()); }
|
||||||
|
|
||||||
LvSelectable *widget_{};
|
LvSelectable *widget_;
|
||||||
optional<std::string> initial_state_{};
|
lv_anim_enable_t anim_;
|
||||||
lv_anim_enable_t anim_{LV_ANIM_OFF};
|
bool restore_;
|
||||||
|
ESPPreferenceObject pref_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace lvgl
|
} // namespace lvgl
|
||||||
|
@ -250,7 +250,7 @@ async def button_update_to_code(config, action_id, template_arg, args):
|
|||||||
widgets = await get_widgets(config[CONF_ID])
|
widgets = await get_widgets(config[CONF_ID])
|
||||||
assert all(isinstance(w, MatrixButton) for w in widgets)
|
assert all(isinstance(w, MatrixButton) for w in widgets)
|
||||||
|
|
||||||
async def do_button_update(w: MatrixButton):
|
async def do_button_update(w):
|
||||||
if (width := config.get(CONF_WIDTH)) is not None:
|
if (width := config.get(CONF_WIDTH)) is not None:
|
||||||
lv.btnmatrix_set_btn_width(w.obj, w.index, width)
|
lv.btnmatrix_set_btn_width(w.obj, w.index, width)
|
||||||
if config.get(CONF_SELECTED):
|
if config.get(CONF_SELECTED):
|
||||||
@ -275,5 +275,5 @@ async def button_update_to_code(config, action_id, template_arg, args):
|
|||||||
)
|
)
|
||||||
|
|
||||||
return await action_to_code(
|
return await action_to_code(
|
||||||
widgets, do_button_update, action_id, template_arg, args
|
widgets, do_button_update, action_id, template_arg, args, config
|
||||||
)
|
)
|
||||||
|
@ -97,7 +97,7 @@ async def canvas_fill(config, action_id, template_arg, args):
|
|||||||
async def do_fill(w: Widget):
|
async def do_fill(w: Widget):
|
||||||
lv.canvas_fill_bg(w.obj, color, opa)
|
lv.canvas_fill_bg(w.obj, color, opa)
|
||||||
|
|
||||||
return await action_to_code(widget, do_fill, action_id, template_arg, args)
|
return await action_to_code(widget, do_fill, action_id, template_arg, args, config)
|
||||||
|
|
||||||
|
|
||||||
@automation.register_action(
|
@automation.register_action(
|
||||||
@ -145,7 +145,9 @@ async def canvas_set_pixel(config, action_id, template_arg, args):
|
|||||||
x, y = point
|
x, y = point
|
||||||
lv.canvas_set_px_opa(w.obj, x, y, opa_var)
|
lv.canvas_set_px_opa(w.obj, x, y, opa_var)
|
||||||
|
|
||||||
return await action_to_code(widget, do_set_pixels, action_id, template_arg, args)
|
return await action_to_code(
|
||||||
|
widget, do_set_pixels, action_id, template_arg, args, config
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
DRAW_SCHEMA = cv.Schema(
|
DRAW_SCHEMA = cv.Schema(
|
||||||
@ -181,7 +183,9 @@ async def draw_to_code(config, dsc_type, props, do_draw, action_id, template_arg
|
|||||||
lv_assign(getattr(dsc, mapped_prop), value)
|
lv_assign(getattr(dsc, mapped_prop), value)
|
||||||
await do_draw(w, x, y, dsc_addr)
|
await do_draw(w, x, y, dsc_addr)
|
||||||
|
|
||||||
return await action_to_code(widget, action_func, action_id, template_arg, args)
|
return await action_to_code(
|
||||||
|
widget, action_func, action_id, template_arg, args, config
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
RECT_PROPS = {
|
RECT_PROPS = {
|
||||||
|
@ -297,7 +297,9 @@ async def indicator_update_to_code(config, action_id, template_arg, args):
|
|||||||
async def set_value(w: Widget):
|
async def set_value(w: Widget):
|
||||||
await set_indicator_values(w.var, w.obj, config)
|
await set_indicator_values(w.var, w.obj, config)
|
||||||
|
|
||||||
return await action_to_code(widget, set_value, action_id, template_arg, args)
|
return await action_to_code(
|
||||||
|
widget, set_value, action_id, template_arg, args, config
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def set_indicator_values(meter, indicator, config):
|
async def set_indicator_values(meter, indicator, config):
|
||||||
|
@ -441,9 +441,10 @@ void AudioPipeline::decode_task(void *params) {
|
|||||||
pdFALSE, // Wait for all the bits,
|
pdFALSE, // Wait for all the bits,
|
||||||
portMAX_DELAY); // Block indefinitely until bit is set
|
portMAX_DELAY); // Block indefinitely until bit is set
|
||||||
|
|
||||||
if (!(event_bits & EventGroupBits::PIPELINE_COMMAND_STOP)) {
|
|
||||||
xEventGroupClearBits(this_pipeline->event_group_,
|
xEventGroupClearBits(this_pipeline->event_group_,
|
||||||
EventGroupBits::DECODER_MESSAGE_FINISHED | EventGroupBits::READER_MESSAGE_LOADED_MEDIA_TYPE);
|
EventGroupBits::DECODER_MESSAGE_FINISHED | EventGroupBits::READER_MESSAGE_LOADED_MEDIA_TYPE);
|
||||||
|
|
||||||
|
if (!(event_bits & EventGroupBits::PIPELINE_COMMAND_STOP)) {
|
||||||
InfoErrorEvent event;
|
InfoErrorEvent event;
|
||||||
event.source = InfoErrorSource::DECODER;
|
event.source = InfoErrorSource::DECODER;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Constants used by esphome."""
|
"""Constants used by esphome."""
|
||||||
|
|
||||||
__version__ = "2025.4.0b1"
|
__version__ = "2025.4.0b2"
|
||||||
|
|
||||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||||
VALID_SUBSTITUTIONS_CHARACTERS = (
|
VALID_SUBSTITUTIONS_CHARACTERS = (
|
||||||
|
@ -12,9 +12,9 @@ pyserial==3.5
|
|||||||
platformio==6.1.18 # When updating platformio, also update /docker/Dockerfile
|
platformio==6.1.18 # When updating platformio, also update /docker/Dockerfile
|
||||||
esptool==4.8.1
|
esptool==4.8.1
|
||||||
click==8.1.7
|
click==8.1.7
|
||||||
esphome-dashboard==20250212.0
|
esphome-dashboard==20250415.0
|
||||||
aioesphomeapi==29.9.0
|
aioesphomeapi==29.10.0
|
||||||
zeroconf==0.146.3
|
zeroconf==0.146.4
|
||||||
puremagic==1.28
|
puremagic==1.28
|
||||||
ruamel.yaml==0.18.10 # dashboard_import
|
ruamel.yaml==0.18.10 # dashboard_import
|
||||||
esphome-glyphsets==0.2.0
|
esphome-glyphsets==0.2.0
|
||||||
|
@ -38,6 +38,7 @@ number:
|
|||||||
widget: slider_id
|
widget: slider_id
|
||||||
name: LVGL Slider
|
name: LVGL Slider
|
||||||
update_on_release: true
|
update_on_release: true
|
||||||
|
restore_value: true
|
||||||
- platform: lvgl
|
- platform: lvgl
|
||||||
widget: lv_arc
|
widget: lv_arc
|
||||||
id: lvgl_arc_number
|
id: lvgl_arc_number
|
||||||
|
@ -990,3 +990,13 @@ color:
|
|||||||
green_int: 123
|
green_int: 123
|
||||||
blue_int: 64
|
blue_int: 64
|
||||||
white_int: 255
|
white_int: 255
|
||||||
|
|
||||||
|
select:
|
||||||
|
- platform: lvgl
|
||||||
|
id: lv_roller_select
|
||||||
|
widget: lv_roller
|
||||||
|
restore_value: true
|
||||||
|
- platform: lvgl
|
||||||
|
id: lv_dropdown_select
|
||||||
|
widget: lv_dropdown
|
||||||
|
restore_value: false
|
||||||
|
@ -71,5 +71,6 @@ lvgl:
|
|||||||
sensor: encoder
|
sensor: encoder
|
||||||
enter_button: pushbutton
|
enter_button: pushbutton
|
||||||
group: general
|
group: general
|
||||||
|
initial_focus: lv_roller
|
||||||
|
|
||||||
<<: !include common.yaml
|
<<: !include common.yaml
|
||||||
|
Loading…
x
Reference in New Issue
Block a user