DualLedController/components/LedController/LedController.h

42 lines
1013 B
C++

#ifndef __LEDCONTROLLER_H__
#define __LEDCONTROLLER_H__
#include <driver/ledc.h>
class LedController {
public:
constexpr static ledc_timer_bit_t TimerBit = LEDC_TIMER_12_BIT;
constexpr static int32_t Resolution = 1 << LEDC_TIMER_12_BIT;
constexpr static int32_t MinimumColorTemp = 153;
constexpr static int32_t MaximumColorTemp = 500;
enum Channel {
Warm = 0,
Cold = 1,
};
static LedController *instance();
bool initialize();
int32_t brightness() const;
void setBrightness(int32_t brightness);
int32_t colorTemperature() const;
void setColorTemperature(int32_t temp);
bool enabled() const;
void setEnabled(bool enabled);
void setDuty(Channel channel, int32_t duty);
protected:
LedController();
void update();
ledc_channel_config_t m_channels[2];
private:
bool m_enabled = false;
int32_t m_brightness = 0;
int32_t m_colorTemp = 0;
};
#endif // __LEDCONTROLLER_H__