led class refactor

This commit is contained in:
Emanuele Trabattoni
2025-08-01 10:38:41 +02:00
parent eaa643bf3c
commit 25aa2d6cb6
3 changed files with 87 additions and 50 deletions

View File

@@ -5,21 +5,22 @@
#define DEBUGLOG_DEFAULT_LOG_LEVEL_INFO
#include <DebugLog.h>
#include <mutex>
namespace drivers
{
class Led
{
const uint8_t c_ledPin = 38;
public:
public:
typedef struct
{
uint8_t r;
uint8_t g;
uint8_t b;
} color_t;
const color_t COLOR_RED = {255, 0, 0};
const color_t COLOR_ORANGE = {255, 127, 0};
const color_t COLOR_YELLOW = {255, 255, 0};
@@ -30,32 +31,35 @@ namespace drivers
const color_t COLOR_BLUE = {0, 0, 255};
const color_t COLOR_VIOLET = {127, 0, 255};
const color_t COLOR_MAGENTA = {255, 0, 255};
private:
typedef struct
{
color_t color1;
color_t color2;
uint8_t pin;
uint16_t tOn;
uint16_t tOff;
TaskHandle_t blinkTask;
} led_params_t;
public:
public:
Led();
~Led();
void setColor(const color_t color);
void flashColor(const uint16_t tOn, const color_t color);
void blinkColor(const uint16_t tOn, const uint16_t tOff, const color_t color);
void blinkAlternate(const uint16_t tOn, const uint16_t tOff, const color_t color1, const color_t color2);
void blinkStop();
private:
private:
static void flashHandle(TimerHandle_t th);
static void blinkTask(void *params);
private:
const uint8_t c_ledPin = 38;
color_t m_color1;
color_t m_color2;
color_t m_colorDefault;
private:
led_params_t m_lp;
uint16_t m_tOn;
uint16_t m_tOff;
TaskHandle_t m_blinkTask;
TimerHandle_t m_flashTimer;
std::mutex m_ledMutex;
};
}