70 lines
1.3 KiB
C++

/// © MiroZ 2024
#ifndef __LED_H__
#define __LED_H__
#include <stdint.h>
#include <Adafruit_NeoPixel.h>
#include "TaskMgr.h"
#include <System.h>
class Led
{
struct LED_QUEUE
{
uint8_t program;
uint8_t r;
uint8_t g;
uint8_t b;
};
private:
bool m_leds_physically_on = false;
bool m_led_sync_mode = false;
uint32_t m_last_light_sync = 0; // Last time we synced with light measurement
public:
bool areLedsCurrentlyOff() const { return !m_leds_physically_on; }
void setLightMeasurementSyncMode(bool enable);
void updateLedPhysicalState(bool leds_on);
public:
enum PROGRAM
{
STEADY,
PULSATING
};
protected:
Adafruit_NeoPixel *m_strip;
TaskHandle_t m_task = nullptr;
uint8_t m_brightness = 100;
uint8_t scale(uint8_t val){ return (uint8_t)((int)val*m_brightness/100); }
Queue<struct LED_QUEUE> m_queue;
protected:
void run();
void steady(uint8_t r, uint8_t g, uint8_t b, uint8_t delay);
public:
Led(uint32_t led_pin);
virtual ~Led();
public:
void setBrightness(uint8_t brightness);
void setColor(uint8_t r, uint8_t g, uint8_t b);
void setPulse(uint8_t r, uint8_t g, uint8_t b);
void setLedColor(uint8_t led_index, uint8_t r, uint8_t g, uint8_t b);
void suspendTask();
void resumeTask();
void allOff();
void setDirectColor(uint8_t led_index, uint8_t r, uint8_t g, uint8_t b);
};
#endif /* __LED_H__ */