Added the Matrix handling and clock/day wordmaps

Time and day display is functional again
This commit is contained in:
Matthias Mitscherlich
2024-03-21 16:39:20 +01:00
parent ac8505a157
commit 0fcd60ff57
17 changed files with 498 additions and 571 deletions
+113
View File
@@ -0,0 +1,113 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file ledmatrix.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_PLATFORM_INC_LEDMATRIX_H_
#define MAIN_PLATFORM_INC_LEDMATRIX_H_
/**
* ledmatrix implementation
* \defgroup ledmatrix
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
// ProjectIncludes
// All include files that are provided by the project
#include "prgm_ledstrip.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class ledmatrix : public prgm_ledstrip
{
// -----------------------------------------------------------------------------------------------------------------
// Public Section
// -----------------------------------------------------------------------------------------------------------------
public:
typedef enum
{
ORIENTATION_ROW_LEFT_UP = 0,
ORIENTATION_ROW_LEFT_DOWN = 1,
ORIENTATION_ROW_RIGHT_UP = 2,
ORIENTATION_ROW_RIGHT_DOWN = 3,
ORIENTATION_COL_LEFT_UP = 4,
ORIENTATION_COL_LEFT_DOWN = 5,
ORIENTATION_COL_RIGHT_UP = 6,
ORIENTATION_COL_RIGHT_DOWN = 7,
ORIENTATION_END = 8
} Orientation_t;
struct coordinate
{
uint32_t x;
uint32_t y;
};
// Class Constructor
ledmatrix(uint32_t rows, uint32_t columns, uint32_t gpio);
FunctionStatus setOrientation(Orientation_t orientation);
FunctionStatus setPixel(uint32_t row, uint32_t column, uint8_t red, uint8_t green, uint8_t blue);
// -----------------------------------------------------------------------------------------------------------------
// Protected Section
// -----------------------------------------------------------------------------------------------------------------
protected:
// -----------------------------------------------------------------------------------------------------------------
// Private Section
// -----------------------------------------------------------------------------------------------------------------
private:
uint32_t width;
uint32_t highth;
Orientation_t orientation;
FunctionStatus calculateIndexFromCoordinates(uint32_t row, uint32_t column, uint32_t* index);
};
/** @} */
#endif /* MAIN_PLATFORM_INC_LEDMATRIX_H_ */
+8
View File
@@ -76,7 +76,15 @@ class prgm_ledstrip
// Class Constructor
prgm_ledstrip(uint32_t numberOfLEDs, uint32_t gpio);
// Set and clear functions only update the pixel value(s) locally but do not push the values to the strip
FunctionStatus setPixel(struct pixel& pixel);
FunctionStatus clearAll(void);
// Clears all pixels locally and automatically pushes the values to the strip
FunctionStatus clearAndUpdate(void);
// Push the latest pixel values to the strip
FunctionStatus update(void);
// -----------------------------------------------------------------------------------------------------------------
// Protected Section
+124
View File
@@ -0,0 +1,124 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file ledmatrix.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include <ledmatrix.h>
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
ledmatrix::ledmatrix(uint32_t rows, uint32_t columns, uint32_t gpio) : prgm_ledstrip(rows * columns, gpio)
{
this->width = columns;
this->highth = rows;
this->orientation = ORIENTATION_ROW_LEFT_UP;
}
FunctionStatus ledmatrix::setOrientation(Orientation_t orientation)
{
FunctionStatus returnValue = FUNCTION_STATUS_OK;
if (orientation < ORIENTATION_END)
{
this->orientation = orientation;
}
else
{
returnValue = FUNCTION_STATUS_ERROR;
}
return returnValue;
}
FunctionStatus ledmatrix::setPixel(uint32_t row, uint32_t column, uint8_t red, uint8_t green, uint8_t blue)
{
FunctionStatus returnValue = FUNCTION_STATUS_OK;
uint32_t index = 0;
returnValue = calculateIndexFromCoordinates(row, column, &index);
if (returnValue == FUNCTION_STATUS_OK)
{
struct pixel p;
p.index = index;
p.red = red;
p.green = green;
p.blue = blue;
returnValue = prgm_ledstrip::setPixel(p);
}
return returnValue;
}
FunctionStatus ledmatrix::calculateIndexFromCoordinates(uint32_t row, uint32_t column, uint32_t* index)
{
FunctionStatus returnValue = FUNCTION_STATUS_OK;
switch(orientation)
{
case ORIENTATION_ROW_LEFT_UP:
*index = row * width + column;
break;
case ORIENTATION_ROW_LEFT_DOWN:
break;
case ORIENTATION_ROW_RIGHT_UP:
break;
case ORIENTATION_ROW_RIGHT_DOWN:
break;
case ORIENTATION_COL_LEFT_UP:
break;
case ORIENTATION_COL_LEFT_DOWN:
break;
case ORIENTATION_COL_RIGHT_UP:
break;
case ORIENTATION_COL_RIGHT_DOWN:
break;
default:
*index = 0;
returnValue = FUNCTION_STATUS_ERROR;
}
return returnValue;
}
+34 -6
View File
@@ -53,8 +53,8 @@ prgm_ledstrip::prgm_ledstrip(uint32_t numberOfLEDs, uint32_t gpio) : numberOfLED
/* LED strip initialization with the GPIO and pixels number*/
memset(&strip_config, 0, sizeof(strip_config));
strip_config.strip_gpio_num = 8; // The GPIO that connected to the LED strip's data line
strip_config.max_leds = 2; // The number of LEDs in the strip,
strip_config.strip_gpio_num = gpio; // The GPIO that connected to the LED strip's data line
strip_config.max_leds = numberOfLEDs; // The number of LEDs in the strip,
strip_config.led_pixel_format = LED_PIXEL_FORMAT_GRB; // Pixel format of your LED strip
strip_config.led_model = LED_MODEL_WS2812; // LED strip model
strip_config.flags.invert_out = false; // whether to invert the output signal (useful when your hardware has a level inverter)
@@ -69,15 +69,43 @@ prgm_ledstrip::prgm_ledstrip(uint32_t numberOfLEDs, uint32_t gpio) : numberOfLED
rmt_config.flags.with_dma = false; // whether to enable the DMA feature
#endif
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));
}
FunctionStatus prgm_ledstrip::setPixel(struct pixel& pixel)
{
FunctionStatus returnValue = FUNCTION_STATUS_OK;
ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, pixel.index, pixel.red, pixel.green, pixel.blue));
ESP_ERROR_CHECK(led_strip_refresh(led_strip));
if (pixel.index < numberOfLEDs)
{
ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, pixel.index, pixel.red, pixel.green, pixel.blue));
}
else
{
returnValue = FUNCTION_STATUS_ERROR;
}
return returnValue;
}
FunctionStatus prgm_ledstrip::clearAll(void)
{
for (int i = 0; i < numberOfLEDs; i++)
{
ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, i, 0, 0, 0));
}
return FUNCTION_STATUS_OK;
}
FunctionStatus prgm_ledstrip::clearAndUpdate(void)
{
ESP_ERROR_CHECK(led_strip_clear(led_strip));
return FUNCTION_STATUS_OK;
}
FunctionStatus prgm_ledstrip::update(void)
{
ESP_ERROR_CHECK(led_strip_refresh(led_strip));
return FUNCTION_STATUS_OK;
}