diff --git a/lib/light/light.cpp b/lib/light/light.cpp index 9736a4f..16020f9 100644 --- a/lib/light/light.cpp +++ b/lib/light/light.cpp @@ -14,8 +14,8 @@ const struct { } Availability; -Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, Mqtt* mqttClient, std::string uniqueId) - : pinR(pinR), pinG(pinG), pinB(pinB), pinCW(nullptr), pinWW(nullptr), mqttClient(mqttClient) { +Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, std::string uniqueId) + : pinR(pinR), pinG(pinG), pinB(pinB), pinCW(nullptr), pinWW(nullptr) { lightInfo.uniqueId = uniqueId; lightType = LightType::rgb; uint8_t bits = pinR->getLedResolutionBits(); @@ -24,8 +24,8 @@ Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, Mqtt* mqttClient, std::string uniq subscribeToMqttTopics(); } -Light::Light(Pin* pinR, Pin* pinG, Pin* pinB, Pin* pinCW, Pin* pinWW, Mqtt* mqttClient, std::string uniqueId) - : pinR(pinR), pinG(pinG), pinB(pinB), pinCW(pinCW), pinWW(pinWW), mqttClient(mqttClient) { +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) { lightInfo.uniqueId = uniqueId; lightType = LightType::rgbww; uint8_t bits = pinR->getLedResolutionBits(); @@ -76,7 +76,7 @@ void Light::publishInitialState() { std::string configJson; serializeJson(configInfo, configJson); - mqttClient->publish(lightInfo.discoveryTopic, configJson); + Mqtt::publish(lightInfo.discoveryTopic, configJson); std::string stateJson; JsonDocument stateInfo; @@ -95,8 +95,8 @@ void Light::publishInitialState() { JsonDocument availabilityInfoDoc; availabilityInfoDoc["availability"] = Availability.available; serializeJson(availabilityInfoDoc, availabilityJson); - mqttClient->publish(lightInfo.stateTopic, stateJson); - mqttClient->publish(lightInfo.availabilityTopic, availabilityJson); + Mqtt::publish(lightInfo.stateTopic, stateJson); + Mqtt::publish(lightInfo.availabilityTopic, availabilityJson); } void Light::operatePin() { @@ -159,7 +159,7 @@ void Light::operatePin() { } 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(payload), length); handleCommand(command); }); @@ -241,11 +241,11 @@ void Light::publishCurrentState() { std::string stateJson; serializeJson(stateInfo, stateJson); Serial.println("Publishing current state: " + String(stateJson.c_str())); - mqttClient->publish(lightInfo.stateTopic, stateJson); + Mqtt::publish(lightInfo.stateTopic, stateJson); std::string attributeJson; serializeJson(attributeInfo, attributeJson); 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) { diff --git a/lib/light/light.h b/lib/light/light.h index 793b0d1..f0015a1 100644 --- a/lib/light/light.h +++ b/lib/light/light.h @@ -2,7 +2,6 @@ #include #include "pin.h" -#include "mqtt.h" struct LightInfo { std::string uniqueId; @@ -65,9 +64,9 @@ enum ActiveMode { 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); + 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 subscribeToMqttTopics(); void publishInitialState(); void publishCurrentState(); @@ -97,7 +96,6 @@ private: Pin* pinB; Pin* pinCW; Pin* pinWW; - Mqtt* mqttClient; LightInfo lightInfo; DeviceInfo deviceInfo; LightType lightType = onOff; // Default light type diff --git a/src/main.cpp b/src/main.cpp index d5bc921..8a822dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,7 +40,7 @@ void setup() { network->registerMDNS(); Mqtt::connect("10.238.75.81", 1883, "smart_rgb_client", "mqtt", "mqtt"); delay(1000); // Wait for MQTT connection to stabilize - light = new Light(pinR, pinG, pinB, pinCW, pinWW, mqttClient, "smart_rgb_light"); + light = new Light(pinR, pinG, pinB, pinCW, pinWW, "smart_rgb_light"); initializeScheduler(); }