diff --git a/README.md b/README.md index 45ecce8..976f9e3 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ A minimum working example for setting up the display. A more complex configurati ```yaml display: - - platform: matrix_display + - platform: hub75_matrix_display id: matrix width: 64 height: 32 @@ -87,20 +87,21 @@ The additional settings are used to set the configuration variables for the wrap - **i2sspeed**(**Optional**): I2SSpeed used for configuring the display. Select one of `HZ_8M`, `HZ_10M`, `HZ_15M`, `HZ_20M`. - **latch_blanking**(**Optional**, int): Latch blanking value used for configuring the display. - **clock_phase**(**Optional**, boolean): Clock phase value used for configuring the display. +- **use_custom_library**(**Optional**, boolean): If set to `true` a custom library must be defined using `platformio_options:lib_deps`. Defaults to `false`. See [this example](custom_library.yaml) for more details. - All other options from [Display](https://esphome.io/components/display/index.html) Note that the default pin configurations are the ones mentioned in the [ESP32-HUB75-MatrixPanel-DMA](https://github.com/mrfaptastic/ESP32-HUB75-MatrixPanel-DMA) library. Some of these pins are used as strapping pins on ESPs. It is recommended to not use these. My panel and the ESP do not work unless I change the R2, G2 and B2 pins. -## Matrix Display Switch +## Switch This switch can be used to turn the display on or off. In it's off state the display is showing a blank screen. - **matrix_id**(**Required**, string): The matrix display entity to which this power switch belongs. - All other options from [Switch](https://esphome.io/components/switch/index.html#config-switch) -## Matrix Display Brightness +## Brightness This number entity can be used to set the display brightness. In combination with a brightness sensor this can used to adaptively change matrix displays brightness. diff --git a/complex_matrix_config.yaml b/complex_matrix_config.yaml index cec7c4d..ff07104 100644 --- a/complex_matrix_config.yaml +++ b/complex_matrix_config.yaml @@ -1,5 +1,5 @@ display: - - platform: matrix_display + - platform: hub75_matrix_display id: matrix width: 64 height: 32 diff --git a/components/matrix_display/__init__.py b/components/hub75_matrix_display/__init__.py similarity index 100% rename from components/matrix_display/__init__.py rename to components/hub75_matrix_display/__init__.py diff --git a/components/matrix_display/display.py b/components/hub75_matrix_display/display.py similarity index 91% rename from components/matrix_display/display.py rename to components/hub75_matrix_display/display.py index a86e7fe..ee9b250 100644 --- a/components/matrix_display/display.py +++ b/components/hub75_matrix_display/display.py @@ -10,7 +10,6 @@ CONF_WIDTH, ) -AUTO_LOAD = ["switch", "matrix_display_switch", "number", "matrix_display_brightness"] MATRIX_ID = "matrix_id" CHAIN_LENGTH = "chain_length" BRIGHTNESS = "brightness" @@ -37,6 +36,8 @@ LATCH_BLANKING = "latch_blanking" CLOCK_PHASE = "clock_phase" +USE_CUSTOM_LIBRARY = "use_custom_library" + matrix_display_ns = cg.esphome_ns.namespace("matrix_display") MatrixDisplay = matrix_display_ns.class_( "MatrixDisplay", cg.PollingComponent, display.DisplayBuffer @@ -65,6 +66,7 @@ cv.GenerateID(): cv.declare_id(MatrixDisplay), cv.Required(CONF_WIDTH): cv.positive_int, cv.Required(CONF_HEIGHT): cv.positive_int, + cv.Optional(USE_CUSTOM_LIBRARY, default=False): cv.boolean, cv.Optional(CHAIN_LENGTH, default=1): cv.positive_int, cv.Optional(BRIGHTNESS, default=128): cv.int_range(min=0, max=255), cv.Optional( @@ -93,6 +95,16 @@ async def to_code(config): + if not config[USE_CUSTOM_LIBRARY]: + cg.add_library("SPI", None) + cg.add_library("Wire", None) + cg.add_library("Adafruit BusIO", None) + cg.add_library("adafruit/Adafruit GFX Library", None) + cg.add_library( + "https://github.com/TillFleisch/ESP32-HUB75-MatrixPanel-DMA#optional_logging", + None, + ) + var = cg.new_Pvariable(config[CONF_ID]) cg.add(var.set_panel_width(config[CONF_WIDTH])) cg.add(var.set_panel_height(config[CONF_HEIGHT])) diff --git a/components/matrix_display/matrix_display.cpp b/components/hub75_matrix_display/matrix_display.cpp similarity index 100% rename from components/matrix_display/matrix_display.cpp rename to components/hub75_matrix_display/matrix_display.cpp diff --git a/components/matrix_display/matrix_display.h b/components/hub75_matrix_display/matrix_display.h similarity index 100% rename from components/matrix_display/matrix_display.h rename to components/hub75_matrix_display/matrix_display.h diff --git a/components/matrix_display_brightness/number.py b/components/hub75_matrix_display/number/__init__.py similarity index 91% rename from components/matrix_display_brightness/number.py rename to components/hub75_matrix_display/number/__init__.py index 4a521d9..230caa8 100644 --- a/components/matrix_display_brightness/number.py +++ b/components/hub75_matrix_display/number/__init__.py @@ -3,9 +3,7 @@ from esphome.components import number from esphome.const import CONF_MODE -from ..matrix_display.display import MATRIX_ID, MatrixDisplay - -AUTO_LOAD = ["number"] +from ..display import MATRIX_ID, MatrixDisplay matrix_display_brightness_ns = cg.esphome_ns.namespace( "matrix_display::matrix_display_brightness" diff --git a/components/matrix_display_brightness/matrix_display_brightness.cpp b/components/hub75_matrix_display/number/matrix_display_brightness.cpp similarity index 100% rename from components/matrix_display_brightness/matrix_display_brightness.cpp rename to components/hub75_matrix_display/number/matrix_display_brightness.cpp diff --git a/components/matrix_display_brightness/matrix_display_brightness.h b/components/hub75_matrix_display/number/matrix_display_brightness.h similarity index 97% rename from components/matrix_display_brightness/matrix_display_brightness.h rename to components/hub75_matrix_display/number/matrix_display_brightness.h index ddd92bd..5ae3e7d 100644 --- a/components/matrix_display_brightness/matrix_display_brightness.h +++ b/components/hub75_matrix_display/number/matrix_display_brightness.h @@ -2,7 +2,7 @@ #include "esphome/core/component.h" #include "esphome/components/number/number.h" -#include "../matrix_display/matrix_display.h" +#include "../matrix_display.h" namespace esphome::matrix_display::matrix_display_brightness { diff --git a/components/matrix_display_switch/switch.py b/components/hub75_matrix_display/switch/__init__.py similarity index 90% rename from components/matrix_display_switch/switch.py rename to components/hub75_matrix_display/switch/__init__.py index 0cfe730..f0a7f8a 100644 --- a/components/matrix_display_switch/switch.py +++ b/components/hub75_matrix_display/switch/__init__.py @@ -3,9 +3,7 @@ from esphome.components import switch from esphome.const import CONF_ID -from ..matrix_display.display import MATRIX_ID, MatrixDisplay - -AUTO_LOAD = ["switch"] +from ..display import MATRIX_ID, MatrixDisplay matrix_display_switch_ns = cg.esphome_ns.namespace( "matrix_display::matrix_display_switch" diff --git a/components/matrix_display_switch/matrix_display_switch.cpp b/components/hub75_matrix_display/switch/matrix_display_switch.cpp similarity index 100% rename from components/matrix_display_switch/matrix_display_switch.cpp rename to components/hub75_matrix_display/switch/matrix_display_switch.cpp diff --git a/components/matrix_display_switch/matrix_display_switch.h b/components/hub75_matrix_display/switch/matrix_display_switch.h similarity index 96% rename from components/matrix_display_switch/matrix_display_switch.h rename to components/hub75_matrix_display/switch/matrix_display_switch.h index 16358cf..ca8d436 100644 --- a/components/matrix_display_switch/matrix_display_switch.h +++ b/components/hub75_matrix_display/switch/matrix_display_switch.h @@ -2,7 +2,7 @@ #include "esphome/core/component.h" #include "esphome/components/switch/switch.h" -#include "../matrix_display/matrix_display.h" +#include "../matrix_display.h" namespace esphome::matrix_display::matrix_display_switch { diff --git a/components/matrix_display_brightness/__init__.py b/components/matrix_display_brightness/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/components/matrix_display_switch/__init__.py b/components/matrix_display_switch/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/custom_library.yaml b/custom_library.yaml new file mode 100644 index 0000000..dde69b1 --- /dev/null +++ b/custom_library.yaml @@ -0,0 +1,16 @@ +esphome: + name: matrix-display + platformio_options: + lib_deps: + - SPI + - Wire + - Adafruit BusIO + - adafruit/Adafruit GFX Library + - https://github.com/TillFleisch/ESP32-HUB75-MatrixPanel-DMA#optional_logging + +display: + - platform: hub75_matrix_display + id: matrix + width: 64 + height: 32 + use_custom_library: true diff --git a/example.yaml b/example.yaml index 85d29fe..49f6c4b 100644 --- a/example.yaml +++ b/example.yaml @@ -1,13 +1,6 @@ esphome: name: matrix-display friendly_name: Matrix Display - platformio_options: - lib_deps: - - SPI - - Wire - - Adafruit BusIO - - adafruit/Adafruit GFX Library - - https://github.com/TillFleisch/ESP32-HUB75-MatrixPanel-DMA#optional_logging external_components: - source: github://TillFleisch/ESPHome-HUB75-MatrixDisplayWrapper@main @@ -24,7 +17,7 @@ font: size: 10 display: - - platform: matrix_display + - platform: hub75_matrix_display id: matrix width: 64 height: 32 @@ -33,12 +26,12 @@ display: it.print(0, 0, id(roboto), "Hello World!"); switch: - - platform: matrix_display_switch + - platform: hub75_matrix_display matrix_id: matrix name: "Power" id: power number: - - platform: matrix_display_brightness + - platform: hub75_matrix_display matrix_id: matrix name: "Brightness" diff --git a/tests/base.yaml b/tests/base.yaml index 41ddbfe..b43851b 100644 --- a/tests/base.yaml +++ b/tests/base.yaml @@ -1,12 +1,5 @@ esphome: name: matrix-display - platformio_options: - lib_deps: - - SPI - - Wire - - Adafruit BusIO - - adafruit/Adafruit GFX Library - - https://github.com/TillFleisch/ESP32-HUB75-MatrixPanel-DMA#optional_logging esp32: board: esp32dev @@ -27,7 +20,7 @@ uart: stop_bits: 2 display: - - platform: matrix_display + - platform: hub75_matrix_display id: matrix width: 64 height: 32 diff --git a/tests/full.yaml b/tests/full.yaml index 0399a49..a73d431 100644 --- a/tests/full.yaml +++ b/tests/full.yaml @@ -1,12 +1,5 @@ esphome: name: matrix-display - platformio_options: - lib_deps: - - SPI - - Wire - - Adafruit BusIO - - adafruit/Adafruit GFX Library - - https://github.com/TillFleisch/ESP32-HUB75-MatrixPanel-DMA#optional_logging esp32: board: esp32dev @@ -27,7 +20,7 @@ uart: stop_bits: 2 display: - - platform: matrix_display + - platform: hub75_matrix_display id: matrix width: 64 height: 32 @@ -41,14 +34,14 @@ display: update_interval: 8 ms switch: - - platform: matrix_display_switch + - platform: hub75_matrix_display matrix_id: matrix name: "Power" id: power restore_mode: RESTORE_DEFAULT_OFF number: - - platform: matrix_display_brightness + - platform: hub75_matrix_display id: brightness matrix_id: matrix name: "Brightness"