Skip to content

Commit

Permalink
[LED] Add LED STRIP macros and a third Addressable pin (#2063)
Browse files Browse the repository at this point in the history
* [LED] Add LED STRIP macros and a third Addressable pin

---------

Co-authored-by: Florian <[email protected]>
  • Loading branch information
1technophile and 1technophile authored Sep 20, 2024
1 parent 0b4c6ef commit 0d338cc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
4 changes: 4 additions & 0 deletions lib/LEDManager/LEDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ void LEDManager::setMode(int stripIndex, int ledIndex, Mode mode, uint32_t color
} else if (ledIndex >= 0 && ledIndex < ledStrips[stripIndex].ledStates.size()) {
setModeForSingleLED(stripIndex, ledIndex, mode, color, durationOrBlinkCount);
}
} else if (stripIndex == -1) {
for (int i = 0; i < ledStrips.size(); i++) {
setMode(i, ledIndex, mode, color, durationOrBlinkCount);
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/LEDManager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ void setup() {

void loop() {
#ifdef LED_ADDRESSABLE
// Set all LEDs on the strip to static green
// Set all LEDs on the first strip to static green
ledManager.setMode(0, -1, LEDManager::STATIC, LED_COLOR_GREEN);

// Blink first 5 LEDs red for 3 times
// Blink first 5 LEDs red for 3 times on the first strip
for (int i = 0; i < 5; i++) {
ledManager.setMode(0, i, LEDManager::BLINK, LED_COLOR_RED, 3);
}
#else
// Set first LED to static green
ledManager.setMode(0, 0, LEDManager::STATIC, LED_COLOR_GREEN);

// Blink second LED red
// Blink second strip LED red
ledManager.setMode(1, 0, LEDManager::BLINK, LED_COLOR_RED, 3);
#endif

Expand Down
18 changes: 16 additions & 2 deletions main/User_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,22 @@ ss_cnt_parameters cnt_parameters_array[cnt_parameters_array_size] = {
#ifndef LED_NETWORK
# define LED_NETWORK 0
#endif
#ifndef LED_POWER
# define LED_POWER -1

// LED Strip index
#ifndef STRIP_ERROR
# define STRIP_ERROR 0
#endif
#ifndef STRIP_PROCESSING
# define STRIP_PROCESSING 0
#endif
#ifndef STRIP_BROKER
# define STRIP_BROKER 0
#endif
#ifndef STRIP_NETWORK
# define STRIP_NETWORK 0
#endif
#ifndef STRIP_POWER
# define STRIP_POWER 0
#endif

// Single standard LED pin
Expand Down
29 changes: 16 additions & 13 deletions main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1230,65 +1230,65 @@ void updateAndHandleLEDsTask() {
static GatewayState previousGatewayState;
if (previousGatewayState != gatewayState) {
#ifdef LED_POWER
ledManager.setMode(0, LED_POWER, LEDManager::STATIC, LED_POWER_COLOR, -1);
ledManager.setMode(STRIP_POWER, LED_POWER, LEDManager::STATIC, LED_POWER_COLOR, -1);
#endif
switch (gatewayState) {
case PROCESSING:
#ifdef LED_PROCESSING
ledManager.setMode(0, LED_PROCESSING, LEDManager::BLINK, LED_PROCESSING_COLOR, 3);
ledManager.setMode(STRIP_PROCESSING, LED_PROCESSING, LEDManager::BLINK, LED_PROCESSING_COLOR, 3);
#endif
break;
case WAITING_ONBOARDING:
#ifdef LED_BROKER
ledManager.setMode(0, LED_BROKER, LEDManager::STATIC, LED_WAITING_ONBOARD_COLOR, -1);
ledManager.setMode(STRIP_BROKER, LED_BROKER, LEDManager::STATIC, LED_WAITING_ONBOARD_COLOR, -1);
#endif
break;
case ONBOARDING:
#ifdef LED_BROKER
ledManager.setMode(0, LED_BROKER, LEDManager::STATIC, LED_ONBOARD_COLOR, -1);
ledManager.setMode(STRIP_BROKER, LED_BROKER, LEDManager::STATIC, LED_ONBOARD_COLOR, -1);
#endif
break;
case NTWK_CONNECTED:
#ifdef LED_NETWORK
ledManager.setMode(0, LED_NETWORK, LEDManager::STATIC, LED_NETWORK_OK_COLOR, -1);
ledManager.setMode(STRIP_NETWORK, LED_NETWORK, LEDManager::STATIC, LED_NETWORK_OK_COLOR, -1);
#endif
break;
case BROKER_CONNECTED:
#ifdef LED_BROKER
ledManager.setMode(0, LED_BROKER, LEDManager::STATIC, LED_BROKER_OK_COLOR, -1);
ledManager.setMode(STRIP_BROKER, LED_BROKER, LEDManager::STATIC, LED_BROKER_OK_COLOR, -1);
#endif
break;
case NTWK_DISCONNECTED:
#ifdef LED_NETWORK
ledManager.setMode(0, LED_NETWORK, LEDManager::BLINK, LED_NETWORK_ERROR_COLOR, -1);
ledManager.setMode(STRIP_NETWORK, LED_NETWORK, LEDManager::BLINK, LED_NETWORK_ERROR_COLOR, -1);
#endif
break;
case BROKER_DISCONNECTED:
#ifdef LED_BROKER
ledManager.setMode(0, LED_BROKER, LEDManager::BLINK, LED_BROKER_ERROR_COLOR, -1);
ledManager.setMode(STRIP_BROKER, LED_BROKER, LEDManager::BLINK, LED_BROKER_ERROR_COLOR, -1);
#endif
break;
case SLEEPING:
ledManager.setMode(0, -1, LEDManager::OFF, 0, -1);
ledManager.setMode(-1, -1, LEDManager::OFF, 0, -1);
break;
case OFFLINE:
#ifdef LED_NETWORK
ledManager.setMode(0, LED_NETWORK, LEDManager::BLINK, LED_OFFLINE_COLOR, -1);
ledManager.setMode(STRIP_NETWORK, LED_NETWORK, LEDManager::BLINK, LED_OFFLINE_COLOR, -1);
#endif
break;
case LOCAL_OTA_IN_PROGRESS:
#ifdef LED_PROCESSING
ledManager.setMode(0, LED_PROCESSING, LEDManager::BLINK, LED_OTA_LOCAL_COLOR, -1);
ledManager.setMode(STRIP_PROCESSING, LED_PROCESSING, LEDManager::BLINK, LED_OTA_LOCAL_COLOR, -1);
#endif
break;
case REMOTE_OTA_IN_PROGRESS:
#ifdef LED_PROCESSING
ledManager.setMode(0, LED_PROCESSING, LEDManager::BLINK, LED_OTA_REMOTE_COLOR, -1);
ledManager.setMode(STRIP_PROCESSING, LED_PROCESSING, LEDManager::BLINK, LED_OTA_REMOTE_COLOR, -1);
#endif
break;
case ERROR:
#ifdef LED_ERROR
ledManager.setMode(0, LED_ERROR, LEDManager::BLINK, LED_ERROR_COLOR, 3);
ledManager.setMode(STRIP_ERROR, LED_ERROR, LEDManager::BLINK, LED_ERROR_COLOR, 3);
#endif
break;
default:
Expand Down Expand Up @@ -1323,6 +1323,9 @@ void setup() {
# endif
# ifdef LED_ADDRESSABLE_PIN2
ledManager.addLEDStrip(LED_ADDRESSABLE_PIN2, LED_ADDRESSABLE_NUM);
# endif
# ifdef LED_ADDRESSABLE_PIN3
ledManager.addLEDStrip(LED_ADDRESSABLE_PIN3, LED_ADDRESSABLE_NUM);
# endif
ledManager.setBrightness(SYSConfig.rgbbrightness);
#elif LED_PIN
Expand Down

0 comments on commit 0d338cc

Please sign in to comment.