diff --git a/README.md b/README.md index 1e0292e..3998e33 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ Implementation example: You can configure LED power pin in the `platformio.ini` to power off LEDs while not in use. Review the comments at the top of the file: * `LED_POWER_PIN` - This is the data pin external power control +* `LED_POWER_INVERT` - This inverts the output of the exernal power control pin. If set to `false`, the pin state will be low when the relay is turned off. If set to `true`, the pin state will be high when the relay is off. If not defined, default is `false`. Note: For static color configuration this mechanism will turn off the LEDs. To counter this enable "Continuous Output" in HyperHDR "Smoothing" module. For esp32 and relay control, you may want to disable the "Handshake" option in the Adalight HyperHDR driver to avoid the relay immediately shutting down when resetting the device while initializing the connection. diff --git a/include/powercontrol.h b/include/powercontrol.h index 6559f65..1e3cd9b 100644 --- a/include/powercontrol.h +++ b/include/powercontrol.h @@ -28,6 +28,13 @@ #ifndef POWERCONTROL_H #define POWERCONTROL_H +#if LED_POWER_INVERT + #define SET_RELAY_HIGH() powerOff() + #define SET_RELAY_LOW() powerOn() +#else + #define SET_RELAY_HIGH() powerOn() + #define SET_RELAY_LOW() powerOff() +#endif /** * @brief Contains logic for turning on and off the power to leds using external relay @@ -49,10 +56,10 @@ class { pinMode(LED_POWER_PIN, OUTPUT); lastPowerOffResetTimestamp = millis(); - powerOn(); + powerOff(); } - inline void powerOn() + inline void SET_RELAY_HIGH() { if (currentPowerPinMode != HIGH) { @@ -61,7 +68,7 @@ class } } - inline void powerOff() + inline void SET_RELAY_LOW() { if (currentPowerPinMode != LOW) { diff --git a/platformio.ini b/platformio.ini index 49e80b0..1c4b110 100644 --- a/platformio.ini +++ b/platformio.ini @@ -3,6 +3,7 @@ ; DATA_PIN = pin/GPIO for the LED strip data channel, specific [board] section ; CLOCK_PIN = pin/GPIO for the LED strip clock channel, specific [board] section ; LED_POWER_PIN = pin/GPIO for external relay power control, it will turn off (low state) if no serial data is received after 5 seconds +; LED_POWER_INVERT = if defined: off state is a high signal for the power relay, on state is a low signal ; MULTI-SEGMENT SUPPORT ; You can define second segment to handle. Add following parameters (with -D prefix to the build_flags sections). diff --git a/src/main.cpp b/src/main.cpp index 561e737..ad5ca15 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -140,6 +140,9 @@ #endif #pragma message(VAR_NAME_VALUE2(LED_DRIVER)) #pragma message(VAR_NAME_VALUE(SECOND_SEGMENT_START_INDEX)) + #ifdef SECOND_SEGMENT_REVERSED + #pragma message(VAR_NAME_VALUE(SECOND_SEGMENT_REVERSED)) + #endif #pragma message(VAR_NAME_VALUE(SECOND_SEGMENT_DATA_PIN)) #ifdef SECOND_SEGMENT_CLOCK_PIN #pragma message(VAR_NAME_VALUE(SECOND_SEGMENT_CLOCK_PIN)) @@ -157,11 +160,16 @@ #define SerialPort Serial -#if defined(LED_POWER_PIN) +#ifdef LED_POWER_PIN #pragma message(VAR_NAME_VALUE(LED_POWER_PIN)) + #ifdef LED_POWER_INVERT + #pragma message(VAR_NAME_VALUE(LED_POWER_INVERT)) + #endif #include "powercontrol.h" #endif + + #include "main.h"