[INDICATOR] Dimmable RGB (#1801)
This commit is contained in:
1 parent
cf21aed90c
commit
cf285fba15
5 files changed
+73
-11
No files matched your search
+12
-1
@@ -513,7 +513,10 @@ Adafruit_NeoPixel leds2(ANEOPIX_IND_NUM_LEDS, ANEOPIX_IND_DATA_GPIO2, ANEOPIX_IN
|
||||
# define RGB_LED_POWER -1 // If the RGB Led is linked to GPIO pin for power define it here
|
||||
# endif
|
||||
# ifndef ANEOPIX_BRIGHTNESS
|
||||
# define ANEOPIX_BRIGHTNESS 20 // Set Default RGB brightness to approx 10% (0-255 scale)
|
||||
# define ANEOPIX_BRIGHTNESS 20 // Set Default maximum RGB brightness to approx 10% (0-255 scale)
|
||||
# endif
|
||||
# ifndef DEAULT_ADJ_BRIGHTNESS
|
||||
# define DEAULT_ADJ_BRIGHTNESS 255 // Set Default RGB adjustable brightness
|
||||
# endif
|
||||
# ifndef ANEOPIX_COLOR_SCHEME // allow for different color combinations
|
||||
# define ANEOPIX_COLOR_SCHEME 0
|
||||
@@ -590,18 +593,21 @@ Adafruit_NeoPixel leds2(ANEOPIX_IND_NUM_LEDS, ANEOPIX_IND_DATA_GPIO2, ANEOPIX_IN
|
||||
# endif
|
||||
# define ErrorIndicatorON() \
|
||||
leds.setPixelColor(ANEOPIX_ERROR_LED, ANEOPIX_ERROR); \
|
||||
leds.setBrightness(SYSConfig.rgbbrightness); \
|
||||
leds.show();
|
||||
# define ErrorIndicatorOFF() \
|
||||
leds.setPixelColor(ANEOPIX_ERROR_LED, ANEOPIX_OFF); \
|
||||
leds.show();
|
||||
# define SendReceiveIndicatorON() \
|
||||
leds.setPixelColor(ANEOPIX_SEND_RECEIVE_LED, ANEOPIX_SENDRECEIVE); \
|
||||
leds.setBrightness(SYSConfig.rgbbrightness); \
|
||||
leds.show();
|
||||
# define SendReceiveIndicatorOFF() \
|
||||
leds.setPixelColor(ANEOPIX_SEND_RECEIVE_LED, ANEOPIX_OFF); \
|
||||
leds.show();
|
||||
# define InfoIndicatorON() \
|
||||
leds.setPixelColor(ANEOPIX_INFO_LED, ANEOPIX_INFO); \
|
||||
leds.setBrightness(SYSConfig.rgbbrightness); \
|
||||
leds.show();
|
||||
# define InfoIndicatorOFF() \
|
||||
leds.setPixelColor(ANEOPIX_INFO_LED, ANEOPIX_OFF); \
|
||||
@@ -611,9 +617,11 @@ Adafruit_NeoPixel leds2(ANEOPIX_IND_NUM_LEDS, ANEOPIX_IND_DATA_GPIO2, ANEOPIX_IN
|
||||
// This enable to have persistence of the indicator to inform the user
|
||||
# define CriticalIndicatorON() \
|
||||
leds2.setPixelColor(ANEOPIX_INFO_LED, ANEOPIX_CRITICAL); \
|
||||
leds2.setBrightness(255); \
|
||||
leds2.show();
|
||||
# define PowerIndicatorON() \
|
||||
leds2.setPixelColor(ANEOPIX_INFO_LED, ANEOPIX_INFO); \
|
||||
leds2.setBrightness(SYSConfig.rgbbrightness); \
|
||||
leds2.show();
|
||||
# define PowerIndicatorOFF() \
|
||||
leds2.setPixelColor(ANEOPIX_INFO_LED, ANEOPIX_OFF); \
|
||||
@@ -762,6 +770,9 @@ unsigned long lastDiscovery = 0; // Time of the last discovery to trigger automa
|
||||
struct SYSConfig_s {
|
||||
bool discovery; // HA discovery convention
|
||||
bool ohdiscovery; // OH discovery specificities
|
||||
# ifdef RGB_INDICATORS
|
||||
int rgbbrightness; // brightness of the RGB LED
|
||||
# endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -99,6 +99,14 @@ void ONOFFConfig_fromJson(JsonObject& ONOFFdata){};
|
||||
void ONOFFConfig_load(){};
|
||||
# endif
|
||||
|
||||
void updatePowerIndicator() {
|
||||
if (digitalRead(ACTUATOR_ONOFF_GPIO) == ACTUATOR_ON) {
|
||||
PowerIndicatorON();
|
||||
} else {
|
||||
PowerIndicatorOFF();
|
||||
}
|
||||
}
|
||||
|
||||
void setupONOFF() {
|
||||
# ifdef MAX_TEMP_ACTUATOR
|
||||
xTaskCreate(overLimitTemp, "overLimitTemp", 4000, NULL, 10, NULL);
|
||||
@@ -116,11 +124,7 @@ void setupONOFF() {
|
||||
if (ONOFFConfig.useLastStateOnStart)
|
||||
digitalWrite(ACTUATOR_ONOFF_GPIO, ONOFFConfig.ONOFFState);
|
||||
# endif
|
||||
if (digitalRead(ACTUATOR_ONOFF_GPIO) == ACTUATOR_ON) {
|
||||
PowerIndicatorON();
|
||||
} else {
|
||||
PowerIndicatorOFF();
|
||||
}
|
||||
updatePowerIndicator();
|
||||
Log.trace(F("ZactuatorONOFF setup done" CR));
|
||||
}
|
||||
|
||||
|
||||
@@ -516,6 +516,17 @@ void pubMqttDiscovery() {
|
||||
stateClassNone, //State Class
|
||||
"false", "true" //state_off, state_on
|
||||
);
|
||||
# ifdef RGB_INDICATORS
|
||||
createDiscovery("number", //set Type
|
||||
subjectSYStoMQTT, "SYS: LED Brightness", (char*)getUniqueId("rgbbrightness", "").c_str(), //set state_topic,name,uniqueId
|
||||
will_Topic, "", "{{ value_json.rgbbrightness/2.55}}", //set availability_topic,device_class,value_template,
|
||||
"{\"rgbbrightness\":{{value*2.55}},\"save\":true}", "", "s", //set,payload_on,payload_off,unit_of_meas,
|
||||
0, //set off_delay
|
||||
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoSYSset, //set,payload_available,payload_not available ,is a gateway entity, command topic
|
||||
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain,
|
||||
stateClassNone //State Class
|
||||
);
|
||||
# endif
|
||||
|
||||
# ifdef ZdisplaySSD1306
|
||||
createDiscovery("switch", //set Type
|
||||
|
||||
+35
-5
@@ -772,18 +772,24 @@ void delayWithOTA(long waitMillis) {
|
||||
void SYSConfig_init() {
|
||||
SYSConfig.discovery = true;
|
||||
SYSConfig.ohdiscovery = OpenHABDiscovery;
|
||||
# ifdef RGB_INDICATORS
|
||||
SYSConfig.rgbbrightness = DEAULT_ADJ_BRIGHTNESS;
|
||||
# endif
|
||||
}
|
||||
|
||||
void SYSConfig_fromJson(JsonObject& SYSdata) {
|
||||
Config_update(SYSdata, "discovery", SYSConfig.discovery);
|
||||
Config_update(SYSdata, "ohdiscovery", SYSConfig.ohdiscovery);
|
||||
# ifdef RGB_INDICATORS
|
||||
Config_update(SYSdata, "rgbbrightness", SYSConfig.rgbbrightness);
|
||||
# endif
|
||||
}
|
||||
#else
|
||||
void SYSConfig_init() {}
|
||||
void SYSConfig_fromJson(JsonObject& SYSdata) {}
|
||||
#endif
|
||||
|
||||
#if defined(ESP32) && defined(ZmqttDiscovery)
|
||||
#if defined(ESP32)
|
||||
void SYSConfig_load() {
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
preferences.begin(Gateway_Short_Name, true);
|
||||
@@ -1004,6 +1010,12 @@ void setup() {
|
||||
pinMode(TRIGGER_GPIO, INPUT_PULLUP);
|
||||
checkButton();
|
||||
#endif
|
||||
|
||||
delay(100); //give time to start the flash and avoid issue when reading the preferences
|
||||
|
||||
SYSConfig_init();
|
||||
SYSConfig_load();
|
||||
|
||||
//setup LED status
|
||||
SetupIndicatorError();
|
||||
SetupIndicatorSendReceive();
|
||||
@@ -1011,7 +1023,6 @@ void setup() {
|
||||
SetupIndicators(); // For RGB Leds
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
delay(100); //give time to start the flash and avoid issue when reading the preferences
|
||||
# ifdef ESP8266
|
||||
# ifndef ZgatewaySRFB // if we are not in sonoff rf bridge case we apply the ESP8266 GPIO optimization
|
||||
Serial.end();
|
||||
@@ -1117,9 +1128,6 @@ void setup() {
|
||||
modules.add(ZwebUI);
|
||||
#endif
|
||||
|
||||
SYSConfig_init();
|
||||
SYSConfig_load();
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
if (mqtt_secure) {
|
||||
eClient = new WiFiClientSecure;
|
||||
@@ -2317,6 +2325,9 @@ String stateMeasures() {
|
||||
SYSdata["uptime"] = uptime();
|
||||
|
||||
SYSdata["version"] = OMG_VERSION;
|
||||
# ifdef RGB_INDICATORS
|
||||
SYSdata["rgbbrightness"] = SYSConfig.rgbbrightness;
|
||||
# endif
|
||||
# ifdef ZmqttDiscovery
|
||||
SYSdata["discovery"] = SYSConfig.discovery;
|
||||
SYSdata["ohdiscovery"] = SYSConfig.ohdiscovery;
|
||||
@@ -2817,6 +2828,22 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
||||
stateMeasures();
|
||||
}
|
||||
}
|
||||
# ifdef RGB_INDICATORS
|
||||
if (SYSdata.containsKey("rgbbrightness") && SYSdata["rgbbrightness"].is<float>()) {
|
||||
if (SYSdata["rgbbrightness"] >= 0 && SYSdata["rgbbrightness"] <= 255) {
|
||||
SYSConfig.rgbbrightness = round2(SYSdata["rgbbrightness"]);
|
||||
leds.setBrightness(SYSConfig.rgbbrightness);
|
||||
leds.show();
|
||||
# ifdef ZactuatorONOFF
|
||||
updatePowerIndicator();
|
||||
# endif
|
||||
Log.notice(F("RGB brightness: %d" CR), SYSConfig.rgbbrightness);
|
||||
stateMeasures();
|
||||
} else {
|
||||
Log.error(F("RGB brightness value invalid - ignoring command" CR));
|
||||
}
|
||||
}
|
||||
# endif
|
||||
# ifdef ZmqttDiscovery
|
||||
if (SYSdata.containsKey("ohdiscovery") && SYSdata["ohdiscovery"].is<bool>()) {
|
||||
SYSConfig.ohdiscovery = SYSdata["ohdiscovery"];
|
||||
@@ -2990,6 +3017,9 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
||||
JsonObject jo = jsonBuffer.to<JsonObject>();
|
||||
jo["discovery"] = SYSConfig.discovery;
|
||||
jo["ohdiscovery"] = SYSConfig.ohdiscovery;
|
||||
# ifdef RGB_INDICATORS
|
||||
jo["rgbbrightness"] = SYSConfig.rgbbrightness;
|
||||
# endif
|
||||
// Save config into NVS (non-volatile storage)
|
||||
String conf = "";
|
||||
serializeJson(jsonBuffer, conf);
|
||||
|
||||
Reference in new issue
Block a user