94 lines
4.1 KiB
C++
94 lines
4.1 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include "pin.h"
|
|
#include "mqtt.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 baseTopic = "studiotj/smart-rgb/light";
|
|
const std::string availabilityTopic = "studiotj/smart-rgb/light/status";
|
|
const std::string stateTopic = "studiotj/smart-rgb/light/state";
|
|
const std::string stateValueTemplate = "{{ value_json.state }}";
|
|
const std::string commandTopic = "studiotj/smart-rgb/light/state/set";
|
|
const std::string brightnessCommandTopic = "studiotj/smart-rgb/light/brightness/set";
|
|
const std::string brightnessValueTemplate = "{{ value_json.brightness }}";
|
|
const std::string colorTempCommandTopic = "studiotj/smart-rgb/light/color_temp/set";
|
|
const std::string colorTempKelvinTopic = "studiotj/smart-rgb/light/color_temp_kelvin/set";
|
|
const std::string colorTempStateTopic = "studiotj/smart-rgb/light/color_temp/state";
|
|
const std::string colorTempValueTemplate = "{{ value_json.color_temp }}";
|
|
const std::string hsCommandTopic = "studiotj/smart-rgb/light/hs/set";
|
|
const std::string hsCommandTemplate = "{{ value_json.hs_cmd }}";
|
|
const std::string hsStateTopic = "studiotj/smart-rgb/light/hs/state";
|
|
const std::string hsValueTemplate = " {{ value_json.hs_value }}";
|
|
const std::string rgbCommandTopic = "studiotj/smart-rgb/light/rgb/set";
|
|
const std::string rgbCommandTemplate = "{{ {'rgb': [red, green, blue]} | to_json }}";
|
|
const std::string rgbStateTopic = "studiotj/smart-rgb/light/rgb/state";
|
|
const std::string rgbValueTemplate = "{{ value_json.rgb | join(',') }}";
|
|
const std::string rgbwCommandTopic = "studiotj/smart-rgb/light/rgbw/set";
|
|
const std::string rgbwCommandTemplate = "{{ value_json.rgbw_cmd }}";
|
|
const std::string rgbwStateTopic = "studiotj/smart-rgb/light/rgbw/state";
|
|
const std::string rgbwValueTemplate = "{{ value_json.rgbw_value }}";
|
|
const std::string rgbwwCommandTopic = "studiotj/smart-rgb/light/rgbww/set";
|
|
const std::string rgbwwCommandTemplate = "{{ value_json.rgbww_cmd }}";
|
|
const std::string rgbwwStateTopic = "studiotj/smart-rgb/light/rgbww/state";
|
|
const std::string rgbwwValueTemplate = "{{ value_json.rgbww_value }}";
|
|
const std::string supportedColorModesTopic = "studiotj/smart-rgb/light/supported_color_modes";
|
|
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,
|
|
};
|
|
|
|
class Light {
|
|
public:
|
|
Light(Pin* pinR, Pin* pinG, Pin* pinB, Mqtt* mqttClient, std::string uniqueId);
|
|
Light(Pin* pinR, Pin* pinG, Pin* pinB, Pin* pinCW, Mqtt* mqttClient, std::string uniqueId);
|
|
Light(Pin* pinR, Pin* pinG, Pin* pinB, Pin* pinCW, Pin* pinWW, Mqtt* mqttClient, std::string uniqueId);
|
|
void subscribeToMqttTopics();
|
|
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 turnOn();
|
|
void turnOff();
|
|
|
|
private:
|
|
void handleCommand(const std::string& command);
|
|
void operatePin();
|
|
uint8_t r = 255; // Default to white
|
|
uint8_t g = 255; // Default to white
|
|
uint8_t b = 255; // Default to white
|
|
uint8_t cw = 255; // Default to white
|
|
uint8_t ww = 255; // Default to white
|
|
uint16_t colorTemperature;
|
|
uint8_t brightness;
|
|
bool isOn = false;
|
|
Pin* pinR;
|
|
Pin* pinG;
|
|
Pin* pinB;
|
|
Pin* pinCW;
|
|
Pin* pinWW;
|
|
Mqtt* mqttClient;
|
|
LightInfo lightInfo;
|
|
DeviceInfo deviceInfo;
|
|
LightType lightType = onOff; // Default light type
|
|
}; |