Fixed LED display driver that enables ESP32 as controller.

This commit is contained in:
Jens Noack 2020-10-17 23:06:55 +02:00
parent 2c44f8b873
commit b0fdd05bf2
7 changed files with 93 additions and 68 deletions

View file

@ -17,3 +17,5 @@ lib_deps =
SPI SPI
adafruit/Adafruit GFX Library@^1.10.1 adafruit/Adafruit GFX Library@^1.10.1
adafruit/Adafruit BusIO@1.4.1 adafruit/Adafruit BusIO@1.4.1
makuna/NeoPixelBus@^2.6.0
aligator/NeoPixelBusGfx@^1.1.0

View file

@ -7,13 +7,47 @@
#include <Adafruit_NeoPixel.h> #include <Adafruit_NeoPixel.h>
#include <EepromManager.h> #include <EepromManager.h>
#include "esp_task_wdt.h" #include "esp_task_wdt.h"
#include <NeoPixelBrightnessBusGfx.h>
#include <NeoPixelBrightnessBus.h>
// function for updater task on core 0
void updateDisplayGlobal(void* object);
//extern LedDisplayController *ledDisplayControllerGlobal;
class LedDisplayController class LedDisplayController
{ {
public: public:
explicit LedDisplayController(Adafruit_NeoMatrix *matrix); template<typename T_COLOR_FEATURE, typename T_METHOD>
explicit LedDisplayController(NeoPixelBrightnessBusGfx<T_COLOR_FEATURE, T_METHOD> *matrix )
{
this->eepromUnit = nullptr;
//ledDisplayControllerGlobal = this;
this->loadTextSets();
this->matrix = matrix;
this->matrix->Begin();
//this->matrix->setRemapFunction(&remap);
this->matrix->setTextWrap(false);
this->matrix->SetBrightness(40);
text_curr_nr = 0;
text_set_starttime = 0;
text_pass = 0;
textpixel = 0;
disp_brightness = 5;
disp_show = false;
this->disp_init();
// create updater task
xTaskCreatePinnedToCore(updateDisplayGlobal, "DisplayUpdateTask", 10000, this, 1, &displayUpdateTask, 0);
} ;
~LedDisplayController(); ~LedDisplayController();
//typedef uint16_t (*remapfn)(uint16_t, uint16_t);
enum text_align_t enum text_align_t
{ {
AlignLeft, AlignLeft,
@ -63,7 +97,7 @@ public:
private: private:
// matrix objects // matrix objects
TaskHandle_t displayUpdateTask; TaskHandle_t displayUpdateTask;
Adafruit_NeoMatrix *matrix; NeoPixelBrightnessBusGfx<NeoGrbFeature, Neo800KbpsMethod> *matrix;
// matrix variables // matrix variables
uint16_t text_curr_nr; uint16_t text_curr_nr;
@ -76,6 +110,7 @@ private:
bool disp_show; bool disp_show;
// matrix control // matrix control
//uint16_t remap(uint16_t x, uint16_t y);
void disp_init(); void disp_init();
void disp_start_set(); void disp_start_set();
void disp_scroll_text(); void disp_scroll_text();
@ -102,7 +137,7 @@ private:
} sets_t; } sets_t;
// storage variables // storage variables
const text_set_t defaultTextSet {"", false, 0, "", AlignCenter, false, 0, 0}; const text_set_t defaultTextSet {"Hallo", true, 1000, "", AlignCenter, false, 0, 0};
sets_t text_sets; sets_t text_sets;
// storage control // storage control
@ -112,8 +147,6 @@ private:
bool loadTextSets(); bool loadTextSets();
}; };
// function for updater task on core 0
void updateDisplayGlobal(void *);
extern LedDisplayController *ledDisplayControllerGlobal;
#endif // LED_DISPLAY_CONTROLLER #endif // LED_DISPLAY_CONTROLLER

View file

