Skip to content

Commit

Permalink
add LED_POWER_INVERT build option (#56)
Browse files Browse the repository at this point in the history
* add LED_POWER_INVERT build option
change default state to turn LED power off on ESP boot

* fix duplicate build flag

* revert default to powerOn

* define power functions with macros

* make suggested changes

* Changes

* Update

---------

Co-authored-by: Awawa <[email protected]>
  • Loading branch information
jochocki and awawa-dev authored Apr 14, 2024
1 parent b5e0d0f commit 8041360
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
13 changes: 10 additions & 3 deletions include/powercontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
{
Expand All @@ -61,7 +68,7 @@ class
}
}

inline void powerOff()
inline void SET_RELAY_LOW()
{
if (currentPowerPinMode != LOW)
{
Expand Down
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
10 changes: 9 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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"


Expand Down

0 comments on commit 8041360

Please sign in to comment.