Fixed coordiante behaviour of the matrix
This commit is contained in:
@@ -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;
|
||||
|
||||
+8
-29
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+50
-20
@@ -61,30 +61,37 @@ 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;
|
||||
// Clear the matrix initially
|
||||
LEDMatrix::clear();
|
||||
}
|
||||
|
||||
LOGGER_DEBUG("---- %i -----", matrix[0].green);
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if ((row < parameters.height) && (colum < parameters.width))
|
||||
{
|
||||
returnValue = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = false;
|
||||
}
|
||||
|
||||
if (returnValue)
|
||||
{
|
||||
|
||||
// Determine the actual row coordinate based on the matrix orientation
|
||||
if (parameters.columOrientation == LEDMATRIX_ORIENTATION_COLUM_UP_DOWN)
|
||||
{
|
||||
@@ -92,7 +99,7 @@ void LEDMatrix::setPixelValue(unsigned int row, unsigned int colum, bool value)
|
||||
}
|
||||
else if (parameters.columOrientation == LEDMATRIX_ORIENTATION_COLUM_DOWN_UP)
|
||||
{
|
||||
rowC = parameters.height - row;
|
||||
rowC = (parameters.height - 1) - row;
|
||||
}
|
||||
|
||||
// Determine the actual row coordinate based on the matrix orientation
|
||||
@@ -102,16 +109,15 @@ void LEDMatrix::setPixelValue(unsigned int row, unsigned int colum, bool value)
|
||||
}
|
||||
else if (parameters.rowOrientation == LEDMATRIX_ORIENTATION_ROW_RIGHT_LEFT)
|
||||
{
|
||||
colC = parameters.width - colum;
|
||||
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 - 1) * (colC + 1);
|
||||
pixelAddress = rowC + (colC * parameters.height);
|
||||
}
|
||||
|
||||
LOGGER_DEBUG("Calculated address: %i (%i:%i)", pixelAddress, rowC, colC);
|
||||
// Update the pixel value
|
||||
matrix[pixelAddress].on = value;
|
||||
|
||||
@@ -120,8 +126,33 @@ void LEDMatrix::setPixelValue(unsigned int row, unsigned int colum, bool 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