mirror of
https://github.com/esphome/esphome.git
synced 2024-12-12 08:24:55 +01:00
Merge branch 'dev' into remove_dependency
This commit is contained in:
commit
1d227ea7f8
48 changed files with 500 additions and 180 deletions
|
@ -38,7 +38,7 @@ from esphome.const import (
|
||||||
SECRETS_FILES,
|
SECRETS_FILES,
|
||||||
)
|
)
|
||||||
from esphome.core import CORE, EsphomeError, coroutine
|
from esphome.core import CORE, EsphomeError, coroutine
|
||||||
from esphome.helpers import indent, is_ip_address
|
from esphome.helpers import indent, is_ip_address, get_bool_env
|
||||||
from esphome.log import Fore, color, setup_log
|
from esphome.log import Fore, color, setup_log
|
||||||
from esphome.util import (
|
from esphome.util import (
|
||||||
get_serial_ports,
|
get_serial_ports,
|
||||||
|
@ -731,7 +731,11 @@ POST_CONFIG_ACTIONS = {
|
||||||
def parse_args(argv):
|
def parse_args(argv):
|
||||||
options_parser = argparse.ArgumentParser(add_help=False)
|
options_parser = argparse.ArgumentParser(add_help=False)
|
||||||
options_parser.add_argument(
|
options_parser.add_argument(
|
||||||
"-v", "--verbose", help="Enable verbose ESPHome logs.", action="store_true"
|
"-v",
|
||||||
|
"--verbose",
|
||||||
|
help="Enable verbose ESPHome logs.",
|
||||||
|
action="store_true",
|
||||||
|
default=get_bool_env("ESPHOME_VERBOSE"),
|
||||||
)
|
)
|
||||||
options_parser.add_argument(
|
options_parser.add_argument(
|
||||||
"-q", "--quiet", help="Disable all ESPHome logs.", action="store_true"
|
"-q", "--quiet", help="Disable all ESPHome logs.", action="store_true"
|
||||||
|
|
|
@ -1,34 +1,34 @@
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
|
||||||
from esphome.components import sensor, spi
|
from esphome.components import sensor, spi
|
||||||
|
import esphome.config_validation as cv
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
CONF_ID,
|
|
||||||
CONF_REACTIVE_POWER,
|
|
||||||
CONF_VOLTAGE,
|
|
||||||
CONF_CURRENT,
|
CONF_CURRENT,
|
||||||
|
CONF_FORWARD_ACTIVE_ENERGY,
|
||||||
|
CONF_FREQUENCY,
|
||||||
|
CONF_ID,
|
||||||
|
CONF_LINE_FREQUENCY,
|
||||||
CONF_POWER,
|
CONF_POWER,
|
||||||
CONF_POWER_FACTOR,
|
CONF_POWER_FACTOR,
|
||||||
CONF_FREQUENCY,
|
CONF_REACTIVE_POWER,
|
||||||
CONF_FORWARD_ACTIVE_ENERGY,
|
|
||||||
CONF_REVERSE_ACTIVE_ENERGY,
|
CONF_REVERSE_ACTIVE_ENERGY,
|
||||||
|
CONF_VOLTAGE,
|
||||||
DEVICE_CLASS_CURRENT,
|
DEVICE_CLASS_CURRENT,
|
||||||
DEVICE_CLASS_ENERGY,
|
DEVICE_CLASS_ENERGY,
|
||||||
DEVICE_CLASS_POWER,
|
DEVICE_CLASS_POWER,
|
||||||
DEVICE_CLASS_POWER_FACTOR,
|
DEVICE_CLASS_POWER_FACTOR,
|
||||||
DEVICE_CLASS_VOLTAGE,
|
DEVICE_CLASS_VOLTAGE,
|
||||||
ICON_LIGHTBULB,
|
|
||||||
ICON_CURRENT_AC,
|
ICON_CURRENT_AC,
|
||||||
|
ICON_LIGHTBULB,
|
||||||
STATE_CLASS_MEASUREMENT,
|
STATE_CLASS_MEASUREMENT,
|
||||||
STATE_CLASS_TOTAL_INCREASING,
|
STATE_CLASS_TOTAL_INCREASING,
|
||||||
|
UNIT_AMPERE,
|
||||||
UNIT_HERTZ,
|
UNIT_HERTZ,
|
||||||
UNIT_VOLT,
|
UNIT_VOLT,
|
||||||
UNIT_AMPERE,
|
|
||||||
UNIT_WATT,
|
|
||||||
UNIT_VOLT_AMPS_REACTIVE,
|
UNIT_VOLT_AMPS_REACTIVE,
|
||||||
|
UNIT_WATT,
|
||||||
UNIT_WATT_HOURS,
|
UNIT_WATT_HOURS,
|
||||||
)
|
)
|
||||||
|
|
||||||
CONF_LINE_FREQUENCY = "line_frequency"
|
|
||||||
CONF_METER_CONSTANT = "meter_constant"
|
CONF_METER_CONSTANT = "meter_constant"
|
||||||
CONF_PL_CONST = "pl_const"
|
CONF_PL_CONST = "pl_const"
|
||||||
CONF_GAIN_PGA = "gain_pga"
|
CONF_GAIN_PGA = "gain_pga"
|
||||||
|
|
|
@ -7,6 +7,7 @@ from esphome.const import (
|
||||||
CONF_FORWARD_ACTIVE_ENERGY,
|
CONF_FORWARD_ACTIVE_ENERGY,
|
||||||
CONF_FREQUENCY,
|
CONF_FREQUENCY,
|
||||||
CONF_ID,
|
CONF_ID,
|
||||||
|
CONF_LINE_FREQUENCY,
|
||||||
CONF_PHASE_A,
|
CONF_PHASE_A,
|
||||||
CONF_PHASE_ANGLE,
|
CONF_PHASE_ANGLE,
|
||||||
CONF_PHASE_B,
|
CONF_PHASE_B,
|
||||||
|
@ -39,7 +40,6 @@ from esphome.const import (
|
||||||
|
|
||||||
from . import atm90e32_ns
|
from . import atm90e32_ns
|
||||||
|
|
||||||
CONF_LINE_FREQUENCY = "line_frequency"
|
|
||||||
CONF_CHIP_TEMPERATURE = "chip_temperature"
|
CONF_CHIP_TEMPERATURE = "chip_temperature"
|
||||||
CONF_GAIN_PGA = "gain_pga"
|
CONF_GAIN_PGA = "gain_pga"
|
||||||
CONF_CURRENT_PHASES = "current_phases"
|
CONF_CURRENT_PHASES = "current_phases"
|
||||||
|
|
|
@ -172,6 +172,19 @@ def add_idf_component(
|
||||||
KEY_COMPONENTS: components,
|
KEY_COMPONENTS: components,
|
||||||
KEY_SUBMODULES: submodules,
|
KEY_SUBMODULES: submodules,
|
||||||
}
|
}
|
||||||
|
else:
|
||||||
|
component_config = CORE.data[KEY_ESP32][KEY_COMPONENTS][name]
|
||||||
|
if components is not None:
|
||||||
|
component_config[KEY_COMPONENTS] = list(
|
||||||
|
set(component_config[KEY_COMPONENTS] + components)
|
||||||
|
)
|
||||||
|
if submodules is not None:
|
||||||
|
if component_config[KEY_SUBMODULES] is None:
|
||||||
|
component_config[KEY_SUBMODULES] = submodules
|
||||||
|
else:
|
||||||
|
component_config[KEY_SUBMODULES] = list(
|
||||||
|
set(component_config[KEY_SUBMODULES] + submodules)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def add_extra_script(stage: str, filename: str, path: str):
|
def add_extra_script(stage: str, filename: str, path: str):
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#endif
|
#endif
|
||||||
#include <driver/ledc.h>
|
#include <driver/ledc.h>
|
||||||
|
|
||||||
|
#include <cinttypes>
|
||||||
|
|
||||||
#define CLOCK_FREQUENCY 80e6f
|
#define CLOCK_FREQUENCY 80e6f
|
||||||
|
|
||||||
#ifdef USE_ARDUINO
|
#ifdef USE_ARDUINO
|
||||||
|
@ -115,20 +117,22 @@ void LEDCOutput::write_state(float state) {
|
||||||
const uint32_t max_duty = (uint32_t(1) << this->bit_depth_) - 1;
|
const uint32_t max_duty = (uint32_t(1) << this->bit_depth_) - 1;
|
||||||
const float duty_rounded = roundf(state * max_duty);
|
const float duty_rounded = roundf(state * max_duty);
|
||||||
auto duty = static_cast<uint32_t>(duty_rounded);
|
auto duty = static_cast<uint32_t>(duty_rounded);
|
||||||
|
ESP_LOGV(TAG, "Setting duty: %" PRIu32 " on channel %u", duty, this->channel_);
|
||||||
#ifdef USE_ARDUINO
|
#ifdef USE_ARDUINO
|
||||||
ESP_LOGV(TAG, "Setting duty: %u on channel %u", duty, this->channel_);
|
|
||||||
ledcWrite(this->channel_, duty);
|
ledcWrite(this->channel_, duty);
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_ESP_IDF
|
#ifdef USE_ESP_IDF
|
||||||
// ensure that 100% on is not 99.975% on
|
|
||||||
if ((duty == max_duty) && (max_duty != 1)) {
|
|
||||||
duty = max_duty + 1;
|
|
||||||
}
|
|
||||||
auto speed_mode = get_speed_mode(channel_);
|
auto speed_mode = get_speed_mode(channel_);
|
||||||
auto chan_num = static_cast<ledc_channel_t>(channel_ % 8);
|
auto chan_num = static_cast<ledc_channel_t>(channel_ % 8);
|
||||||
int hpoint = ledc_angle_to_htop(this->phase_angle_, this->bit_depth_);
|
int hpoint = ledc_angle_to_htop(this->phase_angle_, this->bit_depth_);
|
||||||
|
if (duty == max_duty) {
|
||||||
|
ledc_stop(speed_mode, chan_num, 1);
|
||||||
|
} else if (duty == 0) {
|
||||||
|
ledc_stop(speed_mode, chan_num, 0);
|
||||||
|
} else {
|
||||||
ledc_set_duty_with_hpoint(speed_mode, chan_num, duty, hpoint);
|
ledc_set_duty_with_hpoint(speed_mode, chan_num, duty, hpoint);
|
||||||
ledc_update_duty(speed_mode, chan_num);
|
ledc_update_duty(speed_mode, chan_num);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,10 @@ async def to_code(config):
|
||||||
await add_top_layer(config)
|
await add_top_layer(config)
|
||||||
await msgboxes_to_code(config)
|
await msgboxes_to_code(config)
|
||||||
await disp_update(f"{lv_component}->get_disp()", config)
|
await disp_update(f"{lv_component}->get_disp()", config)
|
||||||
|
# At this point only the setup code should be generated
|
||||||
|
assert LvContext.added_lambda_count == 1
|
||||||
Widget.set_completed()
|
Widget.set_completed()
|
||||||
|
async with LvContext(lv_component):
|
||||||
await generate_triggers(lv_component)
|
await generate_triggers(lv_component)
|
||||||
for conf in config.get(CONF_ON_IDLE, ()):
|
for conf in config.get(CONF_ON_IDLE, ()):
|
||||||
templ = await cg.templatable(conf[CONF_TIMEOUT], [], cg.uint32)
|
templ = await cg.templatable(conf[CONF_TIMEOUT], [], cg.uint32)
|
||||||
|
|
|
@ -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
|
||||||
|
@ -147,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)
|
||||||
|
|
|
@ -10,7 +10,7 @@ from ..defines import CONF_LVGL_ID, CONF_WIDGET
|
||||||
from ..lvcode import EVENT_ARG, LambdaContext, LvContext
|
from ..lvcode import EVENT_ARG, LambdaContext, LvContext
|
||||||
from ..schemas import LVGL_SCHEMA
|
from ..schemas import LVGL_SCHEMA
|
||||||
from ..types import LV_EVENT, lv_pseudo_button_t
|
from ..types import LV_EVENT, lv_pseudo_button_t
|
||||||
from ..widgets import Widget, get_widgets
|
from ..widgets import Widget, get_widgets, wait_for_widgets
|
||||||
|
|
||||||
CONFIG_SCHEMA = (
|
CONFIG_SCHEMA = (
|
||||||
binary_sensor_schema(BinarySensor)
|
binary_sensor_schema(BinarySensor)
|
||||||
|
@ -29,6 +29,7 @@ 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]
|
||||||
assert isinstance(widget, Widget)
|
assert isinstance(widget, Widget)
|
||||||
|
await wait_for_widgets()
|
||||||
async with LambdaContext(EVENT_ARG) as pressed_ctx:
|
async with LambdaContext(EVENT_ARG) as pressed_ctx:
|
||||||
pressed_ctx.add(sensor.publish_state(widget.is_pressed()))
|
pressed_ctx.add(sensor.publish_state(widget.is_pressed()))
|
||||||
async with LvContext(paren) as ctx:
|
async with LvContext(paren) as ctx:
|
||||||
|
|
|
@ -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))
|
||||||
|
|
|
@ -8,7 +8,7 @@ from ..defines import CONF_LVGL_ID
|
||||||
from ..lvcode import LvContext
|
from ..lvcode import LvContext
|
||||||
from ..schemas import LVGL_SCHEMA
|
from ..schemas import LVGL_SCHEMA
|
||||||
from ..types import LvType, lvgl_ns
|
from ..types import LvType, lvgl_ns
|
||||||
from ..widgets import get_widgets
|
from ..widgets import get_widgets, wait_for_widgets
|
||||||
|
|
||||||
lv_led_t = LvType("lv_led_t")
|
lv_led_t = LvType("lv_led_t")
|
||||||
LVLight = lvgl_ns.class_("LVLight", LightOutput)
|
LVLight = lvgl_ns.class_("LVLight", LightOutput)
|
||||||
|
@ -28,5 +28,6 @@ async def to_code(config):
|
||||||
paren = await cg.get_variable(config[CONF_LVGL_ID])
|
paren = await cg.get_variable(config[CONF_LVGL_ID])
|
||||||
widget = await get_widgets(config, CONF_LED)
|
widget = await get_widgets(config, CONF_LED)
|
||||||
widget = widget[0]
|
widget = widget[0]
|
||||||
|
await wait_for_widgets()
|
||||||
async with LvContext(paren) as ctx:
|
async with LvContext(paren) as ctx:
|
||||||
ctx.add(var.set_obj(widget.obj))
|
ctx.add(var.set_obj(widget.obj))
|
||||||
|
|
|
@ -176,6 +176,8 @@ class LvContext(LambdaContext):
|
||||||
Code generation into the LVGL initialisation code (called in `setup()`)
|
Code generation into the LVGL initialisation code (called in `setup()`)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
added_lambda_count = 0
|
||||||
|
|
||||||
def __init__(self, lv_component, args=None):
|
def __init__(self, lv_component, args=None):
|
||||||
self.args = args or LVGL_COMP_ARG
|
self.args = args or LVGL_COMP_ARG
|
||||||
super().__init__(parameters=self.args)
|
super().__init__(parameters=self.args)
|
||||||
|
@ -183,6 +185,7 @@ class LvContext(LambdaContext):
|
||||||
|
|
||||||
async def add_init_lambda(self):
|
async def add_init_lambda(self):
|
||||||
cg.add(self.lv_component.add_init_lambda(await self.get_lambda()))
|
cg.add(self.lv_component.add_init_lambda(await self.get_lambda()))
|
||||||
|
LvContext.added_lambda_count += 1
|
||||||
|
|
||||||
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
||||||
await super().__aexit__(exc_type, exc_val, exc_tb)
|
await super().__aexit__(exc_type, exc_val, exc_tb)
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -16,7 +16,7 @@ from ..lvcode import (
|
||||||
)
|
)
|
||||||
from ..schemas import LVGL_SCHEMA
|
from ..schemas import LVGL_SCHEMA
|
||||||
from ..types import LV_EVENT, LvNumber, lvgl_ns
|
from ..types import LV_EVENT, LvNumber, lvgl_ns
|
||||||
from ..widgets import get_widgets
|
from ..widgets import get_widgets, wait_for_widgets
|
||||||
|
|
||||||
LVGLNumber = lvgl_ns.class_("LVGLNumber", number.Number)
|
LVGLNumber = lvgl_ns.class_("LVGLNumber", number.Number)
|
||||||
|
|
||||||
|
@ -44,11 +44,13 @@ async def to_code(config):
|
||||||
step=widget.get_step(),
|
step=widget.get_step(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await wait_for_widgets()
|
||||||
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:
|
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 = (
|
||||||
|
|
|
@ -15,7 +15,7 @@ from ..lvcode import (
|
||||||
)
|
)
|
||||||
from ..schemas import LVGL_SCHEMA
|
from ..schemas import LVGL_SCHEMA
|
||||||
from ..types import LV_EVENT, LvSelect, lvgl_ns
|
from ..types import LV_EVENT, LvSelect, lvgl_ns
|
||||||
from ..widgets import get_widgets
|
from ..widgets import get_widgets, wait_for_widgets
|
||||||
|
|
||||||
LVGLSelect = lvgl_ns.class_("LVGLSelect", select.Select)
|
LVGLSelect = lvgl_ns.class_("LVGLSelect", select.Select)
|
||||||
|
|
||||||
|
@ -37,11 +37,13 @@ async def to_code(config):
|
||||||
options = widget.config.get(CONF_OPTIONS, [])
|
options = widget.config.get(CONF_OPTIONS, [])
|
||||||
selector = await select.new_select(config, options=options)
|
selector = await select.new_select(config, options=options)
|
||||||
paren = await cg.get_variable(config[CONF_LVGL_ID])
|
paren = await cg.get_variable(config[CONF_LVGL_ID])
|
||||||
|
await wait_for_widgets()
|
||||||
async with LambdaContext(EVENT_ARG) as pub_ctx:
|
async with LambdaContext(EVENT_ARG) as pub_ctx:
|
||||||
pub_ctx.add(selector.publish_index(widget.get_value()))
|
pub_ctx.add(selector.publish_index(widget.get_value()))
|
||||||
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(
|
||||||
|
|
|
@ -14,7 +14,7 @@ from ..lvcode import (
|
||||||
)
|
)
|
||||||
from ..schemas import LVGL_SCHEMA
|
from ..schemas import LVGL_SCHEMA
|
||||||
from ..types import LV_EVENT, LvNumber
|
from ..types import LV_EVENT, LvNumber
|
||||||
from ..widgets import Widget, get_widgets
|
from ..widgets import Widget, get_widgets, wait_for_widgets
|
||||||
|
|
||||||
CONFIG_SCHEMA = (
|
CONFIG_SCHEMA = (
|
||||||
sensor_schema(Sensor)
|
sensor_schema(Sensor)
|
||||||
|
@ -33,6 +33,7 @@ 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]
|
||||||
assert isinstance(widget, Widget)
|
assert isinstance(widget, Widget)
|
||||||
|
await wait_for_widgets()
|
||||||
async with LambdaContext(EVENT_ARG) as lamb:
|
async with LambdaContext(EVENT_ARG) as lamb:
|
||||||
lv_add(sensor.publish_state(widget.get_value()))
|
lv_add(sensor.publish_state(widget.get_value()))
|
||||||
async with LvContext(paren, LVGL_COMP_ARG):
|
async with LvContext(paren, LVGL_COMP_ARG):
|
||||||
|
|
|
@ -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,
|
||||||
|
@ -16,7 +16,7 @@ from ..lvcode import (
|
||||||
)
|
)
|
||||||
from ..schemas import LVGL_SCHEMA
|
from ..schemas import LVGL_SCHEMA
|
||||||
from ..types import LV_EVENT, LV_STATE, lv_pseudo_button_t, lvgl_ns
|
from ..types import LV_EVENT, LV_STATE, lv_pseudo_button_t, lvgl_ns
|
||||||
from ..widgets import get_widgets
|
from ..widgets import get_widgets, wait_for_widgets
|
||||||
|
|
||||||
LVGLSwitch = lvgl_ns.class_("LVGLSwitch", Switch)
|
LVGLSwitch = lvgl_ns.class_("LVGLSwitch", Switch)
|
||||||
CONFIG_SCHEMA = (
|
CONFIG_SCHEMA = (
|
||||||
|
@ -35,6 +35,7 @@ async def to_code(config):
|
||||||
paren = await cg.get_variable(config[CONF_LVGL_ID])
|
paren = await cg.get_variable(config[CONF_LVGL_ID])
|
||||||
widget = await get_widgets(config, CONF_WIDGET)
|
widget = await get_widgets(config, CONF_WIDGET)
|
||||||
widget = widget[0]
|
widget = widget[0]
|
||||||
|
await wait_for_widgets()
|
||||||
async with LambdaContext(EVENT_ARG) as checked_ctx:
|
async with LambdaContext(EVENT_ARG) as checked_ctx:
|
||||||
checked_ctx.add(switch.publish_state(widget.get_value()))
|
checked_ctx.add(switch.publish_state(widget.get_value()))
|
||||||
async with LambdaContext([(cg.bool_, "v")]) as control:
|
async with LambdaContext([(cg.bool_, "v")]) as control:
|
||||||
|
@ -43,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(
|
||||||
|
|
|
@ -15,7 +15,7 @@ from ..lvcode import (
|
||||||
)
|
)
|
||||||
from ..schemas import LVGL_SCHEMA
|
from ..schemas import LVGL_SCHEMA
|
||||||
from ..types import LV_EVENT, LvText, lvgl_ns
|
from ..types import LV_EVENT, LvText, lvgl_ns
|
||||||
from ..widgets import get_widgets
|
from ..widgets import get_widgets, wait_for_widgets
|
||||||
|
|
||||||
LVGLText = lvgl_ns.class_("LVGLText", text.Text)
|
LVGLText = lvgl_ns.class_("LVGLText", text.Text)
|
||||||
|
|
||||||
|
@ -32,9 +32,11 @@ async def to_code(config):
|
||||||
paren = await cg.get_variable(config[CONF_LVGL_ID])
|
paren = await cg.get_variable(config[CONF_LVGL_ID])
|
||||||
widget = await get_widgets(config, CONF_WIDGET)
|
widget = await get_widgets(config, CONF_WIDGET)
|
||||||
widget = widget[0]
|
widget = widget[0]
|
||||||
|
await wait_for_widgets()
|
||||||
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):
|
||||||
|
|
|
@ -10,7 +10,7 @@ from ..defines import CONF_LVGL_ID, CONF_WIDGET
|
||||||
from ..lvcode import API_EVENT, EVENT_ARG, UPDATE_EVENT, LambdaContext, LvContext
|
from ..lvcode import API_EVENT, EVENT_ARG, UPDATE_EVENT, LambdaContext, LvContext
|
||||||
from ..schemas import LVGL_SCHEMA
|
from ..schemas import LVGL_SCHEMA
|
||||||
from ..types import LV_EVENT, LvText
|
from ..types import LV_EVENT, LvText
|
||||||
from ..widgets import get_widgets
|
from ..widgets import get_widgets, wait_for_widgets
|
||||||
|
|
||||||
CONFIG_SCHEMA = (
|
CONFIG_SCHEMA = (
|
||||||
text_sensor_schema(TextSensor)
|
text_sensor_schema(TextSensor)
|
||||||
|
@ -28,6 +28,7 @@ async def to_code(config):
|
||||||
paren = await cg.get_variable(config[CONF_LVGL_ID])
|
paren = await cg.get_variable(config[CONF_LVGL_ID])
|
||||||
widget = await get_widgets(config, CONF_WIDGET)
|
widget = await get_widgets(config, CONF_WIDGET)
|
||||||
widget = widget[0]
|
widget = widget[0]
|
||||||
|
await wait_for_widgets()
|
||||||
async with LambdaContext(EVENT_ARG) as pressed_ctx:
|
async with LambdaContext(EVENT_ARG) as pressed_ctx:
|
||||||
pressed_ctx.add(sensor.publish_state(widget.get_value()))
|
pressed_ctx.add(sensor.publish_state(widget.get_value()))
|
||||||
async with LvContext(paren) as ctx:
|
async with LvContext(paren) as ctx:
|
||||||
|
|
|
@ -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"),
|
||||||
|
@ -223,6 +231,19 @@ async def get_widget_(wid: Widget):
|
||||||
return await FakeAwaitable(get_widget_generator(wid))
|
return await FakeAwaitable(get_widget_generator(wid))
|
||||||
|
|
||||||
|
|
||||||
|
def widgets_wait_generator():
|
||||||
|
while True:
|
||||||
|
if Widget.widgets_completed:
|
||||||
|
return
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
async def wait_for_widgets():
|
||||||
|
if Widget.widgets_completed:
|
||||||
|
return
|
||||||
|
await FakeAwaitable(widgets_wait_generator())
|
||||||
|
|
||||||
|
|
||||||
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 []
|
||||||
|
@ -306,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 {
|
||||||
|
@ -371,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):
|
||||||
|
|
|
@ -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(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
|
@ -136,6 +136,9 @@ void Pipsolar::loop() {
|
||||||
if (this->output_source_priority_battery_switch_) {
|
if (this->output_source_priority_battery_switch_) {
|
||||||
this->output_source_priority_battery_switch_->publish_state(value_output_source_priority_ == 2);
|
this->output_source_priority_battery_switch_->publish_state(value_output_source_priority_ == 2);
|
||||||
}
|
}
|
||||||
|
if (this->output_source_priority_hybrid_switch_) {
|
||||||
|
this->output_source_priority_hybrid_switch_->publish_state(value_output_source_priority_ == 3);
|
||||||
|
}
|
||||||
if (this->charger_source_priority_) {
|
if (this->charger_source_priority_) {
|
||||||
this->charger_source_priority_->publish_state(value_charger_source_priority_);
|
this->charger_source_priority_->publish_state(value_charger_source_priority_);
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,6 +174,7 @@ class Pipsolar : public uart::UARTDevice, public PollingComponent {
|
||||||
PIPSOLAR_SWITCH(output_source_priority_utility_switch, QPIRI)
|
PIPSOLAR_SWITCH(output_source_priority_utility_switch, QPIRI)
|
||||||
PIPSOLAR_SWITCH(output_source_priority_solar_switch, QPIRI)
|
PIPSOLAR_SWITCH(output_source_priority_solar_switch, QPIRI)
|
||||||
PIPSOLAR_SWITCH(output_source_priority_battery_switch, QPIRI)
|
PIPSOLAR_SWITCH(output_source_priority_battery_switch, QPIRI)
|
||||||
|
PIPSOLAR_SWITCH(output_source_priority_hybrid_switch, QPIRI)
|
||||||
PIPSOLAR_SWITCH(input_voltage_range_switch, QPIRI)
|
PIPSOLAR_SWITCH(input_voltage_range_switch, QPIRI)
|
||||||
PIPSOLAR_SWITCH(pv_ok_condition_for_parallel_switch, QPIRI)
|
PIPSOLAR_SWITCH(pv_ok_condition_for_parallel_switch, QPIRI)
|
||||||
PIPSOLAR_SWITCH(pv_power_balance_switch, QPIRI)
|
PIPSOLAR_SWITCH(pv_power_balance_switch, QPIRI)
|
||||||
|
|
|
@ -9,6 +9,7 @@ DEPENDENCIES = ["uart"]
|
||||||
CONF_OUTPUT_SOURCE_PRIORITY_UTILITY = "output_source_priority_utility"
|
CONF_OUTPUT_SOURCE_PRIORITY_UTILITY = "output_source_priority_utility"
|
||||||
CONF_OUTPUT_SOURCE_PRIORITY_SOLAR = "output_source_priority_solar"
|
CONF_OUTPUT_SOURCE_PRIORITY_SOLAR = "output_source_priority_solar"
|
||||||
CONF_OUTPUT_SOURCE_PRIORITY_BATTERY = "output_source_priority_battery"
|
CONF_OUTPUT_SOURCE_PRIORITY_BATTERY = "output_source_priority_battery"
|
||||||
|
CONF_OUTPUT_SOURCE_PRIORITY_HYBRID = "output_source_priority_hybrid"
|
||||||
CONF_INPUT_VOLTAGE_RANGE = "input_voltage_range"
|
CONF_INPUT_VOLTAGE_RANGE = "input_voltage_range"
|
||||||
CONF_PV_OK_CONDITION_FOR_PARALLEL = "pv_ok_condition_for_parallel"
|
CONF_PV_OK_CONDITION_FOR_PARALLEL = "pv_ok_condition_for_parallel"
|
||||||
CONF_PV_POWER_BALANCE = "pv_power_balance"
|
CONF_PV_POWER_BALANCE = "pv_power_balance"
|
||||||
|
@ -17,6 +18,7 @@ TYPES = {
|
||||||
CONF_OUTPUT_SOURCE_PRIORITY_UTILITY: ("POP00", None),
|
CONF_OUTPUT_SOURCE_PRIORITY_UTILITY: ("POP00", None),
|
||||||
CONF_OUTPUT_SOURCE_PRIORITY_SOLAR: ("POP01", None),
|
CONF_OUTPUT_SOURCE_PRIORITY_SOLAR: ("POP01", None),
|
||||||
CONF_OUTPUT_SOURCE_PRIORITY_BATTERY: ("POP02", None),
|
CONF_OUTPUT_SOURCE_PRIORITY_BATTERY: ("POP02", None),
|
||||||
|
CONF_OUTPUT_SOURCE_PRIORITY_HYBRID: ("POP03", None),
|
||||||
CONF_INPUT_VOLTAGE_RANGE: ("PGR01", "PGR00"),
|
CONF_INPUT_VOLTAGE_RANGE: ("PGR01", "PGR00"),
|
||||||
CONF_PV_OK_CONDITION_FOR_PARALLEL: ("PPVOKC1", "PPVOKC0"),
|
CONF_PV_OK_CONDITION_FOR_PARALLEL: ("PPVOKC1", "PPVOKC0"),
|
||||||
CONF_PV_POWER_BALANCE: ("PSPB1", "PSPB0"),
|
CONF_PV_POWER_BALANCE: ("PSPB1", "PSPB0"),
|
||||||
|
|
|
@ -7,8 +7,10 @@
|
||||||
|
|
||||||
#include <hardware/clocks.h>
|
#include <hardware/clocks.h>
|
||||||
#include <hardware/dma.h>
|
#include <hardware/dma.h>
|
||||||
|
#include <hardware/irq.h>
|
||||||
#include <hardware/pio.h>
|
#include <hardware/pio.h>
|
||||||
#include <pico/stdlib.h>
|
#include <pico/stdlib.h>
|
||||||
|
#include <pico/sem.h>
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace rp2040_pio_led_strip {
|
namespace rp2040_pio_led_strip {
|
||||||
|
@ -23,6 +25,19 @@ static std::map<Chipset, bool> conf_count_ = {
|
||||||
{CHIPSET_WS2812, false}, {CHIPSET_WS2812B, false}, {CHIPSET_SK6812, false},
|
{CHIPSET_WS2812, false}, {CHIPSET_WS2812B, false}, {CHIPSET_SK6812, false},
|
||||||
{CHIPSET_SM16703, false}, {CHIPSET_CUSTOM, false},
|
{CHIPSET_SM16703, false}, {CHIPSET_CUSTOM, false},
|
||||||
};
|
};
|
||||||
|
static bool dma_chan_active_[12];
|
||||||
|
static struct semaphore dma_write_complete_sem_[12];
|
||||||
|
|
||||||
|
// DMA interrupt service routine
|
||||||
|
void RP2040PIOLEDStripLightOutput::dma_write_complete_handler_() {
|
||||||
|
uint32_t channel = dma_hw->ints0;
|
||||||
|
for (uint dma_chan = 0; dma_chan < 12; ++dma_chan) {
|
||||||
|
if (RP2040PIOLEDStripLightOutput::dma_chan_active_[dma_chan] && (channel & (1u << dma_chan))) {
|
||||||
|
dma_hw->ints0 = (1u << dma_chan); // Clear the interrupt
|
||||||
|
sem_release(&RP2040PIOLEDStripLightOutput::dma_write_complete_sem_[dma_chan]); // Handle the interrupt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RP2040PIOLEDStripLightOutput::setup() {
|
void RP2040PIOLEDStripLightOutput::setup() {
|
||||||
ESP_LOGCONFIG(TAG, "Setting up RP2040 LED Strip...");
|
ESP_LOGCONFIG(TAG, "Setting up RP2040 LED Strip...");
|
||||||
|
@ -57,22 +72,22 @@ void RP2040PIOLEDStripLightOutput::setup() {
|
||||||
// but there are only 4 state machines on each PIO so we can only have 4 strips per PIO
|
// but there are only 4 state machines on each PIO so we can only have 4 strips per PIO
|
||||||
uint offset = 0;
|
uint offset = 0;
|
||||||
|
|
||||||
if (num_instance_[this->pio_ == pio0 ? 0 : 1] > 4) {
|
if (RP2040PIOLEDStripLightOutput::num_instance_[this->pio_ == pio0 ? 0 : 1] > 4) {
|
||||||
ESP_LOGE(TAG, "Too many instances of PIO program");
|
ESP_LOGE(TAG, "Too many instances of PIO program");
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// keep track of how many instances of the PIO program are running on each PIO
|
// keep track of how many instances of the PIO program are running on each PIO
|
||||||
num_instance_[this->pio_ == pio0 ? 0 : 1]++;
|
RP2040PIOLEDStripLightOutput::num_instance_[this->pio_ == pio0 ? 0 : 1]++;
|
||||||
|
|
||||||
// if there are multiple strips of the same chipset, we can reuse the same PIO program and save space
|
// if there are multiple strips of the same chipset, we can reuse the same PIO program and save space
|
||||||
if (this->conf_count_[this->chipset_]) {
|
if (this->conf_count_[this->chipset_]) {
|
||||||
offset = chipset_offsets_[this->chipset_];
|
offset = RP2040PIOLEDStripLightOutput::chipset_offsets_[this->chipset_];
|
||||||
} else {
|
} else {
|
||||||
// Load the assembled program into the PIO and get its location in the PIO's instruction memory and save it
|
// Load the assembled program into the PIO and get its location in the PIO's instruction memory and save it
|
||||||
offset = pio_add_program(this->pio_, this->program_);
|
offset = pio_add_program(this->pio_, this->program_);
|
||||||
chipset_offsets_[this->chipset_] = offset;
|
RP2040PIOLEDStripLightOutput::chipset_offsets_[this->chipset_] = offset;
|
||||||
conf_count_[this->chipset_] = true;
|
RP2040PIOLEDStripLightOutput::conf_count_[this->chipset_] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure the state machine's PIO, and start it
|
// Configure the state machine's PIO, and start it
|
||||||
|
@ -93,6 +108,9 @@ void RP2040PIOLEDStripLightOutput::setup() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark the DMA channel as active
|
||||||
|
RP2040PIOLEDStripLightOutput::dma_chan_active_[this->dma_chan_] = true;
|
||||||
|
|
||||||
this->dma_config_ = dma_channel_get_default_config(this->dma_chan_);
|
this->dma_config_ = dma_channel_get_default_config(this->dma_chan_);
|
||||||
channel_config_set_transfer_data_size(
|
channel_config_set_transfer_data_size(
|
||||||
&this->dma_config_,
|
&this->dma_config_,
|
||||||
|
@ -109,6 +127,13 @@ void RP2040PIOLEDStripLightOutput::setup() {
|
||||||
false // don't start yet
|
false // don't start yet
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Initialize the semaphore for this DMA channel
|
||||||
|
sem_init(&RP2040PIOLEDStripLightOutput::dma_write_complete_sem_[this->dma_chan_], 1, 1);
|
||||||
|
|
||||||
|
irq_set_exclusive_handler(DMA_IRQ_0, dma_write_complete_handler_); // after DMA all data, raise an interrupt
|
||||||
|
dma_channel_set_irq0_enabled(this->dma_chan_, true); // map DMA channel to interrupt
|
||||||
|
irq_set_enabled(DMA_IRQ_0, true); // enable interrupt
|
||||||
|
|
||||||
this->init_(this->pio_, this->sm_, offset, this->pin_, this->max_refresh_rate_);
|
this->init_(this->pio_, this->sm_, offset, this->pin_, this->max_refresh_rate_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,6 +151,7 @@ void RP2040PIOLEDStripLightOutput::write_state(light::LightState *state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// the bits are already in the correct order for the pio program so we can just copy the buffer using DMA
|
// the bits are already in the correct order for the pio program so we can just copy the buffer using DMA
|
||||||
|
sem_acquire_blocking(&RP2040PIOLEDStripLightOutput::dma_write_complete_sem_[this->dma_chan_]);
|
||||||
dma_channel_transfer_from_buffer_now(this->dma_chan_, this->buf_, this->get_buffer_size_());
|
dma_channel_transfer_from_buffer_now(this->dma_chan_, this->buf_, this->get_buffer_size_());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <hardware/pio.h>
|
#include <hardware/pio.h>
|
||||||
#include <hardware/structs/pio.h>
|
#include <hardware/structs/pio.h>
|
||||||
#include <pico/stdio.h>
|
#include <pico/stdio.h>
|
||||||
|
#include <pico/sem.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
|
@ -95,6 +96,8 @@ class RP2040PIOLEDStripLightOutput : public light::AddressableLight {
|
||||||
|
|
||||||
size_t get_buffer_size_() const { return this->num_leds_ * (3 + this->is_rgbw_); }
|
size_t get_buffer_size_() const { return this->num_leds_ * (3 + this->is_rgbw_); }
|
||||||
|
|
||||||
|
static void dma_write_complete_handler_();
|
||||||
|
|
||||||
uint8_t *buf_{nullptr};
|
uint8_t *buf_{nullptr};
|
||||||
uint8_t *effect_data_{nullptr};
|
uint8_t *effect_data_{nullptr};
|
||||||
|
|
||||||
|
@ -120,6 +123,8 @@ class RP2040PIOLEDStripLightOutput : public light::AddressableLight {
|
||||||
inline static int num_instance_[2];
|
inline static int num_instance_[2];
|
||||||
inline static std::map<Chipset, bool> conf_count_;
|
inline static std::map<Chipset, bool> conf_count_;
|
||||||
inline static std::map<Chipset, int> chipset_offsets_;
|
inline static std::map<Chipset, int> chipset_offsets_;
|
||||||
|
inline static bool dma_chan_active_[12];
|
||||||
|
inline static struct semaphore dma_write_complete_sem_[12];
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace rp2040_pio_led_strip
|
} // namespace rp2040_pio_led_strip
|
||||||
|
|
|
@ -32,7 +32,7 @@ void Rtttl::play(std::string rtttl) {
|
||||||
if (this->state_ != State::STATE_STOPPED && this->state_ != State::STATE_STOPPING) {
|
if (this->state_ != State::STATE_STOPPED && this->state_ != State::STATE_STOPPING) {
|
||||||
int pos = this->rtttl_.find(':');
|
int pos = this->rtttl_.find(':');
|
||||||
auto name = this->rtttl_.substr(0, pos);
|
auto name = this->rtttl_.substr(0, pos);
|
||||||
ESP_LOGW(TAG, "RTTL Component is already playing: %s", name.c_str());
|
ESP_LOGW(TAG, "RTTTL Component is already playing: %s", name.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +122,7 @@ void Rtttl::stop() {
|
||||||
#ifdef USE_OUTPUT
|
#ifdef USE_OUTPUT
|
||||||
if (this->output_ != nullptr) {
|
if (this->output_ != nullptr) {
|
||||||
this->output_->set_level(0.0);
|
this->output_->set_level(0.0);
|
||||||
|
this->set_state_(STATE_STOPPED);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_SPEAKER
|
#ifdef USE_SPEAKER
|
||||||
|
@ -129,10 +130,10 @@ void Rtttl::stop() {
|
||||||
if (this->speaker_->is_running()) {
|
if (this->speaker_->is_running()) {
|
||||||
this->speaker_->stop();
|
this->speaker_->stop();
|
||||||
}
|
}
|
||||||
|
this->set_state_(STATE_STOPPING);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
this->note_duration_ = 0;
|
this->note_duration_ = 0;
|
||||||
this->set_state_(STATE_STOPPING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rtttl::loop() {
|
void Rtttl::loop() {
|
||||||
|
@ -342,6 +343,7 @@ void Rtttl::finish_() {
|
||||||
#ifdef USE_OUTPUT
|
#ifdef USE_OUTPUT
|
||||||
if (this->output_ != nullptr) {
|
if (this->output_ != nullptr) {
|
||||||
this->output_->set_level(0.0);
|
this->output_->set_level(0.0);
|
||||||
|
this->set_state_(State::STATE_STOPPED);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_SPEAKER
|
#ifdef USE_SPEAKER
|
||||||
|
@ -354,9 +356,9 @@ void Rtttl::finish_() {
|
||||||
this->speaker_->play((uint8_t *) (&sample), 8);
|
this->speaker_->play((uint8_t *) (&sample), 8);
|
||||||
|
|
||||||
this->speaker_->finish();
|
this->speaker_->finish();
|
||||||
|
this->set_state_(State::STATE_STOPPING);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
this->set_state_(State::STATE_STOPPING);
|
|
||||||
this->note_duration_ = 0;
|
this->note_duration_ = 0;
|
||||||
this->on_finished_playback_callback_.call();
|
this->on_finished_playback_callback_.call();
|
||||||
ESP_LOGD(TAG, "Playback finished");
|
ESP_LOGD(TAG, "Playback finished");
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
#if defined(USE_SOCKET_IMPL_LWIP_TCP) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) || defined(USE_SOCKET_IMPL_BSD_SOCKETS)
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -74,3 +75,4 @@ socklen_t set_sockaddr_any(struct sockaddr *addr, socklen_t addrlen, uint16_t po
|
||||||
}
|
}
|
||||||
} // namespace socket
|
} // namespace socket
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "esphome/core/optional.h"
|
#include "esphome/core/optional.h"
|
||||||
#include "headers.h"
|
#include "headers.h"
|
||||||
|
|
||||||
|
#if defined(USE_SOCKET_IMPL_LWIP_TCP) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) || defined(USE_SOCKET_IMPL_BSD_SOCKETS)
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace socket {
|
namespace socket {
|
||||||
|
|
||||||
|
@ -57,3 +58,4 @@ socklen_t set_sockaddr_any(struct sockaddr *addr, socklen_t addrlen, uint16_t po
|
||||||
|
|
||||||
} // namespace socket
|
} // namespace socket
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ CONF_DATAPOINT_TYPE = "datapoint_type"
|
||||||
CONF_STATUS_PIN = "status_pin"
|
CONF_STATUS_PIN = "status_pin"
|
||||||
|
|
||||||
tuya_ns = cg.esphome_ns.namespace("tuya")
|
tuya_ns = cg.esphome_ns.namespace("tuya")
|
||||||
|
TuyaDatapointType = tuya_ns.enum("TuyaDatapointType", is_class=True)
|
||||||
Tuya = tuya_ns.class_("Tuya", cg.Component, uart.UARTDevice)
|
Tuya = tuya_ns.class_("Tuya", cg.Component, uart.UARTDevice)
|
||||||
|
|
||||||
DPTYPE_ANY = "any"
|
DPTYPE_ANY = "any"
|
||||||
|
|
|
@ -8,18 +8,36 @@ from esphome.const import (
|
||||||
CONF_MIN_VALUE,
|
CONF_MIN_VALUE,
|
||||||
CONF_MULTIPLY,
|
CONF_MULTIPLY,
|
||||||
CONF_STEP,
|
CONF_STEP,
|
||||||
|
CONF_INITIAL_VALUE,
|
||||||
)
|
)
|
||||||
from .. import tuya_ns, CONF_TUYA_ID, Tuya
|
from .. import tuya_ns, CONF_TUYA_ID, Tuya, TuyaDatapointType
|
||||||
|
|
||||||
DEPENDENCIES = ["tuya"]
|
DEPENDENCIES = ["tuya"]
|
||||||
CODEOWNERS = ["@frankiboy1"]
|
CODEOWNERS = ["@frankiboy1"]
|
||||||
|
|
||||||
|
CONF_DATAPOINT_HIDDEN = "datapoint_hidden"
|
||||||
|
CONF_DATAPOINT_TYPE = "datapoint_type"
|
||||||
|
|
||||||
TuyaNumber = tuya_ns.class_("TuyaNumber", number.Number, cg.Component)
|
TuyaNumber = tuya_ns.class_("TuyaNumber", number.Number, cg.Component)
|
||||||
|
|
||||||
|
DATAPOINT_TYPES = {
|
||||||
|
"int": TuyaDatapointType.INTEGER,
|
||||||
|
"uint": TuyaDatapointType.INTEGER,
|
||||||
|
"enum": TuyaDatapointType.ENUM,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def validate_min_max(config):
|
def validate_min_max(config):
|
||||||
if config[CONF_MAX_VALUE] <= config[CONF_MIN_VALUE]:
|
max_value = config[CONF_MAX_VALUE]
|
||||||
|
min_value = config[CONF_MIN_VALUE]
|
||||||
|
if max_value <= min_value:
|
||||||
raise cv.Invalid("max_value must be greater than min_value")
|
raise cv.Invalid("max_value must be greater than min_value")
|
||||||
|
if hidden_config := config.get(CONF_DATAPOINT_HIDDEN):
|
||||||
|
if (initial_value := hidden_config.get(CONF_INITIAL_VALUE, None)) is not None:
|
||||||
|
if (initial_value > max_value) or (initial_value < min_value):
|
||||||
|
raise cv.Invalid(
|
||||||
|
f"{CONF_INITIAL_VALUE} must be a value between {CONF_MAX_VALUE} and {CONF_MIN_VALUE}"
|
||||||
|
)
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,6 +51,16 @@ CONFIG_SCHEMA = cv.All(
|
||||||
cv.Required(CONF_MIN_VALUE): cv.float_,
|
cv.Required(CONF_MIN_VALUE): cv.float_,
|
||||||
cv.Required(CONF_STEP): cv.positive_float,
|
cv.Required(CONF_STEP): cv.positive_float,
|
||||||
cv.Optional(CONF_MULTIPLY, default=1.0): cv.float_,
|
cv.Optional(CONF_MULTIPLY, default=1.0): cv.float_,
|
||||||
|
cv.Optional(CONF_DATAPOINT_HIDDEN): cv.All(
|
||||||
|
cv.Schema(
|
||||||
|
{
|
||||||
|
cv.Required(CONF_DATAPOINT_TYPE): cv.enum(
|
||||||
|
DATAPOINT_TYPES, lower=True
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_INITIAL_VALUE): cv.float_,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.extend(cv.COMPONENT_SCHEMA),
|
.extend(cv.COMPONENT_SCHEMA),
|
||||||
|
@ -56,3 +84,9 @@ async def to_code(config):
|
||||||
cg.add(var.set_tuya_parent(parent))
|
cg.add(var.set_tuya_parent(parent))
|
||||||
|
|
||||||
cg.add(var.set_number_id(config[CONF_NUMBER_DATAPOINT]))
|
cg.add(var.set_number_id(config[CONF_NUMBER_DATAPOINT]))
|
||||||
|
if hidden_config := config.get(CONF_DATAPOINT_HIDDEN):
|
||||||
|
cg.add(var.set_datapoint_type(hidden_config[CONF_DATAPOINT_TYPE]))
|
||||||
|
if (
|
||||||
|
hidden_init_value := hidden_config.get(CONF_INITIAL_VALUE, None)
|
||||||
|
) is not None:
|
||||||
|
cg.add(var.set_datapoint_initial_value(hidden_init_value))
|
||||||
|
|
|
@ -15,8 +15,18 @@ void TuyaNumber::setup() {
|
||||||
ESP_LOGV(TAG, "MCU reported number %u is: %u", datapoint.id, datapoint.value_enum);
|
ESP_LOGV(TAG, "MCU reported number %u is: %u", datapoint.id, datapoint.value_enum);
|
||||||
this->publish_state(datapoint.value_enum);
|
this->publish_state(datapoint.value_enum);
|
||||||
}
|
}
|
||||||
|
if ((this->type_) && (this->type_ != datapoint.type)) {
|
||||||
|
ESP_LOGW(TAG, "Reported type (%d) different than previously set (%d)!", static_cast<int>(datapoint.type),
|
||||||
|
static_cast<int>(*this->type_));
|
||||||
|
}
|
||||||
this->type_ = datapoint.type;
|
this->type_ = datapoint.type;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this->parent_->add_on_initialized_callback([this] {
|
||||||
|
if ((this->initial_value_) && (this->type_)) {
|
||||||
|
this->control(*this->initial_value_);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void TuyaNumber::control(float value) {
|
void TuyaNumber::control(float value) {
|
||||||
|
@ -33,6 +43,15 @@ void TuyaNumber::control(float value) {
|
||||||
void TuyaNumber::dump_config() {
|
void TuyaNumber::dump_config() {
|
||||||
LOG_NUMBER("", "Tuya Number", this);
|
LOG_NUMBER("", "Tuya Number", this);
|
||||||
ESP_LOGCONFIG(TAG, " Number has datapoint ID %u", this->number_id_);
|
ESP_LOGCONFIG(TAG, " Number has datapoint ID %u", this->number_id_);
|
||||||
|
if (this->type_) {
|
||||||
|
ESP_LOGCONFIG(TAG, " Datapoint type is %d", static_cast<int>(*this->type_));
|
||||||
|
} else {
|
||||||
|
ESP_LOGCONFIG(TAG, " Datapoint type is unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->initial_value_) {
|
||||||
|
ESP_LOGCONFIG(TAG, " Initial Value: %f", *this->initial_value_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace tuya
|
} // namespace tuya
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#include "esphome/components/tuya/tuya.h"
|
#include "esphome/components/tuya/tuya.h"
|
||||||
#include "esphome/components/number/number.h"
|
#include "esphome/components/number/number.h"
|
||||||
|
#include "esphome/core/optional.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace tuya {
|
namespace tuya {
|
||||||
|
@ -13,6 +14,8 @@ class TuyaNumber : public number::Number, public Component {
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
void set_number_id(uint8_t number_id) { this->number_id_ = number_id; }
|
void set_number_id(uint8_t number_id) { this->number_id_ = number_id; }
|
||||||
void set_write_multiply(float factor) { multiply_by_ = factor; }
|
void set_write_multiply(float factor) { multiply_by_ = factor; }
|
||||||
|
void set_datapoint_type(TuyaDatapointType type) { type_ = type; }
|
||||||
|
void set_datapoint_initial_value(float value) { this->initial_value_ = value; }
|
||||||
|
|
||||||
void set_tuya_parent(Tuya *parent) { this->parent_ = parent; }
|
void set_tuya_parent(Tuya *parent) { this->parent_ = parent; }
|
||||||
|
|
||||||
|
@ -22,7 +25,8 @@ class TuyaNumber : public number::Number, public Component {
|
||||||
Tuya *parent_;
|
Tuya *parent_;
|
||||||
uint8_t number_id_{0};
|
uint8_t number_id_{0};
|
||||||
float multiply_by_{1.0};
|
float multiply_by_{1.0};
|
||||||
TuyaDatapointType type_{};
|
optional<TuyaDatapointType> type_{};
|
||||||
|
optional<float> initial_value_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tuya
|
} // namespace tuya
|
||||||
|
|
|
@ -480,7 +480,7 @@ void HOT WaveshareEPaperTypeA::display() {
|
||||||
this->start_data_();
|
this->start_data_();
|
||||||
switch (this->model_) {
|
switch (this->model_) {
|
||||||
case TTGO_EPAPER_2_13_IN_B1: { // block needed because of variable initializations
|
case TTGO_EPAPER_2_13_IN_B1: { // block needed because of variable initializations
|
||||||
int16_t wb = ((this->get_width_internal()) >> 3);
|
int16_t wb = ((this->get_width_controller()) >> 3);
|
||||||
for (int i = 0; i < this->get_height_internal(); i++) {
|
for (int i = 0; i < this->get_height_internal(); i++) {
|
||||||
for (int j = 0; j < wb; j++) {
|
for (int j = 0; j < wb; j++) {
|
||||||
int idx = j + (this->get_height_internal() - 1 - i) * wb;
|
int idx = j + (this->get_height_internal() - 1 - i) * wb;
|
||||||
|
@ -766,7 +766,7 @@ void WaveshareEPaper2P7InV2::initialize() {
|
||||||
// XRAM_START_AND_END_POSITION
|
// XRAM_START_AND_END_POSITION
|
||||||
this->command(0x44);
|
this->command(0x44);
|
||||||
this->data(0x00);
|
this->data(0x00);
|
||||||
this->data(((get_width_internal() - 1) >> 3) & 0xFF);
|
this->data(((this->get_width_controller() - 1) >> 3) & 0xFF);
|
||||||
// YRAM_START_AND_END_POSITION
|
// YRAM_START_AND_END_POSITION
|
||||||
this->command(0x45);
|
this->command(0x45);
|
||||||
this->data(0x00);
|
this->data(0x00);
|
||||||
|
@ -928,8 +928,8 @@ void HOT WaveshareEPaper2P7InB::display() {
|
||||||
|
|
||||||
// TCON_RESOLUTION
|
// TCON_RESOLUTION
|
||||||
this->command(0x61);
|
this->command(0x61);
|
||||||
this->data(this->get_width_internal() >> 8);
|
this->data(this->get_width_controller() >> 8);
|
||||||
this->data(this->get_width_internal() & 0xff); // 176
|
this->data(this->get_width_controller() & 0xff); // 176
|
||||||
this->data(this->get_height_internal() >> 8);
|
this->data(this->get_height_internal() >> 8);
|
||||||
this->data(this->get_height_internal() & 0xff); // 264
|
this->data(this->get_height_internal() & 0xff); // 264
|
||||||
|
|
||||||
|
@ -994,7 +994,7 @@ void WaveshareEPaper2P7InBV2::initialize() {
|
||||||
// self.SetWindows(0, 0, self.width-1, self.height-1)
|
// self.SetWindows(0, 0, self.width-1, self.height-1)
|
||||||
// SetWindows(self, Xstart, Ystart, Xend, Yend):
|
// SetWindows(self, Xstart, Ystart, Xend, Yend):
|
||||||
|
|
||||||
uint32_t xend = this->get_width_internal() - 1;
|
uint32_t xend = this->get_width_controller() - 1;
|
||||||
uint32_t yend = this->get_height_internal() - 1;
|
uint32_t yend = this->get_height_internal() - 1;
|
||||||
this->command(0x44);
|
this->command(0x44);
|
||||||
this->data(0x00);
|
this->data(0x00);
|
||||||
|
|
|
@ -431,6 +431,7 @@ CONF_LIGHT_ID = "light_id"
|
||||||
CONF_LIGHTNING_ENERGY = "lightning_energy"
|
CONF_LIGHTNING_ENERGY = "lightning_energy"
|
||||||
CONF_LIGHTNING_THRESHOLD = "lightning_threshold"
|
CONF_LIGHTNING_THRESHOLD = "lightning_threshold"
|
||||||
CONF_LIMIT_MODE = "limit_mode"
|
CONF_LIMIT_MODE = "limit_mode"
|
||||||
|
CONF_LINE_FREQUENCY = "line_frequency"
|
||||||
CONF_LINE_THICKNESS = "line_thickness"
|
CONF_LINE_THICKNESS = "line_thickness"
|
||||||
CONF_LINE_TYPE = "line_type"
|
CONF_LINE_TYPE = "line_type"
|
||||||
CONF_LOADED_INTEGRATIONS = "loaded_integrations"
|
CONF_LOADED_INTEGRATIONS = "loaded_integrations"
|
||||||
|
@ -1042,6 +1043,7 @@ UNIT_KILOVOLT_AMPS_REACTIVE = "kVAR"
|
||||||
UNIT_KILOVOLT_AMPS_REACTIVE_HOURS = "kVARh"
|
UNIT_KILOVOLT_AMPS_REACTIVE_HOURS = "kVARh"
|
||||||
UNIT_KILOWATT = "kW"
|
UNIT_KILOWATT = "kW"
|
||||||
UNIT_KILOWATT_HOURS = "kWh"
|
UNIT_KILOWATT_HOURS = "kWh"
|
||||||
|
UNIT_LITRE = "L"
|
||||||
UNIT_LUX = "lx"
|
UNIT_LUX = "lx"
|
||||||
UNIT_METER = "m"
|
UNIT_METER = "m"
|
||||||
UNIT_METER_PER_SECOND_SQUARED = "m/s²"
|
UNIT_METER_PER_SECOND_SQUARED = "m/s²"
|
||||||
|
|
|
@ -1,19 +1,64 @@
|
||||||
#include "bytebuffer.h"
|
#include "bytebuffer.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
|
|
||||||
ByteBuffer ByteBuffer::create(size_t capacity) {
|
ByteBuffer ByteBuffer::wrap(const uint8_t *ptr, size_t len, Endian endianness) {
|
||||||
std::vector<uint8_t> data(capacity);
|
// there is a double copy happening here, could be optimized but at cost of clarity.
|
||||||
return {data};
|
|
||||||
}
|
|
||||||
|
|
||||||
ByteBuffer ByteBuffer::wrap(uint8_t *ptr, size_t len) {
|
|
||||||
std::vector<uint8_t> data(ptr, ptr + len);
|
std::vector<uint8_t> data(ptr, ptr + len);
|
||||||
return {data};
|
ByteBuffer buffer = {data};
|
||||||
|
buffer.endianness_ = endianness;
|
||||||
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer ByteBuffer::wrap(std::vector<uint8_t> data) { return {std::move(data)}; }
|
ByteBuffer ByteBuffer::wrap(std::vector<uint8_t> const &data, Endian endianness) {
|
||||||
|
ByteBuffer buffer = {data};
|
||||||
|
buffer.endianness_ = endianness;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteBuffer ByteBuffer::wrap(uint8_t value) {
|
||||||
|
ByteBuffer buffer = ByteBuffer(1);
|
||||||
|
buffer.put_uint8(value);
|
||||||
|
buffer.flip();
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteBuffer ByteBuffer::wrap(uint16_t value, Endian endianness) {
|
||||||
|
ByteBuffer buffer = ByteBuffer(2, endianness);
|
||||||
|
buffer.put_uint16(value);
|
||||||
|
buffer.flip();
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteBuffer ByteBuffer::wrap(uint32_t value, Endian endianness) {
|
||||||
|
ByteBuffer buffer = ByteBuffer(4, endianness);
|
||||||
|
buffer.put_uint32(value);
|
||||||
|
buffer.flip();
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteBuffer ByteBuffer::wrap(uint64_t value, Endian endianness) {
|
||||||
|
ByteBuffer buffer = ByteBuffer(8, endianness);
|
||||||
|
buffer.put_uint64(value);
|
||||||
|
buffer.flip();
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteBuffer ByteBuffer::wrap(float value, Endian endianness) {
|
||||||
|
ByteBuffer buffer = ByteBuffer(sizeof(float), endianness);
|
||||||
|
buffer.put_float(value);
|
||||||
|
buffer.flip();
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteBuffer ByteBuffer::wrap(double value, Endian endianness) {
|
||||||
|
ByteBuffer buffer = ByteBuffer(sizeof(double), endianness);
|
||||||
|
buffer.put_double(value);
|
||||||
|
buffer.flip();
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
void ByteBuffer::set_limit(size_t limit) {
|
void ByteBuffer::set_limit(size_t limit) {
|
||||||
assert(limit <= this->get_capacity());
|
assert(limit <= this->get_capacity());
|
||||||
|
@ -27,108 +72,102 @@ void ByteBuffer::clear() {
|
||||||
this->limit_ = this->get_capacity();
|
this->limit_ = this->get_capacity();
|
||||||
this->position_ = 0;
|
this->position_ = 0;
|
||||||
}
|
}
|
||||||
uint16_t ByteBuffer::get_uint16() {
|
void ByteBuffer::flip() {
|
||||||
assert(this->get_remaining() >= 2);
|
this->limit_ = this->position_;
|
||||||
uint16_t value;
|
this->position_ = 0;
|
||||||
if (endianness_ == LITTLE) {
|
|
||||||
value = this->data_[this->position_++];
|
|
||||||
value |= this->data_[this->position_++] << 8;
|
|
||||||
} else {
|
|
||||||
value = this->data_[this->position_++] << 8;
|
|
||||||
value |= this->data_[this->position_++];
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ByteBuffer::get_uint32() {
|
/// Getters
|
||||||
assert(this->get_remaining() >= 4);
|
|
||||||
uint32_t value;
|
|
||||||
if (endianness_ == LITTLE) {
|
|
||||||
value = this->data_[this->position_++];
|
|
||||||
value |= this->data_[this->position_++] << 8;
|
|
||||||
value |= this->data_[this->position_++] << 16;
|
|
||||||
value |= this->data_[this->position_++] << 24;
|
|
||||||
} else {
|
|
||||||
value = this->data_[this->position_++] << 24;
|
|
||||||
value |= this->data_[this->position_++] << 16;
|
|
||||||
value |= this->data_[this->position_++] << 8;
|
|
||||||
value |= this->data_[this->position_++];
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
uint32_t ByteBuffer::get_uint24() {
|
|
||||||
assert(this->get_remaining() >= 3);
|
|
||||||
uint32_t value;
|
|
||||||
if (endianness_ == LITTLE) {
|
|
||||||
value = this->data_[this->position_++];
|
|
||||||
value |= this->data_[this->position_++] << 8;
|
|
||||||
value |= this->data_[this->position_++] << 16;
|
|
||||||
} else {
|
|
||||||
value = this->data_[this->position_++] << 16;
|
|
||||||
value |= this->data_[this->position_++] << 8;
|
|
||||||
value |= this->data_[this->position_++];
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
uint32_t ByteBuffer::get_int24() {
|
|
||||||
auto value = this->get_uint24();
|
|
||||||
uint32_t mask = (~(uint32_t) 0) << 23;
|
|
||||||
if ((value & mask) != 0)
|
|
||||||
value |= mask;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
uint8_t ByteBuffer::get_uint8() {
|
uint8_t ByteBuffer::get_uint8() {
|
||||||
assert(this->get_remaining() >= 1);
|
assert(this->get_remaining() >= 1);
|
||||||
return this->data_[this->position_++];
|
return this->data_[this->position_++];
|
||||||
}
|
}
|
||||||
float ByteBuffer::get_float() {
|
uint64_t ByteBuffer::get_uint(size_t length) {
|
||||||
auto value = this->get_uint32();
|
assert(this->get_remaining() >= length);
|
||||||
return *(float *) &value;
|
uint64_t value = 0;
|
||||||
|
if (this->endianness_ == LITTLE) {
|
||||||
|
this->position_ += length;
|
||||||
|
auto index = this->position_;
|
||||||
|
while (length-- != 0) {
|
||||||
|
value <<= 8;
|
||||||
|
value |= this->data_[--index];
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
while (length-- != 0) {
|
||||||
|
value <<= 8;
|
||||||
|
value |= this->data_[this->position_++];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ByteBuffer::get_int24() {
|
||||||
|
auto value = this->get_uint24();
|
||||||
|
uint32_t mask = (~static_cast<uint32_t>(0)) << 23;
|
||||||
|
if ((value & mask) != 0)
|
||||||
|
value |= mask;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
float ByteBuffer::get_float() {
|
||||||
|
assert(this->get_remaining() >= sizeof(float));
|
||||||
|
auto ui_value = this->get_uint32();
|
||||||
|
float value;
|
||||||
|
memcpy(&value, &ui_value, sizeof(float));
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
double ByteBuffer::get_double() {
|
||||||
|
assert(this->get_remaining() >= sizeof(double));
|
||||||
|
auto ui_value = this->get_uint64();
|
||||||
|
double value;
|
||||||
|
memcpy(&value, &ui_value, sizeof(double));
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
std::vector<uint8_t> ByteBuffer::get_vector(size_t length) {
|
||||||
|
assert(this->get_remaining() >= length);
|
||||||
|
auto start = this->data_.begin() + this->position_;
|
||||||
|
this->position_ += length;
|
||||||
|
return {start, start + length};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Putters
|
||||||
void ByteBuffer::put_uint8(uint8_t value) {
|
void ByteBuffer::put_uint8(uint8_t value) {
|
||||||
assert(this->get_remaining() >= 1);
|
assert(this->get_remaining() >= 1);
|
||||||
this->data_[this->position_++] = value;
|
this->data_[this->position_++] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ByteBuffer::put_uint16(uint16_t value) {
|
void ByteBuffer::put_uint(uint64_t value, size_t length) {
|
||||||
assert(this->get_remaining() >= 2);
|
assert(this->get_remaining() >= length);
|
||||||
if (this->endianness_ == LITTLE) {
|
if (this->endianness_ == LITTLE) {
|
||||||
this->data_[this->position_++] = (uint8_t) value;
|
while (length-- != 0) {
|
||||||
this->data_[this->position_++] = (uint8_t) (value >> 8);
|
this->data_[this->position_++] = static_cast<uint8_t>(value);
|
||||||
|
value >>= 8;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this->data_[this->position_++] = (uint8_t) (value >> 8);
|
this->position_ += length;
|
||||||
this->data_[this->position_++] = (uint8_t) value;
|
auto index = this->position_;
|
||||||
|
while (length-- != 0) {
|
||||||
|
this->data_[--index] = static_cast<uint8_t>(value);
|
||||||
|
value >>= 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ByteBuffer::put_uint24(uint32_t value) {
|
|
||||||
assert(this->get_remaining() >= 3);
|
|
||||||
if (this->endianness_ == LITTLE) {
|
|
||||||
this->data_[this->position_++] = (uint8_t) value;
|
|
||||||
this->data_[this->position_++] = (uint8_t) (value >> 8);
|
|
||||||
this->data_[this->position_++] = (uint8_t) (value >> 16);
|
|
||||||
} else {
|
|
||||||
this->data_[this->position_++] = (uint8_t) (value >> 16);
|
|
||||||
this->data_[this->position_++] = (uint8_t) (value >> 8);
|
|
||||||
this->data_[this->position_++] = (uint8_t) value;
|
|
||||||
}
|
}
|
||||||
|
void ByteBuffer::put_float(float value) {
|
||||||
|
static_assert(sizeof(float) == sizeof(uint32_t), "Float sizes other than 32 bit not supported");
|
||||||
|
assert(this->get_remaining() >= sizeof(float));
|
||||||
|
uint32_t ui_value;
|
||||||
|
memcpy(&ui_value, &value, sizeof(float)); // this work-around required to silence compiler warnings
|
||||||
|
this->put_uint32(ui_value);
|
||||||
}
|
}
|
||||||
void ByteBuffer::put_uint32(uint32_t value) {
|
void ByteBuffer::put_double(double value) {
|
||||||
assert(this->get_remaining() >= 4);
|
static_assert(sizeof(double) == sizeof(uint64_t), "Double sizes other than 64 bit not supported");
|
||||||
if (this->endianness_ == LITTLE) {
|
assert(this->get_remaining() >= sizeof(double));
|
||||||
this->data_[this->position_++] = (uint8_t) value;
|
uint64_t ui_value;
|
||||||
this->data_[this->position_++] = (uint8_t) (value >> 8);
|
memcpy(&ui_value, &value, sizeof(double));
|
||||||
this->data_[this->position_++] = (uint8_t) (value >> 16);
|
this->put_uint64(ui_value);
|
||||||
this->data_[this->position_++] = (uint8_t) (value >> 24);
|
|
||||||
} else {
|
|
||||||
this->data_[this->position_++] = (uint8_t) (value >> 24);
|
|
||||||
this->data_[this->position_++] = (uint8_t) (value >> 16);
|
|
||||||
this->data_[this->position_++] = (uint8_t) (value >> 8);
|
|
||||||
this->data_[this->position_++] = (uint8_t) value;
|
|
||||||
}
|
}
|
||||||
}
|
void ByteBuffer::put_vector(const std::vector<uint8_t> &value) {
|
||||||
void ByteBuffer::put_float(float value) { this->put_uint32(*(uint32_t *) &value); }
|
assert(this->get_remaining() >= value.size());
|
||||||
void ByteBuffer::flip() {
|
std::copy(value.begin(), value.end(), this->data_.begin() + this->position_);
|
||||||
this->limit_ = this->position_;
|
this->position_ += value.size();
|
||||||
this->position_ = 0;
|
|
||||||
}
|
}
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
|
@ -15,55 +15,103 @@ enum Endian { LITTLE, BIG };
|
||||||
*
|
*
|
||||||
* There are three variables maintained pointing into the buffer:
|
* There are three variables maintained pointing into the buffer:
|
||||||
*
|
*
|
||||||
* 0 <= position <= limit <= capacity
|
* capacity: the maximum amount of data that can be stored - set on construction and cannot be changed
|
||||||
*
|
|
||||||
* capacity: the maximum amount of data that can be stored
|
|
||||||
* limit: the limit of the data currently available to get or put
|
* limit: the limit of the data currently available to get or put
|
||||||
* position: the current insert or extract position
|
* position: the current insert or extract position
|
||||||
*
|
*
|
||||||
|
* 0 <= position <= limit <= capacity
|
||||||
|
*
|
||||||
* In addition a mark can be set to the current position with mark(). A subsequent call to reset() will restore
|
* In addition a mark can be set to the current position with mark(). A subsequent call to reset() will restore
|
||||||
* the position to the mark.
|
* the position to the mark.
|
||||||
*
|
*
|
||||||
* The buffer can be marked to be little-endian (default) or big-endian. All subsequent operations will use that order.
|
* The buffer can be marked to be little-endian (default) or big-endian. All subsequent operations will use that order.
|
||||||
*
|
*
|
||||||
|
* The flip() operation will reset the position to 0 and limit to the current position. This is useful for reading
|
||||||
|
* data from a buffer after it has been written.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
class ByteBuffer {
|
class ByteBuffer {
|
||||||
public:
|
public:
|
||||||
|
// Default constructor (compatibility with TEMPLATABLE_VALUE)
|
||||||
|
ByteBuffer() : ByteBuffer(std::vector<uint8_t>()) {}
|
||||||
/**
|
/**
|
||||||
* Create a new Bytebuffer with the given capacity
|
* Create a new Bytebuffer with the given capacity
|
||||||
*/
|
*/
|
||||||
static ByteBuffer create(size_t capacity);
|
ByteBuffer(size_t capacity, Endian endianness = LITTLE)
|
||||||
|
: data_(std::vector<uint8_t>(capacity)), endianness_(endianness), limit_(capacity){};
|
||||||
/**
|
/**
|
||||||
* Wrap an existing vector in a Bytebufffer
|
* Wrap an existing vector in a ByteBufffer
|
||||||
*/
|
*/
|
||||||
static ByteBuffer wrap(std::vector<uint8_t> data);
|
static ByteBuffer wrap(std::vector<uint8_t> const &data, Endian endianness = LITTLE);
|
||||||
/**
|
/**
|
||||||
* Wrap an existing array in a Bytebufffer
|
* Wrap an existing array in a ByteBuffer. Note that this will create a copy of the data.
|
||||||
*/
|
*/
|
||||||
static ByteBuffer wrap(uint8_t *ptr, size_t len);
|
static ByteBuffer wrap(const uint8_t *ptr, size_t len, Endian endianness = LITTLE);
|
||||||
|
// Convenience functions to create a ByteBuffer from a value
|
||||||
|
static ByteBuffer wrap(uint8_t value);
|
||||||
|
static ByteBuffer wrap(uint16_t value, Endian endianness = LITTLE);
|
||||||
|
static ByteBuffer wrap(uint32_t value, Endian endianness = LITTLE);
|
||||||
|
static ByteBuffer wrap(uint64_t value, Endian endianness = LITTLE);
|
||||||
|
static ByteBuffer wrap(int8_t value) { return wrap(static_cast<uint8_t>(value)); }
|
||||||
|
static ByteBuffer wrap(int16_t value, Endian endianness = LITTLE) {
|
||||||
|
return wrap(static_cast<uint16_t>(value), endianness);
|
||||||
|
}
|
||||||
|
static ByteBuffer wrap(int32_t value, Endian endianness = LITTLE) {
|
||||||
|
return wrap(static_cast<uint32_t>(value), endianness);
|
||||||
|
}
|
||||||
|
static ByteBuffer wrap(int64_t value, Endian endianness = LITTLE) {
|
||||||
|
return wrap(static_cast<uint64_t>(value), endianness);
|
||||||
|
}
|
||||||
|
static ByteBuffer wrap(float value, Endian endianness = LITTLE);
|
||||||
|
static ByteBuffer wrap(double value, Endian endianness = LITTLE);
|
||||||
|
static ByteBuffer wrap(bool value) { return wrap(static_cast<uint8_t>(value)); }
|
||||||
|
|
||||||
|
// Get an integral value from the buffer, increment position by length
|
||||||
|
uint64_t get_uint(size_t length);
|
||||||
// Get one byte from the buffer, increment position by 1
|
// Get one byte from the buffer, increment position by 1
|
||||||
uint8_t get_uint8();
|
uint8_t get_uint8();
|
||||||
// Get a 16 bit unsigned value, increment by 2
|
// Get a 16 bit unsigned value, increment by 2
|
||||||
uint16_t get_uint16();
|
uint16_t get_uint16() { return static_cast<uint16_t>(this->get_uint(sizeof(uint16_t))); };
|
||||||
// Get a 24 bit unsigned value, increment by 3
|
// Get a 24 bit unsigned value, increment by 3
|
||||||
uint32_t get_uint24();
|
uint32_t get_uint24() { return static_cast<uint32_t>(this->get_uint(3)); };
|
||||||
// Get a 32 bit unsigned value, increment by 4
|
// Get a 32 bit unsigned value, increment by 4
|
||||||
uint32_t get_uint32();
|
uint32_t get_uint32() { return static_cast<uint32_t>(this->get_uint(sizeof(uint32_t))); };
|
||||||
// signed versions of the get functions
|
// Get a 64 bit unsigned value, increment by 8
|
||||||
uint8_t get_int8() { return (int8_t) this->get_uint8(); };
|
uint64_t get_uint64() { return this->get_uint(sizeof(uint64_t)); };
|
||||||
int16_t get_int16() { return (int16_t) this->get_uint16(); }
|
// Signed versions of the get functions
|
||||||
|
uint8_t get_int8() { return static_cast<int8_t>(this->get_uint8()); };
|
||||||
|
int16_t get_int16() { return static_cast<int16_t>(this->get_uint(sizeof(int16_t))); }
|
||||||
uint32_t get_int24();
|
uint32_t get_int24();
|
||||||
int32_t get_int32() { return (int32_t) this->get_uint32(); }
|
int32_t get_int32() { return static_cast<int32_t>(this->get_uint(sizeof(int32_t))); }
|
||||||
|
int64_t get_int64() { return static_cast<int64_t>(this->get_uint(sizeof(int64_t))); }
|
||||||
// Get a float value, increment by 4
|
// Get a float value, increment by 4
|
||||||
float get_float();
|
float get_float();
|
||||||
|
// Get a double value, increment by 8
|
||||||
|
double get_double();
|
||||||
|
// Get a bool value, increment by 1
|
||||||
|
bool get_bool() { return this->get_uint8(); }
|
||||||
|
// Get vector of bytes, increment by length
|
||||||
|
std::vector<uint8_t> get_vector(size_t length);
|
||||||
|
|
||||||
// put values into the buffer, increment the position accordingly
|
// Put values into the buffer, increment the position accordingly
|
||||||
|
// put any integral value, length represents the number of bytes
|
||||||
|
void put_uint(uint64_t value, size_t length);
|
||||||
void put_uint8(uint8_t value);
|
void put_uint8(uint8_t value);
|
||||||
void put_uint16(uint16_t value);
|
void put_uint16(uint16_t value) { this->put_uint(value, sizeof(uint16_t)); }
|
||||||
void put_uint24(uint32_t value);
|
void put_uint24(uint32_t value) { this->put_uint(value, 3); }
|
||||||
void put_uint32(uint32_t value);
|
void put_uint32(uint32_t value) { this->put_uint(value, sizeof(uint32_t)); }
|
||||||
|
void put_uint64(uint64_t value) { this->put_uint(value, sizeof(uint64_t)); }
|
||||||
|
// Signed versions of the put functions
|
||||||
|
void put_int8(int8_t value) { this->put_uint8(static_cast<uint8_t>(value)); }
|
||||||
|
void put_int16(int32_t value) { this->put_uint(static_cast<uint16_t>(value), sizeof(uint16_t)); }
|
||||||
|
void put_int24(int32_t value) { this->put_uint(static_cast<uint32_t>(value), 3); }
|
||||||
|
void put_int32(int32_t value) { this->put_uint(static_cast<uint32_t>(value), sizeof(uint32_t)); }
|
||||||
|
void put_int64(int64_t value) { this->put_uint(static_cast<uint64_t>(value), sizeof(uint64_t)); }
|
||||||
|
// Extra put functions
|
||||||
void put_float(float value);
|
void put_float(float value);
|
||||||
|
void put_double(double value);
|
||||||
|
void put_bool(bool value) { this->put_uint8(value); }
|
||||||
|
void put_vector(const std::vector<uint8_t> &value);
|
||||||
|
|
||||||
inline size_t get_capacity() const { return this->data_.size(); }
|
inline size_t get_capacity() const { return this->data_.size(); }
|
||||||
inline size_t get_position() const { return this->position_; }
|
inline size_t get_position() const { return this->position_; }
|
||||||
|
@ -80,12 +128,12 @@ class ByteBuffer {
|
||||||
// set limit to current position, postition to zero. Used when swapping from write to read operations.
|
// set limit to current position, postition to zero. Used when swapping from write to read operations.
|
||||||
void flip();
|
void flip();
|
||||||
// retrieve a pointer to the underlying data.
|
// retrieve a pointer to the underlying data.
|
||||||
uint8_t *array() { return this->data_.data(); };
|
std::vector<uint8_t> get_data() { return this->data_; };
|
||||||
void rewind() { this->position_ = 0; }
|
void rewind() { this->position_ = 0; }
|
||||||
void reset() { this->position_ = this->mark_; }
|
void reset() { this->position_ = this->mark_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ByteBuffer(std::vector<uint8_t> data) : data_(std::move(data)) { this->limit_ = this->get_capacity(); }
|
ByteBuffer(std::vector<uint8_t> const &data) : data_(data), limit_(data.size()) {}
|
||||||
std::vector<uint8_t> data_;
|
std::vector<uint8_t> data_;
|
||||||
Endian endianness_{LITTLE};
|
Endian endianness_{LITTLE};
|
||||||
size_t position_{0};
|
size_t position_{0};
|
||||||
|
|
|
@ -106,6 +106,8 @@ def storage_should_clean(old: StorageJSON, new: StorageJSON) -> bool:
|
||||||
return True
|
return True
|
||||||
if old.build_path != new.build_path:
|
if old.build_path != new.build_path:
|
||||||
return True
|
return True
|
||||||
|
if old.loaded_integrations != new.loaded_integrations:
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,7 +119,9 @@ def update_storage_json():
|
||||||
return
|
return
|
||||||
|
|
||||||
if storage_should_clean(old, new):
|
if storage_should_clean(old, new):
|
||||||
_LOGGER.info("Core config or version changed, cleaning build files...")
|
_LOGGER.info(
|
||||||
|
"Core config, version or integrations changed, cleaning build files..."
|
||||||
|
)
|
||||||
clean_build()
|
clean_build()
|
||||||
|
|
||||||
new.save(path)
|
new.save(path)
|
||||||
|
|
|
@ -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:
|
||||||
|
@ -379,6 +395,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 +404,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:
|
||||||
|
|
|
@ -220,6 +220,8 @@ switch:
|
||||||
name: inverter0_output_source_priority_solar
|
name: inverter0_output_source_priority_solar
|
||||||
output_source_priority_battery:
|
output_source_priority_battery:
|
||||||
name: inverter0_output_source_priority_battery
|
name: inverter0_output_source_priority_battery
|
||||||
|
output_source_priority_hybrid:
|
||||||
|
name: inverter0_output_source_priority_hybrid
|
||||||
input_voltage_range:
|
input_voltage_range:
|
||||||
name: inverter0_input_voltage_range
|
name: inverter0_input_voltage_range
|
||||||
pv_ok_condition_for_parallel:
|
pv_ok_condition_for_parallel:
|
||||||
|
|
|
@ -220,6 +220,8 @@ switch:
|
||||||
name: inverter0_output_source_priority_solar
|
name: inverter0_output_source_priority_solar
|
||||||
output_source_priority_battery:
|
output_source_priority_battery:
|
||||||
name: inverter0_output_source_priority_battery
|
name: inverter0_output_source_priority_battery
|
||||||
|
output_source_priority_hybrid:
|
||||||
|
name: inverter0_output_source_priority_hybrid
|
||||||
input_voltage_range:
|
input_voltage_range:
|
||||||
name: inverter0_input_voltage_range
|
name: inverter0_input_voltage_range
|
||||||
pv_ok_condition_for_parallel:
|
pv_ok_condition_for_parallel:
|
||||||
|
|
|
@ -220,6 +220,8 @@ switch:
|
||||||
name: inverter0_output_source_priority_solar
|
name: inverter0_output_source_priority_solar
|
||||||
output_source_priority_battery:
|
output_source_priority_battery:
|
||||||
name: inverter0_output_source_priority_battery
|
name: inverter0_output_source_priority_battery
|
||||||
|
output_source_priority_hybrid:
|
||||||
|
name: inverter0_output_source_priority_hybrid
|
||||||
input_voltage_range:
|
input_voltage_range:
|
||||||
name: inverter0_input_voltage_range
|
name: inverter0_input_voltage_range
|
||||||
pv_ok_condition_for_parallel:
|
pv_ok_condition_for_parallel:
|
||||||
|
|
|
@ -220,6 +220,8 @@ switch:
|
||||||
name: inverter0_output_source_priority_solar
|
name: inverter0_output_source_priority_solar
|
||||||
output_source_priority_battery:
|
output_source_priority_battery:
|
||||||
name: inverter0_output_source_priority_battery
|
name: inverter0_output_source_priority_battery
|
||||||
|
output_source_priority_hybrid:
|
||||||
|
name: inverter0_output_source_priority_hybrid
|
||||||
input_voltage_range:
|
input_voltage_range:
|
||||||
name: inverter0_input_voltage_range
|
name: inverter0_input_voltage_range
|
||||||
pv_ok_condition_for_parallel:
|
pv_ok_condition_for_parallel:
|
||||||
|
|
|
@ -220,6 +220,8 @@ switch:
|
||||||
name: inverter0_output_source_priority_solar
|
name: inverter0_output_source_priority_solar
|
||||||
output_source_priority_battery:
|
output_source_priority_battery:
|
||||||
name: inverter0_output_source_priority_battery
|
name: inverter0_output_source_priority_battery
|
||||||
|
output_source_priority_hybrid:
|
||||||
|
name: inverter0_output_source_priority_hybrid
|
||||||
input_voltage_range:
|
input_voltage_range:
|
||||||
name: inverter0_input_voltage_range
|
name: inverter0_input_voltage_range
|
||||||
pv_ok_condition_for_parallel:
|
pv_ok_condition_for_parallel:
|
||||||
|
|
|
@ -220,6 +220,8 @@ switch:
|
||||||
name: inverter0_output_source_priority_solar
|
name: inverter0_output_source_priority_solar
|
||||||
output_source_priority_battery:
|
output_source_priority_battery:
|
||||||
name: inverter0_output_source_priority_battery
|
name: inverter0_output_source_priority_battery
|
||||||
|
output_source_priority_hybrid:
|
||||||
|
name: inverter0_output_source_priority_hybrid
|
||||||
input_voltage_range:
|
input_voltage_range:
|
||||||
name: inverter0_input_voltage_range
|
name: inverter0_input_voltage_range
|
||||||
pv_ok_condition_for_parallel:
|
pv_ok_condition_for_parallel:
|
||||||
|
|
Loading…
Reference in a new issue