Procházet zdrojové kódy

Actually wire up the configured lambda - it was never running

Root cause, found via a buffer-content histogram: every byte of both
planes came out 0x00 on every single hardware run, regardless of any
protocol-level change (busy timeout, display-update-control bytes,
red-plane bit convention, power-on/off bracketing, SPI clock - none of
it mattered, because none of it touches whether the lambda runs).

display.register_display() only wires up a `pages:` block automatically;
a bare top-level `lambda:` - what our CONFIG_SCHEMA actually validates -
has to be processed and attached via set_writer() by the platform's own
to_code(), the same way every other display component does it (see
epaper_spi's display.py). Ours never did this, so do_update_() only ever
ran auto_clear's default fill(COLOR_OFF) - solid black - and the
configured lambda was silently never invoked at all.
ZiB před 1 měsícem
rodič
revize
9d80ac067b
1 změnil soubory, kde provedl 22 přidání a 1 odebrání
  1. 22 1
      components/gxepd2/display.py

+ 22 - 1
components/gxepd2/display.py

@@ -11,7 +11,16 @@ import esphome.codegen as cg
 import esphome.config_validation as cv
 from esphome import pins
 from esphome.components import display, spi
-from esphome.const import CONF_BUSY_PIN, CONF_CS_PIN, CONF_DC_PIN, CONF_ID, CONF_RESET_PIN, CONF_SPI_ID, Framework
+from esphome.const import (
+    CONF_BUSY_PIN,
+    CONF_CS_PIN,
+    CONF_DC_PIN,
+    CONF_ID,
+    CONF_LAMBDA,
+    CONF_RESET_PIN,
+    CONF_SPI_ID,
+    Framework,
+)
 from esphome.types import ConfigType
 
 CODEOWNERS = ["@zib"]
@@ -48,4 +57,16 @@ async def to_code(config: ConfigType) -> None:
     spi_parent = await cg.get_variable(config[CONF_SPI_ID])
     cg.add(var.set_spi_parent(spi_parent))
 
+    # display.register_display() only wires up `pages:` - a bare top-level
+    # `lambda:` (what our CONFIG_SCHEMA actually supports) has to be
+    # processed and attached via set_writer() by the platform itself, same
+    # as every other display component's to_code() (see e.g. epaper_spi's
+    # display.py). Missing this meant the configured lambda never ran at
+    # all - the only thing ever drawn was auto_clear's default
+    # fill(COLOR_OFF), which is why every real-hardware run came out solid
+    # black regardless of any protocol-level change.
+    if CONF_LAMBDA in config:
+        lambda_ = await cg.process_lambda(config[CONF_LAMBDA], [(display.DisplayRef, "it")], return_type=cg.void)
+        cg.add(var.set_writer(lambda_))
+
     await display.register_display(var, config)