Fixed LED display driver that enables ESP32 as controller.
This commit is contained in:
parent
2c44f8b873
commit
b0fdd05bf2
7 changed files with 93 additions and 68 deletions
|
@ -17,3 +17,5 @@ lib_deps =
|
|||
SPI
|
||||
adafruit/Adafruit GFX Library@^1.10.1
|
||||
adafruit/Adafruit BusIO@1.4.1
|
||||
makuna/NeoPixelBus@^2.6.0
|
||||
aligator/NeoPixelBusGfx@^1.1.0
|
||||
|
|
|
@ -7,13 +7,47 @@
|
|||
#include <Adafruit_NeoPixel.h>
|
||||
#include <EepromManager.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
|
||||
{
|
||||
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();
|
||||
|
||||
//typedef uint16_t (*remapfn)(uint16_t, uint16_t);
|
||||
|
||||
enum text_align_t
|
||||
{
|
||||
AlignLeft,
|
||||
|
@ -63,7 +97,7 @@ public:
|
|||
private:
|
||||
// matrix objects
|
||||
TaskHandle_t displayUpdateTask;
|
||||
Adafruit_NeoMatrix *matrix;
|
||||
NeoPixelBrightnessBusGfx<NeoGrbFeature, Neo800KbpsMethod> *matrix;
|
||||
|
||||
// matrix variables
|
||||
uint16_t text_curr_nr;
|
||||
|
@ -76,6 +110,7 @@ private:
|
|||
bool disp_show;
|
||||
|
||||
// matrix control
|
||||
//uint16_t remap(uint16_t x, uint16_t y);
|
||||
void disp_init();
|
||||
void disp_start_set();
|
||||
void disp_scroll_text();
|
||||
|
@ -102,7 +137,7 @@ private:
|
|||
} sets_t;
|
||||
|
||||
// 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;
|
||||
|
||||
// storage control
|
||||
|
@ -112,8 +147,6 @@ private:
|
|||
bool loadTextSets();
|
||||
};
|
||||
|
||||
// function for updater task on core 0
|
||||
void updateDisplayGlobal(void *);
|
||||
extern LedDisplayController *ledDisplayControllerGlobal;
|
||||
|
||||
|
||||
#endif // LED_DISPLAY_CONTROLLER
|
|
@ -8,11 +8,32 @@
|
|||
#include "BluetoothLeUartServer.h"
|
||||
#include "LedDisplayController.h"
|
||||
|
||||
|
||||
class OmobiLedDisplay : protected BluetoothLeUartServerCallbacks
|
||||
{
|
||||
|
||||
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
|
||||
friend class BluetoothLeUartServer;
|
||||
|
|
|
@ -22,5 +22,7 @@ lib_deps =
|
|||
adafruit/Adafruit NeoPixel@^1.6.0
|
||||
adafruit/Adafruit NeoMatrix@^1.1.5
|
||||
bblanchon/ArduinoJson@^6.16.1
|
||||
makuna/NeoPixelBus
|
||||
aligator/NeoPixelBusGfx@^1.1.0
|
||||
monitor_filters = esp32_exception_decoder
|
||||
monitor_speed = 115200
|
||||
|
|
|
@ -2,29 +2,7 @@
|
|||
|
||||
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 -
|
||||
|
@ -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].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);
|
||||
if (0 < text_set_starttime || text_sets.sets[text_curr_nr].text == '\0' || text_sets.sets[text_curr_nr].active == false)
|
||||
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->setCursor(pos, 0);
|
||||
this->matrix->print(text);
|
||||
portDISABLE_INTERRUPTS();
|
||||
this->matrix->show();
|
||||
portENABLE_INTERRUPTS();
|
||||
//portDISABLE_INTERRUPTS();
|
||||
this->matrix->Show();
|
||||
//portENABLE_INTERRUPTS();
|
||||
}
|
||||
|
||||
uint16_t LedDisplayController::colorFromHex(String hex)
|
||||
|
@ -198,7 +177,7 @@ LedDisplayController::GetSetTextSetParameterExitCode LedDisplayController::getSe
|
|||
else if (strcmp(this->text_sets.valid, "OK") != 0)
|
||||
return InternalError;
|
||||
|
||||
text_set_t *currentTextSet = &this->text_sets.sets[index];
|
||||
text_set_t* currentTextSet = &this->text_sets.sets[index];
|
||||
String returnValue = "";
|
||||
|
||||
switch (parameter)
|
||||
|
@ -336,7 +315,7 @@ bool LedDisplayController::loadTextSets()
|
|||
if (strcmp(buf.valid, "OK") == 0)
|
||||
{
|
||||
memcpy(&text_sets, &buf, sizeof(sets_t));
|
||||
Serial.println("OK");
|
||||
Serial.printf("OK: '%s\n", text_sets.sets[0].text);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -359,12 +338,12 @@ bool LedDisplayController::loadTextSets()
|
|||
// - Extern -
|
||||
// ----------
|
||||
|
||||
void updateDisplayGlobal(void *)
|
||||
void updateDisplayGlobal(void* object)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
esp_task_wdt_reset();
|
||||
delay(1);
|
||||
ledDisplayControllerGlobal->loop();
|
||||
((LedDisplayController*)(object))->loop();
|
||||
}
|
||||
}
|
|
@ -1,24 +1,7 @@
|
|||
#include "OmobiLedDisplay.h"
|
||||
|
||||
OmobiLedDisplay::OmobiLedDisplay(String deviceName, Adafruit_NeoMatrix *ledDisplayMatrix)
|
||||
{
|
||||
this->lastKeepAlive = -1;
|
||||
this->sessionAuthorized = false;
|
||||
//OmobiLedDisplay::OmobiLedDisplay(String deviceName, Adafruit_NeoMatrix *ledDisplayMatrix)
|
||||
|
||||
// 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()
|
||||
{
|
||||
|
|
|
@ -1,27 +1,32 @@
|
|||
#include <Arduino.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;
|
||||
|
||||
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()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
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
|
||||
displayMatrix->setRemapFunction(&remap);
|
||||
display = new OmobiLedDisplay("OmobiLedDisplay1", displayMatrix);
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
|
Loading…
Reference in a new issue