|
|
|
@@ -14,8 +14,8 @@ const struct {
|
|
|
|
} Availability;
|
|
|
|
} Availability;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, Mqtt* mqttClient, std::string uniqueId)
|
|
|
|
Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, std::string uniqueId)
|
|
|
|
: pinR(pinR), pinG(pinG), pinB(pinB), pinCW(nullptr), pinWW(nullptr), mqttClient(mqttClient) {
|
|
|
|
: pinR(pinR), pinG(pinG), pinB(pinB), pinCW(nullptr), pinWW(nullptr) {
|
|
|
|
lightInfo.uniqueId = uniqueId;
|
|
|
|
lightInfo.uniqueId = uniqueId;
|
|
|
|
lightType = LightType::rgb;
|
|
|
|
lightType = LightType::rgb;
|
|
|
|
uint8_t bits = pinR->getLedResolutionBits();
|
|
|
|
uint8_t bits = pinR->getLedResolutionBits();
|
|
|
|
@@ -24,8 +24,8 @@ Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, Mqtt* mqttClient, std::string uniq
|
|
|
|
subscribeToMqttTopics();
|
|
|
|
subscribeToMqttTopics();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, Pin* pinCW, Pin* pinWW, Mqtt* mqttClient, std::string uniqueId)
|
|
|
|
Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, Pin* pinCW, Pin* pinWW, std::string uniqueId)
|
|
|
|
: pinR(pinR), pinG(pinG), pinB(pinB), pinCW(pinCW), pinWW(pinWW), mqttClient(mqttClient) {
|
|
|
|
: pinR(pinR), pinG(pinG), pinB(pinB), pinCW(pinCW), pinWW(pinWW) {
|
|
|
|
lightInfo.uniqueId = uniqueId;
|
|
|
|
lightInfo.uniqueId = uniqueId;
|
|
|
|
lightType = LightType::rgbww;
|
|
|
|
lightType = LightType::rgbww;
|
|
|
|
uint8_t bits = pinR->getLedResolutionBits();
|
|
|
|
uint8_t bits = pinR->getLedResolutionBits();
|
|
|
|
@@ -76,7 +76,7 @@ void Light::publishInitialState() {
|
|
|
|
|
|
|
|
|
|
|
|
std::string configJson;
|
|
|
|
std::string configJson;
|
|
|
|
serializeJson(configInfo, configJson);
|
|
|
|
serializeJson(configInfo, configJson);
|
|
|
|
mqttClient->publish(lightInfo.discoveryTopic, configJson);
|
|
|
|
Mqtt::publish(lightInfo.discoveryTopic, configJson);
|
|
|
|
|
|
|
|
|
|
|
|
std::string stateJson;
|
|
|
|
std::string stateJson;
|
|
|
|
JsonDocument stateInfo;
|
|
|
|
JsonDocument stateInfo;
|
|
|
|
@@ -95,8 +95,8 @@ void Light::publishInitialState() {
|
|
|
|
JsonDocument availabilityInfoDoc;
|
|
|
|
JsonDocument availabilityInfoDoc;
|
|
|
|
availabilityInfoDoc["availability"] = Availability.available;
|
|
|
|
availabilityInfoDoc["availability"] = Availability.available;
|
|
|
|
serializeJson(availabilityInfoDoc, availabilityJson);
|
|
|
|
serializeJson(availabilityInfoDoc, availabilityJson);
|
|
|
|
mqttClient->publish(lightInfo.stateTopic, stateJson);
|
|
|
|
Mqtt::publish(lightInfo.stateTopic, stateJson);
|
|
|
|
mqttClient->publish(lightInfo.availabilityTopic, availabilityJson);
|
|
|
|
Mqtt::publish(lightInfo.availabilityTopic, availabilityJson);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Light::operatePin() {
|
|
|
|
void Light::operatePin() {
|
|
|
|
@@ -159,7 +159,7 @@ void Light::operatePin() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Light::subscribeToMqttTopics() {
|
|
|
|
void Light::subscribeToMqttTopics() {
|
|
|
|
mqttClient->subscribe(lightInfo.commandTopic, [this](uint8_t* payload, int length) {
|
|
|
|
Mqtt::subscribe(lightInfo.commandTopic, [this](uint8_t* payload, int length) {
|
|
|
|
std::string command(reinterpret_cast<char*>(payload), length);
|
|
|
|
std::string command(reinterpret_cast<char*>(payload), length);
|
|
|
|
handleCommand(command);
|
|
|
|
handleCommand(command);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
@@ -241,11 +241,11 @@ void Light::publishCurrentState() {
|
|
|
|
std::string stateJson;
|
|
|
|
std::string stateJson;
|
|
|
|
serializeJson(stateInfo, stateJson);
|
|
|
|
serializeJson(stateInfo, stateJson);
|
|
|
|
Serial.println("Publishing current state: " + String(stateJson.c_str()));
|
|
|
|
Serial.println("Publishing current state: " + String(stateJson.c_str()));
|
|
|
|
mqttClient->publish(lightInfo.stateTopic, stateJson);
|
|
|
|
Mqtt::publish(lightInfo.stateTopic, stateJson);
|
|
|
|
std::string attributeJson;
|
|
|
|
std::string attributeJson;
|
|
|
|
serializeJson(attributeInfo, attributeJson);
|
|
|
|
serializeJson(attributeInfo, attributeJson);
|
|
|
|
Serial.println("Publishing current attributes: " + String(attributeJson.c_str()));
|
|
|
|
Serial.println("Publishing current attributes: " + String(attributeJson.c_str()));
|
|
|
|
mqttClient->publish(lightInfo.jsonAttributesTopic, attributeJson);
|
|
|
|
Mqtt::publish(lightInfo.jsonAttributesTopic, attributeJson);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t Light::correctGamma(uint32_t originalPwm) {
|
|
|
|
uint32_t Light::correctGamma(uint32_t originalPwm) {
|
|
|
|
|