From 1ae7d6ec5a5ed31091e4eedc577f1e2b72f5c8bc Mon Sep 17 00:00:00 2001 From: Matthias Mitscherlich Date: Wed, 18 Jan 2023 10:36:36 +0100 Subject: [PATCH] Fixed coordiante behaviour of the matrix --- code/main/inc/ledmatrix.h | 8 ++- code/main/main.cpp | 37 +++--------- code/main/src/ledmatrix.cpp | 116 +++++++++++++++++++++++------------- code/main/src/wifi.cpp | 8 +-- 4 files changed, 92 insertions(+), 77 deletions(-) diff --git a/code/main/inc/ledmatrix.h b/code/main/inc/ledmatrix.h index 1834da6..9126b9f 100644 --- a/code/main/inc/ledmatrix.h +++ b/code/main/inc/ledmatrix.h @@ -49,6 +49,9 @@ // Constant and macro definitions // -------------------------------------------------------------------------------------------------------------------- +#define LEDMATRIX_RED_INDEX ((uint32_t)1) +#define LEDMATRIX_GREEN_INDEX ((uint32_t)0) +#define LEDMATRIX_BLUE_INDEX ((uint32_t)2) // -------------------------------------------------------------------------------------------------------------------- // Type definitions. @@ -102,7 +105,10 @@ class LEDMatrix public: LEDMatrix(LEDMatrix_Parameters_t* parameters); - void setPixelValue(unsigned int row, unsigned int colum, bool value); + bool setPixelValue(unsigned int row, unsigned int colum, bool value); + void setGlobalColour(uint8_t red, uint8_t green, uint8_t blue); + + void clear(void); private: LEDMatrix_Parameters_t parameters; diff --git a/code/main/main.cpp b/code/main/main.cpp index 4fef8bf..3f11aab 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -31,7 +31,7 @@ static rmt_transmit_config_t tx_config; static rmt_encoder_handle_t led_encoder = NULL; #define RMT_LED_STRIP_RESOLUTION_HZ 10000000 // 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution) -#define RMT_LED_STRIP_GPIO_NUM 8 +#define RMT_LED_STRIP_GPIO_NUM 0 extern "C" void app_main(void) { @@ -137,36 +137,15 @@ extern "C" void app_main(void) while (true) { -// struct tm tm; -// time(¤tTime); -// localtime_r(¤tTime, &tm); -// -// LOGGER_INFO("%lld\n\r", currentTime); -// LOGGER_INFO("%02i:%02i:%02i\n\r", tm.tm_hour, tm.tm_min, tm.tm_sec); -// -// vTaskDelay(300); + struct tm tm; + time(¤tTime); + localtime_r(¤tTime, &tm); + LOGGER_INFO("%lld\n\r", currentTime); + LOGGER_INFO("%02i:%02i:%02i\n\r", tm.tm_hour, tm.tm_min, tm.tm_sec); + + vTaskDelay(300); - LOGGER_DEBUG("Enable pixel (%i:%i)", row, colum); - LEDMatrix.setPixelValue(row, colum, true); - vTaskDelay(100); - LEDMatrix.setPixelValue(row, colum, false); - if (row<10) - { - row++; - } - else - { - row = 0; - if(colum < 2) - { - colum++; - } - else - { - colum = 0; - } - } } } diff --git a/code/main/src/ledmatrix.cpp b/code/main/src/ledmatrix.cpp index d9bfbc5..c0f025b 100644 --- a/code/main/src/ledmatrix.cpp +++ b/code/main/src/ledmatrix.cpp @@ -61,67 +61,98 @@ LEDMatrix::LEDMatrix(LEDMatrix_Parameters_t* parameters) matrix = new LEDMatrix_Pixel_t[parameters->width * parameters->height]; // Create the second matrix, that is actually transmitted to the periphery - // Reset the matrix to all 0 (all LEDs off) -// memset(&matrix, 0, sizeof(matrix)); - // Create the task Semaphore vSemaphoreCreateBinary(LEDMatrix::taskSemaphore); + // Take the semaphore immediately so the task cannot run + xSemaphoreTake(LEDMatrix::taskSemaphore, 0); // Create the matrix task xTaskCreate(matrixTask, (const char*)"matrixTask", 4096, this, 3, &LEDMatrix::matrixTaskHandle); - for (int i = 0; i < numberOfPixels; i++) - { - matrix[i].on = false; - matrix[i].green = 0x1F; - } - - LOGGER_DEBUG("---- %i -----", matrix[0].green); - + // Clear the matrix initially + LEDMatrix::clear(); } -void LEDMatrix::setPixelValue(unsigned int row, unsigned int colum, bool value) +bool LEDMatrix::setPixelValue(unsigned int row, unsigned int colum, bool value) { + bool returnValue = true; + unsigned int rowC = 0; unsigned int colC = 0; unsigned int pixelAddress = 0; - // Determine the actual row coordinate based on the matrix orientation - if (parameters.columOrientation == LEDMATRIX_ORIENTATION_COLUM_UP_DOWN) + if ((row < parameters.height) && (colum < parameters.width)) { - rowC = row; + returnValue = true; } - else if (parameters.columOrientation == LEDMATRIX_ORIENTATION_COLUM_DOWN_UP) + else { - rowC = parameters.height - row; + returnValue = false; } - // Determine the actual row coordinate based on the matrix orientation - if (parameters.rowOrientation == LEDMATRIX_ORIENTATION_ROW_LEFT_RIGHT) + if (returnValue) { - colC = colum; + + // Determine the actual row coordinate based on the matrix orientation + if (parameters.columOrientation == LEDMATRIX_ORIENTATION_COLUM_UP_DOWN) + { + rowC = row; + } + else if (parameters.columOrientation == LEDMATRIX_ORIENTATION_COLUM_DOWN_UP) + { + rowC = (parameters.height - 1) - row; + } + + // Determine the actual row coordinate based on the matrix orientation + if (parameters.rowOrientation == LEDMATRIX_ORIENTATION_ROW_LEFT_RIGHT) + { + colC = colum; + } + else if (parameters.rowOrientation == LEDMATRIX_ORIENTATION_ROW_RIGHT_LEFT) + { + colC = (parameters.width - 1) - colum; + } + + // Calculate the pixel address in the pixel array based on the previous information + if (parameters.matrixOrientation == LEDMATRIX_ORIENTATION_COLUM) + { + pixelAddress = rowC + (colC * parameters.height); + } + + // Update the pixel value + matrix[pixelAddress].on = value; + + + + // Release the semaphore to trigger an matrix update + xSemaphoreGive(LEDMatrix::taskSemaphore); } - else if (parameters.rowOrientation == LEDMATRIX_ORIENTATION_ROW_RIGHT_LEFT) - { - colC = parameters.width - colum; - } - - // Calculate the pixel address in the pixel array based on the previous information - if (parameters.matrixOrientation == LEDMATRIX_ORIENTATION_COLUM) - { - pixelAddress = (rowC - 1) * (colC + 1); - } - - LOGGER_DEBUG("Calculated address: %i (%i:%i)", pixelAddress, rowC, colC); - // Update the pixel value - matrix[pixelAddress].on = value; - - - - // Release the semaphore to trigger an matrix update - xSemaphoreGive(LEDMatrix::taskSemaphore); + return returnValue; } +void LEDMatrix::setGlobalColour(uint8_t red, uint8_t green, uint8_t blue) +{ + for (int i = 0; i < numberOfPixels; i++) + { + matrix[i].red = red; + matrix[i].green = green; + matrix[i].blue = blue; + } +} + + +void LEDMatrix::clear(void) +{ + for (int i = 0; i < numberOfPixels; i++) + { + matrix[i].on = false; + matrix[i].red = 0; + matrix[i].green = 0; + matrix[i].blue = 0; + } + // Release the semaphore to trigger an matrix update + xSemaphoreGive(LEDMatrix::taskSemaphore); +} void LEDMatrix::matrixTask(void* parameters) @@ -138,9 +169,9 @@ void LEDMatrix::matrixTask(void* parameters) { if (ledmatrix->matrix[i].on) { - matrix[i * 3 + 0] = ledmatrix->matrix[i].red; - matrix[i * 3 + 1] = ledmatrix->matrix[i].green; - matrix[i * 3 + 2] = ledmatrix->matrix[i].blue; + matrix[i * 3 + LEDMATRIX_RED_INDEX] = ledmatrix->matrix[i].red; + matrix[i * 3 + LEDMATRIX_GREEN_INDEX] = ledmatrix->matrix[i].green; + matrix[i * 3 + LEDMATRIX_BLUE_INDEX] = ledmatrix->matrix[i].blue; } else { @@ -150,7 +181,6 @@ void LEDMatrix::matrixTask(void* parameters) } } - LOGGER_DEBUG("HERE AGAIN"); // Re-draw the matrix every 10 seconds anyhow rmt_transmit(*ledmatrix->parameters.rmtChannel, *ledmatrix->parameters.rmtEncoder, matrix, sizeof(matrix), ledmatrix->parameters.rmtConfig); diff --git a/code/main/src/wifi.cpp b/code/main/src/wifi.cpp index 550a57f..9436f63 100644 --- a/code/main/src/wifi.cpp +++ b/code/main/src/wifi.cpp @@ -48,10 +48,10 @@ // -------------------------------------------------------------------------------------------------------------------- -//static const char* ssid = "Kowalski"; -//static const char* pass = "madagascar"; -static const char* ssid = "vbchaos"; -static const char* pass = "mijninternet"; +static const char* ssid = "Kowalski"; +static const char* pass = "madagascar"; +//static const char* ssid = "vbchaos"; +//static const char* pass = "mijninternet"; // -------------------------------------------------------------------------------------------------------------------- // Function declarations