Defensive code for Heltec Display (#1296)
Added to Heltec board display code logic to reduce corruption of messages on the display Two piece of defensive code were added - Only display messages to the display when operating on Core 1 ( Default Arduino ESP32 CONFIG_ARDUINO_RUNNING_CORE ) - Only display one character/string at a time In the event of failure, default to Serial output. PS SSD1306 driver similar issues https://github.com/ThingPulse/esp8266-oled-ssd1306/issues/326 https://github.com/ThingPulse/esp8266-oled-ssd1306/issues/352
This commit is contained in:
1 parent
941b1e109f
commit
19d58e01e0
2 files changed
+19
-13
No files matched your search
+13
-12
@@ -32,7 +32,8 @@
|
|||||||
#if defined(ZboardHELTEC)
|
#if defined(ZboardHELTEC)
|
||||||
# include "ArduinoLog.h"
|
# include "ArduinoLog.h"
|
||||||
# include "config_HELTEC.h"
|
# include "config_HELTEC.h"
|
||||||
// # include "heltec.h"
|
|
||||||
|
SemaphoreHandle_t semaphoreOLEDOperation;
|
||||||
|
|
||||||
void logToLCD(bool display) {
|
void logToLCD(bool display) {
|
||||||
display ? Log.begin(LOG_LEVEL_LCD, &Oled) : Log.begin(LOG_LEVEL, &Serial); // Log on LCD following LOG_LEVEL_LCD
|
display ? Log.begin(LOG_LEVEL_LCD, &Oled) : Log.begin(LOG_LEVEL, &Serial); // Log on LCD following LOG_LEVEL_LCD
|
||||||
@@ -125,6 +126,10 @@ OledSerial::OledSerial(int x) {
|
|||||||
|
|
||||||
void OledSerial::begin() {
|
void OledSerial::begin() {
|
||||||
// Heltec.begin(); // User OMG serial support
|
// Heltec.begin(); // User OMG serial support
|
||||||
|
|
||||||
|
semaphoreOLEDOperation = xSemaphoreCreateBinary();
|
||||||
|
xSemaphoreGive(semaphoreOLEDOperation);
|
||||||
|
|
||||||
display->init();
|
display->init();
|
||||||
display->flipScreenVertically();
|
display->flipScreenVertically();
|
||||||
display->setFont(ArialMT_Plain_10);
|
display->setFont(ArialMT_Plain_10);
|
||||||
@@ -157,18 +162,9 @@ void OledSerial::fillScreen(OLEDDISPLAY_COLOR color) {
|
|||||||
display->fillRect(0, 0, OLED_WIDTH, OLED_HEIGHT);
|
display->fillRect(0, 0, OLED_WIDTH, OLED_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t OledSerial::write(uint8_t c) {
|
|
||||||
display->clear();
|
|
||||||
display->setColor(WHITE);
|
|
||||||
display->setFont(ArialMT_Plain_10);
|
|
||||||
|
|
||||||
display->write((char)c);
|
|
||||||
display->drawLogBuffer(0, 0);
|
|
||||||
display->display();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t OledSerial::write(const uint8_t* buffer, size_t size) {
|
size_t OledSerial::write(const uint8_t* buffer, size_t size) {
|
||||||
|
if (xPortGetCoreID() == CONFIG_ARDUINO_RUNNING_CORE) {
|
||||||
|
if (xSemaphoreTake(semaphoreOLEDOperation, pdMS_TO_TICKS(30000)) == pdTRUE) {
|
||||||
display->clear();
|
display->clear();
|
||||||
display->setColor(WHITE);
|
display->setColor(WHITE);
|
||||||
display->setFont(ArialMT_Plain_10);
|
display->setFont(ArialMT_Plain_10);
|
||||||
@@ -178,8 +174,13 @@ size_t OledSerial::write(const uint8_t* buffer, size_t size) {
|
|||||||
}
|
}
|
||||||
display->drawLogBuffer(0, 0);
|
display->drawLogBuffer(0, 0);
|
||||||
display->display();
|
display->display();
|
||||||
|
xSemaphoreGive(semaphoreOLEDOperation);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// Default to Serial output if the display is not available
|
||||||
|
return Serial.write(buffer, size);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Display OpenMQTTGateway logo - borrowed from ZboardM5.ino and tweaked for ssd1306 display ( removed color and tweaked size/location )
|
Display OpenMQTTGateway logo - borrowed from ZboardM5.ino and tweaked for ssd1306 display ( removed color and tweaked size/location )
|
||||||
|
|||||||
@@ -87,7 +87,12 @@ public:
|
|||||||
|
|
||||||
void fillScreen(OLEDDISPLAY_COLOR); // fillScreen display and set color
|
void fillScreen(OLEDDISPLAY_COLOR); // fillScreen display and set color
|
||||||
|
|
||||||
size_t write(uint8_t);
|
// This is a bit of lazy programmer simplifacation for the semapore and core detecting code. Not sure if it is truly space efficient.
|
||||||
|
|
||||||
|
inline size_t write(uint8_t x) {
|
||||||
|
return write(&x, 1);
|
||||||
|
}
|
||||||
|
|
||||||
size_t write(const uint8_t* buffer, size_t size);
|
size_t write(const uint8_t* buffer, size_t size);
|
||||||
inline size_t write(const char* buffer, size_t size) {
|
inline size_t write(const char* buffer, size_t size) {
|
||||||
return write((uint8_t*)buffer, size);
|
return write((uint8_t*)buffer, size);
|
||||||
|
|||||||
Reference in new issue
Block a user