[LED RGB] Enable ON OFF Led power display depending on actuator status (#1451)

Switch ON the power LED to green when the Actuator is ON and switch it OFF when the Actuator is OFF
This commit is contained in:
Florian authored and GitHub committed 2023-02-10 18:49:18 -06:00
1 parent 115fdf80aa
commit 6dbcd0d888
2 files changed
+37 -3

No files matched your search

+22 -3
View File
@@ -454,7 +454,13 @@ int lowpowermode = DEFAULT_LOW_POWER_MODE;
# define InfoIndicatorON() digitalWrite(LED_INFO, LED_INFO_ON) # define InfoIndicatorON() digitalWrite(LED_INFO, LED_INFO_ON)
# define InfoIndicatorOFF() digitalWrite(LED_INFO, !LED_INFO_ON) # define InfoIndicatorOFF() digitalWrite(LED_INFO, !LED_INFO_ON)
# define CriticalIndicatorON() // Not used # define CriticalIndicatorON() // Not used
# define CriticalIndicatorON() // Not used
# define PowerIndicatorON() // Not used
# define PowerIndicatorOFF() // Not used
#else // Management of Errors, reception/emission and informations indicators with RGB LED #else // Management of Errors, reception/emission and informations indicators with RGB LED
# if !defined(CONFIG_IDF_TARGET_ESP32S3) && !defined(CONFIG_IDF_TARGET_ESP32C3) //I2S not available yet with Fastled on S3 and C3
# define FASTLED_ESP32_I2S // To avoid ESP32 instabilities https://github.com/FastLED/FastLED/issues/1438
# endif
# include <FastLED.h> # include <FastLED.h>
CRGB leds[FASTLED_IND_NUM_LEDS]; CRGB leds[FASTLED_IND_NUM_LEDS];
# ifdef FASTLED_IND_DATA_GPIO2 // Only used for Critical Indicator # ifdef FASTLED_IND_DATA_GPIO2 // Only used for Critical Indicator
@@ -480,11 +486,20 @@ CRGB leds2[FASTLED_IND_NUM_LEDS];
# define FASTLED_CRITICAL_LED 0 // First Led # define FASTLED_CRITICAL_LED 0 // First Led
# endif # endif
# ifndef FASTLED_IND_DATA_GPIO2
# define SetupIndicators() \ # define SetupIndicators() \
pinMode(RGB_LED_POWER, OUTPUT); \ pinMode(RGB_LED_POWER, OUTPUT); \
digitalWrite(RGB_LED_POWER, HIGH); \ digitalWrite(RGB_LED_POWER, HIGH); \
FastLED.addLeds<FASTLED_IND_TYPE, FASTLED_IND_DATA_GPIO>(leds, FASTLED_IND_NUM_LEDS); \ FastLED.addLeds<FASTLED_IND_TYPE, FASTLED_IND_DATA_GPIO>(leds, FASTLED_IND_NUM_LEDS); \
FastLED.setBrightness(FASTLED_BRIGHTNESS) FastLED.setBrightness(FASTLED_BRIGHTNESS)
# else
# define SetupIndicators() \
pinMode(RGB_LED_POWER, OUTPUT); \
digitalWrite(RGB_LED_POWER, HIGH); \
FastLED.addLeds<FASTLED_IND_TYPE, FASTLED_IND_DATA_GPIO>(leds, FASTLED_IND_NUM_LEDS); \
FastLED.addLeds<FASTLED_IND_TYPE, FASTLED_IND_DATA_GPIO2>(leds2, FASTLED_IND_NUM_LEDS); \
FastLED.setBrightness(FASTLED_BRIGHTNESS)
# endif
# define ErrorIndicatorON() \ # define ErrorIndicatorON() \
leds[FASTLED_ERROR_LED] = CRGB::Orange; \ leds[FASTLED_ERROR_LED] = CRGB::Orange; \
FastLED.show() FastLED.show()
@@ -503,14 +518,18 @@ CRGB leds2[FASTLED_IND_NUM_LEDS];
# define InfoIndicatorOFF() \ # define InfoIndicatorOFF() \
leds[FASTLED_INFO_LED] = CRGB::Black; \ leds[FASTLED_INFO_LED] = CRGB::Black; \
FastLED.show() FastLED.show()
# ifdef FASTLED_IND_DATA_GPIO2 # ifdef FASTLED_IND_DATA_GPIO2 // Used for relay power indicator
// For the critical ON indicator there is no method to turn it off, the only way is to unplug the device // For the critical ON indicator there is no method to turn it off, the only way is to unplug the device
// This enable to have persistence of the indicator to inform the user // This enable to have persistence of the indicator to inform the user
# define CriticalIndicatorON() \ # define CriticalIndicatorON() \
FastLED.addLeds<FASTLED_IND_TYPE, FASTLED_IND_DATA_GPIO2>(leds2, FASTLED_IND_NUM_LEDS); \
FastLED.setBrightness(FASTLED_BRIGHTNESS); \
leds2[FASTLED_INFO_LED] = CRGB::Red; \ leds2[FASTLED_INFO_LED] = CRGB::Red; \
FastLED.show() FastLED.show()
# define PowerIndicatorON() \
leds2[FASTLED_INFO_LED] = CRGB::Green; \
FastLED.show()
# define PowerIndicatorOFF() \
leds2[FASTLED_INFO_LED] = CRGB::Black; \
FastLED.show()
# endif # endif
#endif #endif
+15
View File
@@ -55,6 +55,11 @@ void MQTTtoONOFF(char* topicOri, JsonObject& ONOFFdata) {
Log.notice(F("GPIO number: %d" CR), gpio); Log.notice(F("GPIO number: %d" CR), gpio);
pinMode(gpio, OUTPUT); pinMode(gpio, OUTPUT);
digitalWrite(gpio, boolSWITCHTYPE); digitalWrite(gpio, boolSWITCHTYPE);
if (boolSWITCHTYPE == ACTUATOR_ON) {
PowerIndicatorON();
} else {
PowerIndicatorOFF();
}
// we acknowledge the sending by publishing the value to an acknowledgement topic // we acknowledge the sending by publishing the value to an acknowledgement topic
pub(subjectGTWONOFFtoMQTT, ONOFFdata); pub(subjectGTWONOFFtoMQTT, ONOFFdata);
} else { } else {
@@ -103,6 +108,11 @@ void MQTTtoONOFF(char* topicOri, char* datacallback) {
ON = false; ON = false;
digitalWrite(gpio, ON); digitalWrite(gpio, ON);
if (ON == ACTUATOR_ON) {
PowerIndicatorON();
} else {
PowerIndicatorOFF();
}
// we acknowledge the sending by publishing the value to an acknowledgement topic // we acknowledge the sending by publishing the value to an acknowledgement topic
char b = ON; char b = ON;
pub(subjectGTWONOFFtoMQTT, &b); pub(subjectGTWONOFFtoMQTT, &b);
@@ -161,6 +171,11 @@ void ActuatorTrigger() {
uint8_t level = !digitalRead(ACTUATOR_ONOFF_GPIO); uint8_t level = !digitalRead(ACTUATOR_ONOFF_GPIO);
Log.trace(F("Actuator triggered %d" CR), level); Log.trace(F("Actuator triggered %d" CR), level);
digitalWrite(ACTUATOR_ONOFF_GPIO, level); digitalWrite(ACTUATOR_ONOFF_GPIO, level);
if (level == ACTUATOR_ON) {
PowerIndicatorON();
} else {
PowerIndicatorOFF();
}
// Send the state of the switch to the broker so as to update the status // Send the state of the switch to the broker so as to update the status
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer; StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject ONOFFdata = jsonBuffer.to<JsonObject>(); JsonObject ONOFFdata = jsonBuffer.to<JsonObject>();