Skip to content

Commit

Permalink
Do not define LED pins if not explicitly stated
Browse files Browse the repository at this point in the history
Add LED_BUILTIN when available
  • Loading branch information
1technophile committed Mar 21, 2023
1 parent 189b095 commit d437359
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 31 deletions.
93 changes: 63 additions & 30 deletions main/User_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,65 +416,95 @@ int lowpowermode = DEFAULT_LOW_POWER_MODE;
#ifndef RGB_INDICATORS // Management of Errors, reception/emission and informations indicators with basic LED
/*-------------DEFINE PINs FOR STATUS LEDs----------------*/
# ifndef LED_SEND_RECEIVE
# ifdef LED_BUILTIN
# define LED_SEND_RECEIVE LED_BUILTIN
# endif
# ifdef ESP8266
# define LED_SEND_RECEIVE 40
//# define LED_SEND_RECEIVE 40
# elif ESP32
# define LED_SEND_RECEIVE 40
//# define LED_SEND_RECEIVE 40
# elif __AVR_ATmega2560__ //arduino mega
# define LED_SEND_RECEIVE 40
//# define LED_SEND_RECEIVE 40
# else //arduino uno/nano
# define LED_SEND_RECEIVE 40
//# define LED_SEND_RECEIVE 40
# endif
# endif
# ifndef LED_SEND_RECEIVE_ON
# define LED_SEND_RECEIVE_ON HIGH
# endif
# ifndef LED_ERROR
# ifdef LED_BUILTIN
# define LED_ERROR LED_BUILTIN
# endif
# ifdef ESP8266
# define LED_ERROR 42
//# define LED_ERROR 42
# elif ESP32
# define LED_ERROR 42
//# define LED_ERROR 42
# elif __AVR_ATmega2560__ //arduino mega
# define LED_ERROR 42
//# define LED_ERROR 42
# else //arduino uno/nano
# define LED_ERROR 42
//# define LED_ERROR 42
# endif
# endif
# ifndef LED_ERROR_ON
# define LED_ERROR_ON HIGH
# endif
# ifndef LED_INFO
# ifdef LED_BUILTIN
# define LED_INFO LED_BUILTIN
# endif
# ifdef ESP8266
# define LED_INFO 44
//# define LED_INFO 44
# elif ESP32
# define LED_INFO 44
//# define LED_INFO 44
# elif __AVR_ATmega2560__ //arduino mega
# define LED_INFO 44
//# define LED_INFO 44
# else //arduino uno/nano
# define LED_INFO 44
//# define LED_INFO 44
# endif
# endif
# ifndef LED_INFO_ON
# define LED_INFO_ON HIGH
# endif
# define SetupIndicators() \
pinMode(LED_SEND_RECEIVE, OUTPUT); \
pinMode(LED_INFO, OUTPUT); \
pinMode(LED_ERROR, OUTPUT); \
SendReceiveIndicatorOFF(); \
InfoIndicatorOFF(); \
ErrorIndicatorOFF();

# define ErrorIndicatorON() digitalWrite(LED_ERROR, LED_ERROR_ON)
# define ErrorIndicatorOFF() digitalWrite(LED_ERROR, !LED_ERROR_ON)
# define SendReceiveIndicatorON() digitalWrite(LED_SEND_RECEIVE, LED_SEND_RECEIVE_ON)
# 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
# define CriticalIndicatorON() // Not used
# define PowerIndicatorON() // Not used
# define PowerIndicatorOFF() // Not used

# ifdef LED_ERROR
# define SetupIndicatorError() \
pinMode(LED_ERROR, OUTPUT); \
ErrorIndicatorOFF();
# define ErrorIndicatorON() digitalWrite(LED_ERROR, LED_ERROR_ON)
# define ErrorIndicatorOFF() digitalWrite(LED_ERROR, !LED_ERROR_ON)
# else
# define SetupIndicatorError()
# define ErrorIndicatorON()
# define ErrorIndicatorOFF()
# endif
# ifdef LED_SEND_RECEIVE
# define SetupIndicatorSendReceive() \
pinMode(LED_SEND_RECEIVE, OUTPUT); \
SendReceiveIndicatorOFF();
# define SendReceiveIndicatorON() digitalWrite(LED_SEND_RECEIVE, LED_SEND_RECEIVE_ON)
# define SendReceiveIndicatorOFF() digitalWrite(LED_SEND_RECEIVE, !LED_SEND_RECEIVE_ON)
# else
# define SetupIndicatorSendReceive()
# define SendReceiveIndicatorON()
# define SendReceiveIndicatorOFF()
# endif
# ifdef LED_INFO
# define SetupIndicatorInfo() \
pinMode(LED_INFO, OUTPUT); \
InfoIndicatorOFF();
# define InfoIndicatorON() digitalWrite(LED_INFO, LED_INFO_ON)
# define InfoIndicatorOFF() digitalWrite(LED_INFO, !LED_INFO_ON)
# else
# define SetupIndicatorInfo()
# define InfoIndicatorON()
# define InfoIndicatorOFF()
# endif
# define CriticalIndicatorON() // Not used
# define CriticalIndicatorON() // Not used
# define PowerIndicatorON() // Not used
# define PowerIndicatorOFF() // Not used
# define SetupIndicators() // Not used
#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
Expand Down Expand Up @@ -549,6 +579,9 @@ CRGB leds2[FASTLED_IND_NUM_LEDS];
leds2[FASTLED_INFO_LED] = CRGB::Black; \
FastLED.show()
# endif
# define SetupIndicatorInfo()
# define SetupIndicatorSendReceive()
# define SetupIndicatorError()
#endif

#ifdef ESP8266
Expand Down
5 changes: 4 additions & 1 deletion main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,10 @@ void setup() {
checkButton();
#endif
//setup LED status
SetupIndicators();
SetupIndicatorError();
SetupIndicatorSendReceive();
SetupIndicatorInfo();
SetupIndicators(); // For RGB Leds

#if defined(ESP8266) || defined(ESP32)
# ifdef ESP8266
Expand Down

0 comments on commit d437359

Please sign in to comment.