Compile time options for Multi Relay & PWM Fan

This commit is contained in:
Blaz Kristan 2022-04-29 09:56:48 +02:00
parent 1a513c7bbf
commit 23d39e5366
4 changed files with 21 additions and 7 deletions

View File

@ -19,8 +19,8 @@ You will also need `-D USERMOD_DALLASTEMPERATURE`.
All of the parameters are configured during run-time using Usermods settings page. All of the parameters are configured during run-time using Usermods settings page.
This includes: This includes:
* PWM output pin * PWM output pin (can be configured at compile time `-D PWM_PIN=xx`)
* tacho input pin * tacho input pin (can be configured at compile time `-D TACHO_PIN=xx`)
* sampling frequency in seconds * sampling frequency in seconds
* threshold temperature in degees C * threshold temperature in degees C

View File

@ -10,6 +10,13 @@
// https://github.com/KlausMu/esp32-fan-controller/tree/main/src // https://github.com/KlausMu/esp32-fan-controller/tree/main/src
// adapted for WLED usermod by @blazoncek // adapted for WLED usermod by @blazoncek
#ifndef TACHO_PIN
#define TACHO_PIN -1
#endif
#ifndef PWM_PIN
#define PWM_PIN -1
#endif
// tacho counter // tacho counter
static volatile unsigned long counter_rpm = 0; static volatile unsigned long counter_rpm = 0;
@ -37,8 +44,8 @@ class PWMFanUsermod : public Usermod {
#endif #endif
// configurable parameters // configurable parameters
int8_t tachoPin = -1; int8_t tachoPin = TACHO_PIN;
int8_t pwmPin = -1; int8_t pwmPin = PWM_PIN;
uint8_t tachoUpdateSec = 30; uint8_t tachoUpdateSec = 30;
float targetTemperature = 25.0; float targetTemperature = 25.0;
uint8_t minPWMValuePct = 50; uint8_t minPWMValuePct = 50;

View File

@ -81,11 +81,13 @@ void registerUsermods()
Usermod can be configured in Usermods settings page. Usermod can be configured in Usermods settings page.
* `enabled` - enable/disable usermod * `enabled` - enable/disable usermod
* `pin` - GPIO pin where relay is attached to ESP * `pin` - GPIO pin where relay is attached to ESP (can be configured at compile time `-D MULTI_RELAY_PINS=xx,xx,...`)
* `delay-s` - delay in seconds after on/off command is received * `delay-s` - delay in seconds after on/off command is received
* `active-high` - toggle high/low activation of relay (can be used to reverse relay states) * `active-high` - toggle high/low activation of relay (can be used to reverse relay states)
* `external` - if enabled WLED does not control relay, it can only be triggered by external command (MQTT, HTTP, JSON or button) * `external` - if enabled WLED does not control relay, it can only be triggered by external command (MQTT, HTTP, JSON or button)
* `button` - button (from LED Settings) that controls this relay * `button` - button (from LED Settings) that controls this relay
* `broadcast`- time in seconds between state broadcasts using MQTT
* `HA-discovery`- enable Home Assistant auto discovery
If there is no MultiRelay section, just save current configuration and re-open Usermods settings page. If there is no MultiRelay section, just save current configuration and re-open Usermods settings page.

View File

@ -6,6 +6,10 @@
#define MULTI_RELAY_MAX_RELAYS 4 #define MULTI_RELAY_MAX_RELAYS 4
#endif #endif
#ifndef MULTI_RELAY_PINS
#define MULTI_RELAY_PINS -1
#endif
#define WLED_DEBOUNCE_THRESHOLD 50 //only consider button input of at least 50ms as valid (debouncing) #define WLED_DEBOUNCE_THRESHOLD 50 //only consider button input of at least 50ms as valid (debouncing)
#define ON true #define ON true
@ -177,8 +181,9 @@ class MultiRelay : public Usermod {
* constructor * constructor
*/ */
MultiRelay() { MultiRelay() {
const int8_t defPins[] = {MULTI_RELAY_PINS};
for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) { for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
_relay[i].pin = -1; _relay[i].pin = i<sizeof(defPins) ? defPins[i] : -1;
_relay[i].delay = 0; _relay[i].delay = 0;
_relay[i].mode = false; _relay[i].mode = false;
_relay[i].active = false; _relay[i].active = false;
@ -619,7 +624,7 @@ class MultiRelay : public Usermod {
DEBUG_PRINTLN(F(" config (re)loaded.")); DEBUG_PRINTLN(F(" config (re)loaded."));
} }
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features // use "return !top["newestParameter"].isNull();" when updating Usermod with new features
return !top[FPSTR(_broadcast)].isNull(); return !top[FPSTR(_HAautodiscovery)].isNull();
} }
/** /**