monorkin / esphome_st7565

ESPHome external component for ST7565 displays
Other
6 stars 3 forks source link

DsiplayBuffer error #1

Closed smartroad closed 9 months ago

smartroad commented 12 months ago

Hi, just starting to use your extension but when I compile with the latest esphome I get the error: AttributeError: module 'esphome.components.display' has no attribute 'DisplayBufferRef'. Did you mean: 'DisplayBuffer'? any thoughts?

monorkin commented 12 months ago

Seems like the API has changed and this line has to be updated to align with the API.

I'll take a look tomorrow and see if it's an easy fix. If you have the time you can also give it a whirl and open a PR if you manage to solve it.

Thank you for the issue report.

monorkin commented 11 months ago

Hey @smartroad I don't have a device at hand with which I can test, can you try building your project with this branch fix/rename-display-buffer-ref and report back if it works? It implements all API changes.

It should be as simple as changing source: github://monorkin/esphome_st7565@main to source: github://monorkin/esphome_st7565@fix/rename-display-buffer-ref.

smartroad commented 11 months ago

Hi, sorry for delay, I was away for work. Just tried and get different errors:

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
Dependency Graph
|-- AsyncTCP-esphome @ 1.2.2
|-- WiFi @ 2.0.0
|-- FS @ 2.0.0
|-- Update @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 2.1.0
|-- DNSServer @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- noise-c @ 0.1.4
|-- SPI @ 2.0.0
Compiling .pioenvs/powerdisplay1/src/main.cpp.o
Archiving .pioenvs/powerdisplay1/libe06/libAsyncTCP-esphome.a
Indexing .pioenvs/powerdisplay1/libe06/libAsyncTCP-esphome.a
Archiving .pioenvs/powerdisplay1/lib5b1/libWiFi.a
Indexing .pioenvs/powerdisplay1/lib5b1/libWiFi.a
Archiving .pioenvs/powerdisplay1/lib746/libFS.a
Indexing .pioenvs/powerdisplay1/lib746/libFS.a
Archiving .pioenvs/powerdisplay1/lib4cd/libUpdate.a
Indexing .pioenvs/powerdisplay1/lib4cd/libUpdate.a
src/main.cpp: In function 'void setup()':
src/main.cpp:887:38: error: invalid new-expression of abstract class type 'esphome::st7565::ST7565'
   st7565_st7565 = new st7565::ST7565();
                                      ^
In file included from src/esphome.h:40,
                 from src/main.cpp:3:
src/esphome/components/st7565/st7565.h:12:7: note:   because the following virtual functions are pure within 'esphome::st7565::ST7565':
 class ST7565 : public PollingComponent,
       ^~~~~~
In file included from src/esphome.h:17,
                 from src/main.cpp:3:
src/esphome/components/display/display.h:434:23: note:  'virtual esphome::display::DisplayType esphome::display::Display::get_display_type()'
   virtual DisplayType get_display_type() = 0;
                       ^~~~~~~~~~~~~~~~
