#pragma once #include #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"; const std::string jsonAttributesTopic = "studiotj/smart-rgb/light/attributes"; 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, }; enum ActiveMode { modeRgb, modeCct }; class Light { public: 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); void notifyOnline(); void notifyOffline(); 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(); uint32_t correctGamma(uint32_t originalPwm); 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 uint8_t cw = 255; // Default to white uint8_t ww = 255; // Default to white const uint32_t cwTempKelvin = 6000; const uint32_t wwTempKelvin = 3000; uint16_t colorTemperature; uint8_t brightness; uint32_t maxPwm; bool isOn = false; Pin* pinR; Pin* pinG; Pin* pinB; Pin* pinCW; Pin* pinWW; LightInfo lightInfo; DeviceInfo deviceInfo; LightType lightType = onOff; // Default light type ActiveMode activeMode = modeRgb; };