@ -8,11 +8,32 @@
#include "BluetoothLeUartServer.h" #include "BluetoothLeUartServer.h"
#include "LedDisplayController.h" #include "LedDisplayController.h"
class OmobiLedDisplay : protected BluetoothLeUartServerCallbacks class OmobiLedDisplay : protected BluetoothLeUartServerCallbacks
{ {
public: public:
explicit OmobiLedDisplay(String deviceName, Adafruit_NeoMatrix *ledDisplayMatrix); template<typename T_COLOR_FEATURE, typename T_METHOD>
explicit OmobiLedDisplay(String deviceName, NeoPixelBrightnessBusGfx<T_COLOR_FEATURE, T_METHOD> *ledDisplayMatrix)
{
this->lastKeepAlive = -1;
this->sessionAuthorized = false;
// init eeprom manager
this->eepromManager = new EepromManager();
// init led display controller
this->ledDisplayController = new LedDisplayController(ledDisplayMatrix);
this->ledDisplayController->registerEepromUnit(this->eepromManager);
// init ble server
this->bleServer = new BluetoothLeUartServer("Omobi Display", "92fecb20-1406-426a-afa5-cd5c1f306462", "92fecb21-1406-426a-afa5-cd5c1f306462", "92fecb22-1406-426a-afa5-cd5c1f306462");
this->bleServer->setCallbacks(this);
this->eepromUnit = this->eepromManager->registerEempromUnit(sizeof(DisplayProperties));
this->loadProperties();
};
// befriend for callbacks // befriend for callbacks
friend class BluetoothLeUartServer; friend class BluetoothLeUartServer;

View file

@ -22,5 +22,7 @@ lib_deps =
adafruit/Adafruit NeoPixel@^1.6.0 adafruit/Adafruit NeoPixel@^1.6.0
adafruit/Adafruit NeoMatrix@^1.1.5 adafruit/Adafruit NeoMatrix@^1.1.5
bblanchon/ArduinoJson@^6.16.1 bblanchon/ArduinoJson@^6.16.1
makuna/NeoPixelBus
aligator/NeoPixelBusGfx@^1.1.0
monitor_filters = esp32_exception_decoder monitor_filters = esp32_exception_decoder
monitor_speed = 115200 monitor_speed = 115200

View file

@ -2,29 +2,7 @@
LedDisplayController *ledDisplayControllerGlobal = nullptr; LedDisplayController *ledDisplayControllerGlobal = nullptr;
LedDisplayController::LedDisplayController(Adafruit_NeoMatrix *matrix)
{
this->eepromUnit = nullptr;
ledDisplayControllerGlobal = this;
this->loadTextSets();
this->matrix = matrix;
this->matrix->begin();
this->matrix->setTextWrap(false);
this->matrix->setBrightness(40);
text_curr_nr = 0;
text_set_starttime = 0;
text_pass = 0;
textpixel = 0;
disp_brightness = 5;
disp_show = false;
this->disp_init();
// create updater task
xTaskCreatePinnedToCore(updateDisplayGlobal, "DisplayUpdateTask", 10000, NULL, 1, &displayUpdateTask, 0);
}
// -------------------- // --------------------
// - Public functions - // - Public functions -
@ -108,6 +86,7 @@ void LedDisplayController::disp_start_set()
((text_sets.sets[text_curr_nr].scroll == true) && (text_sets.sets[text_curr_nr].scrollCount > 0) && (text_pass >= text_sets.sets[text_curr_nr].scrollCount)) || ((text_sets.sets[text_curr_nr].scroll == true) && (text_sets.sets[text_curr_nr].scrollCount > 0) && (text_pass >= text_sets.sets[text_curr_nr].scrollCount)) ||
(((text_sets.sets[text_curr_nr].scrollCount == 0) || text_sets.sets[text_curr_nr].scroll == false) && (text_sets.sets[text_curr_nr].runtime == 0) && ((millis() - text_set_starttime) >= 10000))) (((text_sets.sets[text_curr_nr].scrollCount == 0) || text_sets.sets[text_curr_nr].scroll == false) && (text_sets.sets[text_curr_nr].runtime == 0) && ((millis() - text_set_starttime) >= 10000)))
{ {
//Serial.printf("[%lu] Meet start set condition. Curr set is %d. \n", millis(), text_curr_nr); //Serial.printf("[%lu] Meet start set condition. Curr set is %d. \n", millis(), text_curr_nr);
if (0 < text_set_starttime || text_sets.sets[text_curr_nr].text == '\0' || text_sets.sets[text_curr_nr].active == false) if (0 < text_set_starttime || text_sets.sets[text_curr_nr].text == '\0' || text_sets.sets[text_curr_nr].active == false)
text_curr_nr++; text_curr_nr++;
@ -163,9 +142,9 @@ void LedDisplayController::show_matrix(const char *text, int pos, const char *co
this->matrix->setTextColor(this->colorFromHex(String(color))); this->matrix->setTextColor(this->colorFromHex(String(color)));
this->matrix->setCursor(pos, 0); this->matrix->setCursor(pos, 0);
this->matrix->print(text); this->matrix->print(text);
portDISABLE_INTERRUPTS(); //portDISABLE_INTERRUPTS();
this->matrix->show(); this->matrix->Show();
portENABLE_INTERRUPTS(); //portENABLE_INTERRUPTS();
} }
uint16_t LedDisplayController::colorFromHex(String hex) uint16_t LedDisplayController::colorFromHex(String hex)
@ -198,7 +177,7 @@ LedDisplayController::GetSetTextSetParameterExitCode LedDisplayController::getSe
else if (strcmp(this->text_sets.valid, "OK") != 0) else if (strcmp(this->text_sets.valid, "OK") != 0)
return InternalError; return InternalError;
text_set_t *currentTextSet = &this->text_sets.sets[index]; text_set_t* currentTextSet = &this->text_sets.sets[index];
String returnValue = ""; String returnValue = "";
switch (parameter) switch (parameter)
@ -336,7 +315,7 @@ bool LedDisplayController::loadTextSets()
if (strcmp(buf.valid, "OK") == 0) if (strcmp(buf.valid, "OK") == 0)
{ {
memcpy(&text_sets, &buf, sizeof(sets_t)); memcpy(&text_sets, &buf, sizeof(sets_t));
Serial.println("OK"); Serial.printf("OK: '%s\n", text_sets.sets[0].text);
return true; return true;
} }
else else
@ -359,12 +338,12 @@ bool LedDisplayController::loadTextSets()
// - Extern - // - Extern -
// ---------- // ----------
void updateDisplayGlobal(void *) void updateDisplayGlobal(void* object)
{ {
for (;;) for (;;)
{ {
esp_task_wdt_reset(); esp_task_wdt_reset();
delay(1); delay(1);
ledDisplayControllerGlobal->loop(); ((LedDisplayController*)(object))->loop();
} }
} }

View file

@ -1,24 +1,7 @@
#include "OmobiLedDisplay.h" #include "OmobiLedDisplay.h"
OmobiLedDisplay::OmobiLedDisplay(String deviceName, Adafruit_NeoMatrix *ledDisplayMatrix) //OmobiLedDisplay::OmobiLedDisplay(String deviceName, Adafruit_NeoMatrix *ledDisplayMatrix)
{
this->lastKeepAlive = -1;
this->sessionAuthorized = false;
// init eeprom manager
this->eepromManager = new EepromManager();
// init led display controller
this->ledDisplayController = new LedDisplayController(ledDisplayMatrix);
this->ledDisplayController->registerEepromUnit(this->eepromManager);
// init ble server
this->bleServer = new BluetoothLeUartServer("Omobi Display", "92fecb20-1406-426a-afa5-cd5c1f306462", "92fecb21-1406-426a-afa5-cd5c1f306462", "92fecb22-1406-426a-afa5-cd5c1f306462");
this->bleServer->setCallbacks(this);
this->eepromUnit = this->eepromManager->registerEempromUnit(sizeof(DisplayProperties));
this->loadProperties();
}
void OmobiLedDisplay::loop() void OmobiLedDisplay::loop()
{ {

View file

@ -1,27 +1,32 @@
#include <Arduino.h> #include <Arduino.h>
#include "OmobiLedDisplay.h" #include "OmobiLedDisplay.h"
#define PIN 4 #define MATRIX_PIN 4
#define TILE_PIXEL_ROWS 8
#define TILE_PIXEL_COLS 8
#define MATRIX_TILES_ROW 1
#define MATRIX_TILES_COL 2
#define MATRIX_PIXEL_WIDTH TILE_PIXEL_COLS*MATRIX_TILES_COL
#define MATRIX_PIXEL_HEIGHT TILE_PIXEL_ROWS*MATRIX_TILES_ROW
OmobiLedDisplay *display; OmobiLedDisplay *display;
NeoPixelBrightnessBusGfx<NeoGrbFeature, Neo800KbpsMethod> *displayMatrix = new NeoPixelBrightnessBusGfx<NeoGrbFeature, Neo800KbpsMethod>(MATRIX_PIXEL_WIDTH, MATRIX_PIXEL_HEIGHT, MATRIX_PIN);
NeoTiles <RowMajorLayout, RowMajorLayout> tiles(TILE_PIXEL_COLS, TILE_PIXEL_ROWS, MATRIX_TILES_COL,MATRIX_TILES_ROW);
// use a remap function to remap based on the topology, tile or mosaik
// this function is passed as remap function to the matrix
uint16_t remap(uint16_t x, uint16_t y) {
return tiles.Map(x, y);
}
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
Serial.printf("Los\n"); Serial.printf("Los\n");
Adafruit_NeoMatrix *displayMatrix = new Adafruit_NeoMatrix(
8,
8,
1,
1,
PIN,
NEO_TILE_TOP + NEO_TILE_LEFT + NEO_TILE_ROWS + NEO_TILE_PROGRESSIVE +
NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_TILE_PROGRESSIVE,
NEO_GRB + NEO_KHZ800);
// create our display // create our display
displayMatrix->setRemapFunction(&remap);
display = new OmobiLedDisplay("OmobiLedDisplay1", displayMatrix); display = new OmobiLedDisplay("OmobiLedDisplay1", displayMatrix);
} }
void loop() void loop()