2025-08-03 00:34:05 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include "pin.h"
|
|
|
|
|
|
|
|
|
|
struct LightInfo {
|
|
|
|
|
std::string uniqueId;
|
|
|
|
|
const std::string name = "Smart RGB Light";
|
|
|
|
|
const std::string discoveryTopic = "homeassistant/light/smart_rgb_light/light/config";
|
|
|
|
|
const std::string availabilityTopic = "studiotj/smart-rgb/light/status";
|
|
|
|
|
const std::string stateTopic = "studiotj/smart-rgb/light/state";
|
2025-08-27 17:30:39 +02:00
|
|
|
const std::string jsonAttributesTopic = "studiotj/smart-rgb/light/attributes";
|
2025-08-03 00:34:05 +02:00
|
|
|
const std::string stateValueTemplate = "{{ value_json.state }}";
|
|
|
|
|
const std::string commandTopic = "studiotj/smart-rgb/light/state/set";
|
|
|
|
|
const std::string supportedColorModesValue = "['rgb', 'brightness']";
|
|
|
|
|
const std::string availabilityTemplate = "{{ value_json.availability }}";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct DeviceInfo {
|
|
|
|
|
std::string name = "Smart RGB Light";
|
|
|
|
|
std::string model = "smart_rgb_light";
|
|
|
|
|
std::string identifier = "smart_rgb_light_";
|
|
|
|
|
std::string swVersion = "1.0"; // TODO: version will be generated.
|
|
|
|
|
std::string manufacturer = "Studio TJ";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum LightType {
|
|
|
|
|
onOff,
|
|
|
|
|
brightness,
|
|
|
|
|
colorTemperature,
|
|
|
|
|
rgb,
|
|
|
|
|
rgbw,
|
|
|
|
|
rgbww,
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-27 17:30:39 +02:00
|
|
|
enum ActiveMode {
|
|
|
|
|
modeRgb,
|
|
|
|
|
modeCct
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-03 00:34:05 +02:00
|
|
|
class Light {
|
|
|
|
|
public:
|
2025-08-29 10:22:36 +02:00
|
|
|
Light(Pin* pinR, Pin* pinG, Pin* pinB, std::string uniqueId);
|
|
|
|
|
Light(Pin* pinR, Pin* pinG, Pin* pinB, Pin* pinCW, std::string uniqueId);
|
|
|
|
|
Light(Pin* pinR, Pin* pinG, Pin* pinB, Pin* pinCW, Pin* pinWW, std::string uniqueId);
|
2025-08-29 19:17:09 +02:00
|
|
|
void notifyOnline();
|
|
|
|
|
void notifyOffline();
|
2025-08-03 00:34:05 +02:00
|
|
|
void publishInitialState();
|
|
|
|
|
void publishCurrentState();
|
|
|
|
|
void setHsl(uint8_t h, uint8_t s, uint8_t l);
|
|
|
|
|
void setColorTemperature(uint16_t temperature);
|
|
|
|
|
void setBrightness(uint8_t brightness);
|
|
|
|
|
void turnOff();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void handleCommand(const std::string& command);
|
|
|
|
|
void operatePin();
|
2025-08-27 10:40:39 +02:00
|
|
|
uint32_t correctGamma(uint32_t originalPwm);
|
2025-08-27 17:30:39 +02:00
|
|
|
void applyKelvin(uint32_t kelvin);
|
|
|
|
|
uint8_t r = 0; // Default to white
|
|
|
|
|
uint8_t g = 0; // Default to white
|
|
|
|
|
uint8_t b = 0; // Default to white
|
2025-08-03 00:34:05 +02:00
|
|
|
uint8_t cw = 255; // Default to white
|
|
|
|
|
uint8_t ww = 255; // Default to white
|
2025-08-27 17:30:39 +02:00
|
|
|
const uint32_t cwTempKelvin = 6000;
|
|
|
|
|
const uint32_t wwTempKelvin = 3000;
|
2025-08-03 00:34:05 +02:00
|
|
|
uint16_t colorTemperature;
|
|
|
|
|
uint8_t brightness;
|
2025-08-27 17:30:39 +02:00
|
|
|
uint32_t maxPwm;
|
2025-08-03 00:34:05 +02:00
|
|
|
bool isOn = false;
|
|
|
|
|
Pin* pinR;
|
|
|
|
|
Pin* pinG;
|
|
|
|
|
Pin* pinB;
|
|
|
|
|
Pin* pinCW;
|
|
|
|
|
Pin* pinWW;
|
|
|
|
|
LightInfo lightInfo;
|
|
|
|
|
DeviceInfo deviceInfo;
|
|
|
|
|
LightType lightType = onOff; // Default light type
|
2025-08-27 17:30:39 +02:00
|
|
|
ActiveMode activeMode = modeRgb;
|
2025-08-03 00:34:05 +02:00
|
|
|
};
|