src/main.cpp:898:56: error: cannot declare parameter 'it' to be of abstract type 'esphome::display::DisplayBuffer'
   st7565_st7565->set_writer([=](display::DisplayBuffer it) -> void {
                                 ~~~~~~~~~~~~~~~~~~~~~~~^~
In file included from src/esphome.h:18,
                 from src/main.cpp:3:
src/esphome/components/display/display_buffer.h:15:7: note:   because the following virtual functions are pure within 'esphome::display::DisplayBuffer':
 class DisplayBuffer : public Display {
       ^~~~~~~~~~~~~
In file included from src/esphome.h:17,
                 from src/main.cpp:3:
src/esphome/components/display/display.h:434:23: note:  'virtual esphome::display::DisplayType esphome::display::Display::get_display_type()'
   virtual DisplayType get_display_type() = 0;
                       ^~~~~~~~~~~~~~~~
In file included from src/esphome.h:18,
                 from src/main.cpp:3:
src/esphome/components/display/display_buffer.h:25:15: note:    'virtual int esphome::display::DisplayBuffer::get_height_internal()'
   virtual int get_height_internal() = 0;
               ^~~~~~~~~~~~~~~~~~~
src/esphome/components/display/display_buffer.h:26:15: note:    'virtual int esphome::display::DisplayBuffer::get_width_internal()'
   virtual int get_width_internal() = 0;
               ^~~~~~~~~~~~~~~~~~
src/esphome/components/display/display_buffer.h:29:16: note:    'virtual void esphome::display::DisplayBuffer::draw_absolute_pixel_internal(int, int, esphome::Color)'
   virtual void draw_absolute_pixel_internal(int x, int y, Color color) = 0;
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
powerdisplay1.yaml:63:4: error: no matching function for call to 'esphome::st7565::ST7565::set_writer(setup()::<lambda(esphome::display::DisplayBuffer)>)'
In file included from src/esphome.h:17,
                 from src/main.cpp:3:
src/esphome/components/display/display.h:411:8: note: candidate: 'void esphome::display::Display::set_writer(esphome::display::display_writer_t&&)'
   void set_writer(display_writer_t &&writer);
        ^~~~~~~~~~
src/esphome/components/display/display.h:411:8: note:   no known conversion for argument 1 from 'setup()::<lambda(esphome::display::DisplayBuffer)>' to 'esphome::display::display_writer_t&&' {aka 'std::function<void(esphome::display::Display&)>&&'}
Compiling .pioenvs/powerdisplay1/libf52/ESPAsyncWebServer-esphome/WebAuthentication.cpp.o
Compiling .pioenvs/powerdisplay1/libf52/ESPAsyncWebServer-esphome/WebHandlers.cpp.o
Compiling .pioenvs/powerdisplay1/libf52/ESPAsyncWebServer-esphome/WebRequest.cpp.o
Compiling .pioenvs/powerdisplay1/libf52/ESPAsyncWebServer-esphome/WebResponses.cpp.o
Compiling .pioenvs/powerdisplay1/libf52/ESPAsyncWebServer-esphome/WebServer.cpp.o
Compiling .pioenvs/powerdisplay1/libf24/DNSServer/DNSServer.cpp.o
Compiling .pioenvs/powerdisplay1/lib026/ESPmDNS/ESPmDNS.cpp.o
Compiling .pioenvs/powerdisplay1/libbdf/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c.o
Compiling .pioenvs/powerdisplay1/libbdf/libsodium/crypto_core/ed25519/core_ed25519.c.o
Compiling .pioenvs/powerdisplay1/libbdf/libsodium/crypto_core/ed25519/core_ristretto255.c.o
Compiling .pioenvs/powerdisplay1/libbdf/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c.o
*** [.pioenvs/powerdisplay1/src/main.cpp.o] Error 1
smartroad commented 11 months ago

My code if that helps:

esphome:
  name: powerdisplay1

esp32:
  board: esp32dev
  framework:
    type: arduino

external_components:
#  - source: github://monorkin/esphome_st7565@main
   - source: github://monorkin/esphome_st7565@fix/rename-display-buffer-ref
#  - source: ./st7565/components/
#    components: [ st7565 ]

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: KEYHERE

ota:
  password: ""

wifi:
  ssid: "SSID"
  password: "PASSWORD"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Powerdisplay Fallback Hotspot"
    password: "FBPASSWORD"

captive_portal:

font:
  - file: "gfonts://Roboto"
    id: my_font
    size: 20

spi:
  - clk_pin: 22
    mosi_pin: 23
    id: primary_spi_bus

display:
  - platform: st7565
    spi_id: primary_spi_bus
    width: 128
    height: 64
    contrast: 16
    dc_pin:
      number: 17
    cs_pin:
      number: 16
    reset_pin:
      number: 0
    # rotation: 180 # If you mount the display upside down
    lambda: |-
      it.print(0, 0, id(my_font), "ST7565");
      it.print(0, 20, id(my_font), "On ESPHome!");
monorkin commented 11 months ago

Sorry, got caught up in other things.

Can you clear your .esphome filder in the build directory and try again? This seems like a caching error. I'll try to build out a breadboard in the next 2 days to iterate more quickly on this.

drduse commented 10 months ago
INFO ESPHome 2023.11.6
INFO Reading configuration /config/esphome/st7565.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing st7565 (board: esp01_1m; framework: arduino; platform: platformio/espressif8266@3.2.0)
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 1MB Flash
Dependency Graph
|-- ESPAsyncTCP-esphome @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 3.1.0
|-- DNSServer @ 1.1.1
|-- ESP8266WiFi @ 1.0
|-- ESP8266mDNS @ 1.2
|-- noise-c @ 0.1.4
|-- SPI @ 1.0
Compiling .pioenvs/st7565/src/main.cpp.o
Compiling .pioenvs/st7565/libbda/ESPAsyncTCP-esphome/SyncClient.cpp.o
Compiling .pioenvs/st7565/libbda/ESPAsyncTCP-esphome/tcp_axtls.c.o
Archiving .pioenvs/st7565/libbda/libESPAsyncTCP-esphome.a
Compiling .pioenvs/st7565/libaf0/Hash/Hash.cpp.o
In file included from src/main.cpp:34:
src/st7565.h:12:7: error: redefinition of 'class esphome::st7565::ST7565'
   12 | class ST7565 : public PollingComponent,
      |       ^~~~~~
In file included from src/esphome.h:42,
                 from src/main.cpp:3:
src/esphome/components/st7565/st7565.h:12:7: note: previous definition of 'class esphome::st7565::ST7565'
   12 | class ST7565 : public PollingComponent,
      |       ^~~~~~
src/main.cpp: In function 'void setup()':
src/main.cpp:897:38: error: invalid new-expression of abstract class type 'esphome::st7565::ST7565'
  897 |   st7565_st7565 = new st7565::ST7565();
      |                                      ^
In file included from src/esphome.h:42,
                 from src/main.cpp:3:
src/esphome/components/st7565/st7565.h:12:7: note:   because the following virtual functions are pure within 'esphome::st7565::ST7565':
   12 | class ST7565 : public PollingComponent,
      |       ^~~~~~
In file included from src/esphome.h:17,
                 from src/main.cpp:3:
src/esphome/components/display/display.h:434:23: note:     'virtual esphome::display::DisplayType esphome::display::Display::get_display_type()'
  434 |   virtual DisplayType get_display_type() = 0;
      |                       ^~~~~~~~~~~~~~~~
src/main.cpp:907:56: error: cannot declare parameter 'it' to be of abstract type 'esphome::display::DisplayBuffer'
  907 |   st7565_st7565->set_writer([=](display::DisplayBuffer it) -> void {
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~^~
In file included from src/esphome.h:18,
                 from src/main.cpp:3:
src/esphome/components/display/display_buffer.h:15:7: note:   because the following virtual functions are pure within 'esphome::display::DisplayBuffer':
   15 | class DisplayBuffer : public Display {
      |       ^~~~~~~~~~~~~
In file included from src/esphome.h:17,
                 from src/main.cpp:3:
src/esphome/components/display/display.h:434:23: note:     'virtual esphome::display::DisplayType esphome::display::Display::get_display_type()'
  434 |   virtual DisplayType get_display_type() = 0;
      |                       ^~~~~~~~~~~~~~~~
In file included from src/esphome.h:18,
                 from src/main.cpp:3:
src/esphome/components/display/display_buffer.h:25:15: note:     'virtual int esphome::display::DisplayBuffer::get_height_internal()'
   25 |   virtual int get_height_internal() = 0;
      |               ^~~~~~~~~~~~~~~~~~~
src/esphome/components/display/display_buffer.h:26:15: note:     'virtual int esphome::display::DisplayBuffer::get_width_internal()'
   26 |   virtual int get_width_internal() = 0;
      |               ^~~~~~~~~~~~~~~~~~
src/esphome/components/display/display_buffer.h:29:16: note:     'virtual void esphome::display::DisplayBuffer::draw_absolute_pixel_internal(int, int, esphome::Color)'
   29 |   virtual void draw_absolute_pixel_internal(int x, int y, Color color) = 0;
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/config/esphome/st7565.yaml:61:4: error: cannot convert 'setup()::<lambda(esphome::display::DisplayBuffer)>' to 'esphome::display::display_writer_t&&' {aka 'std::function<void(esphome::display::Display&)>&&'}
In file included from src/esphome.h:17,
                 from src/main.cpp:3:
src/esphome/components/display/display.h:411:38: note:   initializing argument 1 of 'void esphome::display::Display::set_writer(esphome::display::display_writer_t&&)'
  411 |   void set_writer(display_writer_t &&writer);
      |                   ~~~~~~~~~~~~~~~~~~~^~~~~~
Archiving .pioenvs/st7565/libaf0/libHash.a
Compiling .pioenvs/st7565/lib67b/ESP8266WiFi/BearSSLHelpers.cpp.o
*** [.pioenvs/st7565/src/main.cpp.o] Error 1
========================== [FAILED] Took 6.35 seconds ==========================
drduse commented 10 months ago
esphome:
  name: st7565
  friendly_name: st7565
  includes: st7565.h

esp8266:
  board: esp01_1m

external_components:
#  - source: github://monorkin/esphome_st7565@main
   - source: github://monorkin/esphome_st7565@fix/rename-display-buffer-ref
#  - source: ./st7565/components/
     components: [ st7565 ]  

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "cshYTcAYS3K/0d9WicPuCzSExU9OYzQZpcpAFSy+Cxg="

ota:
  password: "0ae2c75408ff3585b1d917ee24d597ff"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "St7565 Fallback Hotspot"
    password: "jrDVhRCI244w"

captive_portal:

font:
  - file: "gfonts://Roboto"
    id: my_font
    size: 20

spi:
  clk_pin: GPIO14
  mosi_pin: GPIO13
  id: primary_spi_bus

display:
  - platform: st7565
    spi_id: primary_spi_bus
    width: 128
    height: 64
    contrast: 16
    cs_pin: 
      number: GPIO15
    dc_pin: 
      number: GPIO12
    reset_pin:
      number:  GPIO00
    lambda: |-
      it.print(0, 0, id(my_font), "Hello!");    
monorkin commented 10 months ago

Hi @drduse thank you for the info.

I've just pushed some changes to the fix/rename-display-buffer-ref branch that resolve the compilation error on my machine, and with which I can flash a working version of the library to my device.

Can you try again and report back if it works for you? If it doesn't work at first, try deleting your .esphome folder, or at least this git repo from it, and try again.

monorkin commented 9 months ago

I've verified the fix on a few different projects so I'm closing this issue for now. If anyone still has this problem I'll reopen it. I've also created a 1.0.0 release so that using this project will be more stable in the future - instead of e.g. github://monorkin/esphome_st7565@fix/rename-display-buffer-ref, use github://monorkin/esphome_st7565@1.0.0 to always get the same version of the library.