Просмотр исходного кода

test_pattern: take the label font as an optional arg

test_pattern(font=nullptr) instead of a name_font config option. Pass a font
to label the panel with its model - id(disp).test_pattern(id(font)) - or call
test_pattern() with no arg for an unlabelled pattern and no font needed in the
config. Drops the name_font display option and the set_name_font/name_font_
plumbing; set_model_name stays (the label string still comes from model:).
ZiB 3 недель назад
Родитель
Сommit
42beb05ece

+ 1 - 9
components/gxepd2/display.py

@@ -12,7 +12,7 @@ import re
 import esphome.codegen as cg
 import esphome.codegen as cg
 import esphome.config_validation as cv
 import esphome.config_validation as cv
 from esphome import pins
 from esphome import pins
-from esphome.components import display, font, spi
+from esphome.components import display, spi
 from esphome.const import (
 from esphome.const import (
     CONF_BUSY_PIN,
     CONF_BUSY_PIN,
     CONF_CS_PIN,
     CONF_CS_PIN,
@@ -42,11 +42,6 @@ DEPENDENCIES = ["spi"]
 # No effect on 2bpp/4bpp packed panels - there the palette maps literal RGB.
 # No effect on 2bpp/4bpp packed panels - there the palette maps literal RGB.
 CONF_INVERT_MONO = "invert_mono"
 CONF_INVERT_MONO = "invert_mono"
 
 
-# Optional font for the on-screen panel label test_pattern() draws (the model
-# trailer, e.g. "GDEQ0583T31"). A normal ESPHome font:, so the builder can
-# pull one from gfonts:// - no font, no label. See GxEPD2Display::test_pattern.
-CONF_NAME_FONT = "name_font"
-
 gxepd2_ns = cg.esphome_ns.namespace("gxepd2")
 gxepd2_ns = cg.esphome_ns.namespace("gxepd2")
 GxEPD2Display = gxepd2_ns.class_("GxEPD2Display", display.DisplayBuffer)
 GxEPD2Display = gxepd2_ns.class_("GxEPD2Display", display.DisplayBuffer)
 
 
@@ -97,7 +92,6 @@ CONFIG_SCHEMA = cv.All(
             # to_code() (just False today; true for a waveshare alias once that
             # to_code() (just False today; true for a waveshare alias once that
             # lands), while an explicit value always wins.
             # lands), while an explicit value always wins.
             cv.Optional(CONF_INVERT_MONO): cv.boolean,
             cv.Optional(CONF_INVERT_MONO): cv.boolean,
-            cv.Optional(CONF_NAME_FONT): cv.use_id(font.Font),
         }
         }
     ),
     ),
     # IDF-first, but the runtime C++ uses only framework-portable ESPHome
     # IDF-first, but the runtime C++ uses only framework-portable ESPHome
@@ -133,8 +127,6 @@ async def to_code(config: ConfigType) -> None:
     # vendor's dashed silkscreen form (GDEQ-0583T31), so a tested panel shows
     # vendor's dashed silkscreen form (GDEQ-0583T31), so a tested panel shows
     # what it is on the shelf, not the GxEPD2 C++ class id.
     # what it is on the shelf, not the GxEPD2 C++ class id.
     cg.add(var.set_model_name(_panel_label(part_number)))
     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)))
 
 
     # display.register_display() only wires up `pages:` - a bare top-level
     # display.register_display() only wires up `pages:` - a bare top-level
     # `lambda:` (what our CONFIG_SCHEMA actually supports) has to be
     # `lambda:` (what our CONFIG_SCHEMA actually supports) has to be

+ 16 - 19
components/gxepd2/gxepd2_display.h

