|
|
@@ -7,6 +7,8 @@ extracted) EpdPanelDescriptor - see panel_213_z98c.h / panel_426_gdeq0426t82.h
|
|
|
tree as reference material for panels not yet ported to this engine.
|
|
|
"""
|
|
|
|
|
|
+import re
|
|
|
+
|
|
|
import esphome.codegen as cg
|
|
|
import esphome.config_validation as cv
|
|
|
from esphome import pins
|
|
|
@@ -48,21 +50,35 @@ CONF_NAME_FONT = "name_font"
|
|
|
gxepd2_ns = cg.esphome_ns.namespace("gxepd2")
|
|
|
GxEPD2Display = gxepd2_ns.class_("GxEPD2Display", display.DisplayBuffer)
|
|
|
|
|
|
-# model name -> C++ descriptor global (EpdPanelDescriptor) declared in the
|
|
|
-# matching panel_*.h header, which gxepd2_display.h includes unconditionally
|
|
|
-# - so any of these names can be selected without extra include wiring here.
|
|
|
+# model name -> (C++ descriptor global declared in the matching panel_*.h
|
|
|
+# header - gxepd2_display.h includes them all, so no extra include wiring here;
|
|
|
+# Good Display part number on the panel's silkscreen).
|
|
|
+#
|
|
|
+# The part number, not the GxEPD2 class name, is the source of truth for the
|
|
|
+# on-screen label (see _panel_label / test_pattern): GxEPD2's older naming
|
|
|
+# style drops the GDEx prefix and the 4-digit size - GxEPD2_213_Z98C is really
|
|
|
+# GDEY0213Z98 - so the class name alone can't reconstruct what's on the tag.
|
|
|
MODELS = {
|
|
|
- "GxEPD2_213_Z98C": "PANEL_213_Z98C",
|
|
|
- "GxEPD2_426_GDEQ0426T82": "PANEL_426_GDEQ0426T82",
|
|
|
- "GxEPD2_583_GDEQ0583T31": "PANEL_583_GDEQ0583T31",
|
|
|
- "GxEPD2_290c_GDEY029F51": "PANEL_290C_GDEY029F51",
|
|
|
- "GxEPD2_579c_GDEY0579F51": "PANEL_579C_GDEY0579F51",
|
|
|
+ "GxEPD2_213_Z98C": ("PANEL_213_Z98C", "GDEY0213Z98"),
|
|
|
+ "GxEPD2_426_GDEQ0426T82": ("PANEL_426_GDEQ0426T82", "GDEQ0426T82"),
|
|
|
+ "GxEPD2_583_GDEQ0583T31": ("PANEL_583_GDEQ0583T31", "GDEQ0583T31"),
|
|
|
+ "GxEPD2_290c_GDEY029F51": ("PANEL_290C_GDEY029F51", "GDEY029F51"),
|
|
|
+ "GxEPD2_579c_GDEY0579F51": ("PANEL_579C_GDEY0579F51", "GDEY0579F51"),
|
|
|
# Debug variant: master half only, as if it were a self-contained
|
|
|
# 396x272 panel - see panel_579c_gdey0579f51_master_only.h. Kept
|
|
|
- # around as a diagnostic tool, not the panel's real mode.
|
|
|
- "GxEPD2_579c_GDEY0579F51_MASTER_ONLY": "PANEL_579C_GDEY0579F51_MASTER_ONLY",
|
|
|
+ # around as a diagnostic tool, not the panel's real mode. Same physical
|
|
|
+ # part as the full panel, so same label.
|
|
|
+ "GxEPD2_579c_GDEY0579F51_MASTER_ONLY": ("PANEL_579C_GDEY0579F51_MASTER_ONLY", "GDEY0579F51"),
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+# Good Display part number -> shelf label: insert a dash after the 4-char GDEx
|
|
|
+# series prefix (GDEQ0583T31 -> GDEQ-0583T31), matching the vendor's own
|
|
|
+# silkscreen. The size stays encoded exactly once, inside the part number.
|
|
|
+# Anything not starting with GDE<letter> is returned untouched.
|
|
|
+def _panel_label(part: str) -> str:
|
|
|
+ return re.sub(r"^(GDE[A-Z])", r"\1-", part)
|
|
|
+
|
|
|
CONFIG_SCHEMA = cv.All(
|
|
|
display.FULL_DISPLAY_SCHEMA.extend(
|
|
|
{
|
|
|
@@ -93,7 +109,8 @@ CONFIG_SCHEMA = cv.All(
|
|
|
async def to_code(config: ConfigType) -> None:
|
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
|
|
|
|
|
- cg.add(var.set_descriptor(cg.RawExpression(f"&esphome::gxepd2::{MODELS[config[CONF_MODEL]]}")))
|
|
|
+ descriptor, part_number = MODELS[config[CONF_MODEL]]
|
|
|
+ cg.add(var.set_descriptor(cg.RawExpression(f"&esphome::gxepd2::{descriptor}")))
|
|
|
cg.add(var.set_cs_pin(await cg.gpio_pin_expression(config[CONF_CS_PIN])))
|
|
|
cg.add(var.set_dc_pin(await cg.gpio_pin_expression(config[CONF_DC_PIN])))
|
|
|
if reset_pin := config.get(CONF_RESET_PIN):
|
|
|
@@ -108,10 +125,10 @@ async def to_code(config: ConfigType) -> None:
|
|
|
# will compute it from the (aliased) model. An explicit invert_mono wins.
|
|
|
cg.add(var.set_invert_mono(config.get(CONF_INVERT_MONO, False)))
|
|
|
|
|
|
- # Panel label for test_pattern(): the model trailer only (everything
|
|
|
- # after the GxEPD2_<size> prefix, e.g. GxEPD2_583_GDEQ0583T31 ->
|
|
|
- # GDEQ0583T31), so a tested panel shows what it is, not the C++ class id.
|
|
|
- cg.add(var.set_model_name(config[CONF_MODEL].split("_", 2)[-1]))
|
|
|
+ # Panel label for test_pattern(): the Good Display part number in the
|
|
|
+ # vendor's dashed silkscreen form (GDEQ-0583T31), so a tested panel shows
|
|
|
+ # what it is on the shelf, not the GxEPD2 C++ class id.
|
|
|
+ cg.add(var.set_model_name(_panel_label(part_number)))
|
|
|
if name_font := config.get(CONF_NAME_FONT):
|
|
|
cg.add(var.set_name_font(await cg.get_variable(name_font)))
|
|
|
|