From 94d754e63a69f1279f1729adcbc01ef7534022b3 Mon Sep 17 00:00:00 2001 From: Chris Burrows Date: Wed, 1 Nov 2023 16:52:26 +0000 Subject: [PATCH] Allow more compile time settings --- usermods/multi_relay/readme.md | 13 +++++++++ usermods/multi_relay/usermod_multi_relay.h | 32 ++++++++++++++++++---- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/usermods/multi_relay/readme.md b/usermods/multi_relay/readme.md index 71a54070..05db0fbc 100644 --- a/usermods/multi_relay/readme.md +++ b/usermods/multi_relay/readme.md @@ -47,6 +47,19 @@ or You can override the default maximum number of relays (which is 4) by defining MULTI_RELAY_MAX_RELAYS. +Some settings can be defined (defaults) at compile time by setting the following defines: + +MULTI_RELAY_HA_DISCOVERY true or false + +The following definitions should be a list of values (maximum number of entries is MULTI_RELAY_MAX_RELAYS) that will be applied to the relays in order: +(e.g. assuming MULTI_RELAY_MAX_RELAYS=2) + +MULTI_RELAY_DELAYS 0,0 +MULTI_RELAY_EXTERNALS false,true +MULTI_RELAY_INVERTS false,false + +These can be set via your platformio_override.ini file or as #define in your my_config.h (remember to set WLED_USE_MY_CONFIG in your platformio_override.ini) + Example **usermods_list.cpp**: ```cpp diff --git a/usermods/multi_relay/usermod_multi_relay.h b/usermods/multi_relay/usermod_multi_relay.h index 7234df90..0bf1871c 100644 --- a/usermods/multi_relay/usermod_multi_relay.h +++ b/usermods/multi_relay/usermod_multi_relay.h @@ -2,6 +2,8 @@ #include "wled.h" +#define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) + #ifndef MULTI_RELAY_MAX_RELAYS #define MULTI_RELAY_MAX_RELAYS 4 #else @@ -19,6 +21,22 @@ #define MULTI_RELAY_ENABLED true #endif +#ifndef MULTI_RELAY_HA_DISCOVERY + #define MULTI_RELAY_HA_DISCOVERY false +#endif + +#ifndef MULTI_RELAY_DELAYS + #define MULTI_RELAY_DELAYS 0 +#endif + +#ifndef MULTI_RELAY_EXTERNALS + #define MULTI_RELAY_EXTERNALS false +#endif + +#ifndef MULTI_RELAY_INVERTS + #define MULTI_RELAY_INVERTS false +#endif + #define WLED_DEBOUNCE_THRESHOLD 50 //only consider button input of at least 50ms as valid (debouncing) #define ON true @@ -343,18 +361,22 @@ MultiRelay::MultiRelay() , initDone(false) , usePcf8574(USE_PCF8574) , addrPcf8574(PCF8574_ADDRESS) - , HAautodiscovery(false) + , HAautodiscovery(MULTI_RELAY_HA_DISCOVERY) , periodicBroadcastSec(60) , lastBroadcast(0) { const int8_t defPins[] = {MULTI_RELAY_PINS}; + const int8_t relayDelays[] = {MULTI_RELAY_DELAYS}; + const bool relayExternals[] = {MULTI_RELAY_EXTERNALS}; + const bool relayInverts[] = {MULTI_RELAY_INVERTS}; + for (size_t i=0; i