@@ -33,23 +33,23 @@ class GxEPD2Display : public display::DisplayBuffer {
   void set_spi_parent(spi::SPIComponent *parent) { this->spi_.set_spi_parent(parent); }
   void set_spi_parent(spi::SPIComponent *parent) { this->spi_.set_spi_parent(parent); }
   void set_descriptor(const EpdPanelDescriptor *desc) { this->desc_ = desc; }
   void set_descriptor(const EpdPanelDescriptor *desc) { this->desc_ = desc; }
   void set_invert_mono(bool invert) { this->invert_mono_ = invert; }
   void set_invert_mono(bool invert) { this->invert_mono_ = invert; }
-  // Model trailer (e.g. "GDEQ0583T31", not the full "GxEPD2_583_..." id) and
-  // an optional font, both for test_pattern()'s on-screen panel label. Set
-  // from display.py: the name is derived from model:, the font is a normal
-  // ESPHome font: the builder can pull from gfonts://. See test_pattern().
+  // The short panel label (e.g. "GDEQ0583T31") test_pattern() can print,
+  // derived from model: in display.py.
   void set_model_name(const char *name) { this->model_name_ = name; }
   void set_model_name(const char *name) { this->model_name_ = name; }
-  void set_name_font(display::BaseFont *font) { this->name_font_ = font; }
 
 
   // Bench visual-check pattern, bit-depth aware. Everything scales to what
   // Bench visual-check pattern, bit-depth aware. Everything scales to what
   // THIS panel can actually show (see test_colors_): the color-bar count,
   // THIS panel can actually show (see test_colors_): the color-bar count,
   // the ladder color cycle and the corner markers all follow the panel's
   // the ladder color cycle and the corner markers all follow the panel's
   // real color set instead of a hardcoded 4, so the drawn pattern doubles as
   // real color set instead of a hardcoded 4, so the drawn pattern doubles as
-  // a statement of what the driver expects of the panel. Adds a dithered
-  // grey ramp (so a 1bpp panel shows a graded sweep, not just two flat
-  // blocks) and, when a name font is set and the panel can spare the room, a
-  // model-trailer label so a tested panel says what it is on the shelf.
-  // Call it from the display lambda: `id(<display_id>).test_pattern();`.
-  void test_pattern() {
+  // a statement of what the driver expects of the panel. Adds a dithered grey
+  // ramp so a 1bpp panel shows a graded sweep, not just two flat blocks.
+  //
+  // Pass a font to label the panel with its model (and the panel can spare the
+  // room); pass nothing to skip the label - handy when you just want a quick
+  // pattern without defining a font. From the display lambda:
+  //   id(<display_id>).test_pattern();                 // no label
+  //   id(<display_id>).test_pattern(id(<font_id>));    // labelled
+  void test_pattern(display::BaseFont *font = nullptr) {
     const int w = this->get_width();
     const int w = this->get_width();
     const int h = this->get_height();
     const int h = this->get_height();
     Color colors[8];
     Color colors[8];
@@ -64,17 +64,15 @@ class GxEPD2Display : public display::DisplayBuffer {
     const int iw = w - 2 * border;
     const int iw = w - 2 * border;
     int ih = h - 2 * border;
     int ih = h - 2 * border;
 
 
-    // Name band, above every test zone. Drawn only when a font is set and
+    // Name band, above every test zone. Drawn only when a font was passed and
     // the panel is tall enough to give it a fifth of the interior without
     // the panel is tall enough to give it a fifth of the interior without
-    // crowding the zones below - the "skip the name on panels too short to
-    // spare ~10px above the bar" rule, sized to the actual font.
-    if (this->name_font_ != nullptr && this->model_name_ != nullptr && this->model_name_[0] != '\0') {
+    // crowding the zones below.
+    if (font != nullptr && this->model_name_ != nullptr && this->model_name_[0] != '\0') {
       int tw, xoff, baseline, th;
       int tw, xoff, baseline, th;
-      this->name_font_->measure(this->model_name_, &tw, &xoff, &baseline, &th);
+      font->measure(this->model_name_, &tw, &xoff, &baseline, &th);
       const int band = th + 4;
       const int band = th + 4;
       if (band <= ih / 5) {
       if (band <= ih / 5) {
-        this->print(w / 2, y0 + band / 2, this->name_font_, Color(0x00, 0x00, 0x00),
-                    display::TextAlign::CENTER, this->model_name_);
+        this->print(w / 2, y0 + band / 2, font, Color(0x00, 0x00, 0x00), display::TextAlign::CENTER, this->model_name_);
         y0 += band;
         y0 += band;
         ih -= band;
         ih -= band;
       }
       }
@@ -352,7 +350,6 @@ class GxEPD2Display : public display::DisplayBuffer {
 
 
   const EpdPanelDescriptor *desc_{nullptr};
   const EpdPanelDescriptor *desc_{nullptr};
   const char *model_name_{nullptr};
   const char *model_name_{nullptr};
-  display::BaseFont *name_font_{nullptr};
   GPIOPin *cs_{nullptr};
   GPIOPin *cs_{nullptr};
   GPIOPin *dc_{nullptr};
   GPIOPin *dc_{nullptr};
   GPIOPin *rst_{nullptr};
   GPIOPin *rst_{nullptr};

+ 5 - 7
tests/test_pattern_bar_ladder_diagonal.esp32-idf.yaml

@@ -40,12 +40,10 @@ display:
     dc_pin: 17
     dc_pin: 17
     reset_pin: 16
     reset_pin: 16
     busy_pin: 4
     busy_pin: 4
-    name_font: panel_label_font
     update_interval: 60s
     update_interval: 60s
-    # The whole pattern now lives in GxEPD2Display::test_pattern() (C++), so
-    # it can read this panel's descriptor directly and scale the bar count,
-    # ladder cycle and corner markers to the colors it can actually show -
-    # the lambda just invokes it. See gxepd2_display.h for the zone rationale
-    # that used to live in this block.
+    # The pattern lives in GxEPD2Display::test_pattern() (C++) so it can read
+    # the descriptor and scale to the panel's real colors. Pass a font to label
+    # the panel with its model; omit it (test_pattern()) for an unlabelled
+    # pattern with no font needed in the config.
     lambda: |-
     lambda: |-
-      id(gxepd2_test).test_pattern();
+      id(gxepd2_test).test_pattern(id(panel_label_font));