Fixed coordiante behaviour of the matrix
This commit is contained in:
+73
-43
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user