Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ONOFF] - Improve Led display #1430

Merged
merged 1 commit into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion main/User_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,13 @@ int lowpowermode = DEFAULT_LOW_POWER_MODE;
# define SendReceiveIndicatorOFF() digitalWrite(LED_SEND_RECEIVE, !LED_SEND_RECEIVE_ON)
# define InfoIndicatorON() digitalWrite(LED_INFO, LED_INFO_ON)
# define InfoIndicatorOFF() digitalWrite(LED_INFO, !LED_INFO_ON)
# define CriticalIndicatorON() // Not used
#else // Management of Errors, reception/emission and informations indicators with RGB LED
# include <FastLED.h>
CRGB leds[FASTLED_IND_NUM_LEDS];
# ifdef FASTLED_IND_DATA_GPIO2 // Only used for Critical Indicator
CRGB leds2[FASTLED_IND_NUM_LEDS];
# endif
# ifndef RGB_LED_POWER
# define RGB_LED_POWER -1 // If the RGB Led is linked to GPIO pin for power define it here
# endif
Expand All @@ -471,12 +475,15 @@ CRGB leds[FASTLED_IND_NUM_LEDS];
# ifndef FASTLED_ERROR_LED
# define FASTLED_ERROR_LED 0 // First Led
# endif
# ifndef FASTLED_CRITICAL_LED
# define FASTLED_CRITICAL_LED 0 // First Led
# endif

# 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.setBrightness(FASTLED_BRIGHTNESS);
FastLED.setBrightness(FASTLED_BRIGHTNESS)
# define ErrorIndicatorON() \
leds[FASTLED_ERROR_LED] = CRGB::Orange; \
FastLED.show()
Expand All @@ -495,6 +502,15 @@ CRGB leds[FASTLED_IND_NUM_LEDS];
# define InfoIndicatorOFF() \
leds[FASTLED_INFO_LED] = CRGB::Black; \
FastLED.show()
# ifdef FASTLED_IND_DATA_GPIO2
// 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
# 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; \
FastLED.show()
# endif
#endif

#ifdef ESP8266
Expand Down
26 changes: 10 additions & 16 deletions main/ZactuatorONOFF.ino
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,11 @@ void overLimitTemp(void* pvParameters) {
float internalTempc = intTemperatureRead();
Log.trace(F("Internal temperature of the ESP32 %F" CR), internalTempc);
// We switch OFF the actuator if the temperature of the ESP32 is more than MAX_TEMP_ACTUATOR two consecutive times, so as to avoid false single readings to trigger the relay OFF.
if (internalTempc > MAX_TEMP_ACTUATOR && previousInternalTempc > MAX_TEMP_ACTUATOR && digitalRead(ACTUATOR_ONOFF_GPIO) == ACTUATOR_ON) {
Log.error(F("[ActuatorONOFF] OverTemperature detected ( %F > %F ) switching OFF Actuator" CR), internalTempc, MAX_TEMP_ACTUATOR);
ActuatorTrigger();
for (int i = 0; i < 30; i++) {
ErrorIndicatorON();
vTaskDelay(200);
ErrorIndicatorOFF();
vTaskDelay(200);
if (internalTempc > MAX_TEMP_ACTUATOR && previousInternalTempc > MAX_TEMP_ACTUATOR) {
if (digitalRead(ACTUATOR_ONOFF_GPIO) == ACTUATOR_ON) { // This could be with thew previous condition, but it is better to trigger the digitalRead only if the previous condition is met
Log.error(F("[ActuatorONOFF] OverTemperature detected ( %F > %F ) switching OFF Actuator" CR), internalTempc, MAX_TEMP_ACTUATOR);
ActuatorTrigger();
CriticalIndicatorON();
}
}
previousInternalTempc = internalTempc;
Expand All @@ -143,14 +140,11 @@ void overLimitCurrent(void* pvParameters) {
float current = getRN8209current();
Log.trace(F("RN8209 Current %F" CR), current);
// We switch OFF the actuator if the current of the RN8209 is more than MAX_CURRENT_ACTUATOR.
if (current > MAX_CURRENT_ACTUATOR && digitalRead(ACTUATOR_ONOFF_GPIO) == ACTUATOR_ON) {
Log.error(F("[ActuatorONOFF] OverCurrent detected ( %F > %F ) switching OFF Actuator" CR), current, MAX_CURRENT_ACTUATOR);
ActuatorTrigger();
for (int i = 0; i < 30; i++) {
ErrorIndicatorON();
vTaskDelay(200);
ErrorIndicatorOFF();
vTaskDelay(200);
if (current > MAX_CURRENT_ACTUATOR) {
if (digitalRead(ACTUATOR_ONOFF_GPIO) == ACTUATOR_ON) { // This could be with thew previous condition, but it is better to trigger the digitalRead only if the previous condition is met
Log.error(F("[ActuatorONOFF] OverCurrent detected ( %F > %F ) switching OFF Actuator" CR), current, MAX_CURRENT_ACTUATOR);
ActuatorTrigger();
CriticalIndicatorON();
}
}
vTaskDelay(TimeBetweenReadingCurrent);
Expand Down
2 changes: 1 addition & 1 deletion main/config_ONOFF.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extern void MQTTtoONOFF(char* topicOri, JsonObject& RFdata);
# define TimeBetweenReadingIntTemp 5000 // Time interval between internal temp measurement to switch off the relay if MAX_TEMP_ACTUATOR is reached
#endif
#ifndef TimeBetweenReadingCurrent
# define TimeBetweenReadingCurrent 1000 // Time interval between internal temp measurement to switch off the relay if MAX_TEMP_ACTUATOR is reached
# define TimeBetweenReadingCurrent 1000 // Time interval between internal current measurement to switch off the relay if MAX_TEMP_ACTUATOR is reached
#endif
/*-------------------PIN DEFINITIONS----------------------*/
// default pin, if not set into the MQTT json
Expand Down