HelTecAutomation / Heltec_ESP32

Arduino library for Heltec ESP32 (or ESP32+LoRa) based boards
Other
581 stars 219 forks source link

Use the Heltec display with SSD1106 classical notation? #69

Open rin67630 opened 2 years ago

rin67630 commented 2 years ago

The display uses the Heltec library

include "heltec.h"

is instantiated with Heltec.begin(true /DisplayEnable Enable/, false /LoRa Disable/, true /Serial Enable/); and use the functions as Heltec.display->drawString(10, 0, "| Set");

Do I have a way to use the the classical notation display.drawString(10, 0, "| Set"); with this library?

I have a lot of code already written and need to use it with many boards If I must use the Heltec library, then at least with the regular notation.

I just want to swap the libraries and eventually the instantiations with

ifdef directives.

but keep the display instructions unchanged.

Thank you for your help.

MURPHYENGINEERING commented 2 years ago

You need to write the following in the .cpp files where you use display:

#include "heltec.h"
SSD1306Wire& display = *(Heltec.display);

This works because Heltec.display is defined in the Heltec_ESP32 constructor: https://github.com/HelTecAutomation/Heltec_ESP32/blob/e17ad84ccf4964718a62ec1c17d891a096876b9f/src/heltec.cpp#L10 and Heltec is a static global declared in the header: https://github.com/HelTecAutomation/Heltec_ESP32/blob/e17ad84ccf4964718a62ec1c17d891a096876b9f/src/heltec.h#L40

so the pointer is guaranteed to be initialized before you capture the reference.