diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index 2cc34d3d..bb4bf810 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -13,8 +13,10 @@ // - BUTTON_SET_PULLUP: set pullup by software // RELAY#_PIN: GPIO for the n-th relay (1-based, up to 4 relays) // RELAY#_PIN_INVERSE: Relay has inversed logic (closed or ON when pulled down) +// RELAY#_LED: LED number that will be bind to the n-th relay (1-based) // LED#_PIN: GPIO for the n-th LED (1-based, up to 4 LEDs) // LED#_PIN_INVERSE: LED has inversed logic (lit when pulled down) +// WIFI_LED: LED number that will used for WIFI notifications (1-based, defaults to 1) // ----------------------------------------------------------------------------- // Development boards @@ -379,3 +381,20 @@ #ifndef BUTTON4_RELAY #define BUTTON4_RELAY 0 #endif + +#ifndef RELAY1_LED +#define RELAY1_LED 0 +#endif +#ifndef RELAY2_LED +#define RELAY2_LED 0 +#endif +#ifndef RELAY3_LED +#define RELAY3_LED 0 +#endif +#ifndef RELAY4_LED +#define RELAY4_LED 0 +#endif + +#ifndef WIFI_LED +#define WIFI_LED 1 +#endif diff --git a/code/espurna/led.ino b/code/espurna/led.ino index 73970023..d251c243 100644 --- a/code/espurna/led.ino +++ b/code/espurna/led.ino @@ -46,17 +46,19 @@ void ledBlink(unsigned char id, unsigned long delayOff, unsigned long delayOn) { } } +#if WIFI_LED void showStatus() { if (wifiConnected()) { if (WiFi.getMode() == WIFI_AP) { - ledBlink(0, 2500, 2500); + ledBlink(WIFI_LED, 2500, 2500); } else { - ledBlink(0, 4900, 100); + ledBlink(WIFI_LED, 4900, 100); } } else { - ledBlink(0, 500, 500); + ledBlink(WIFI_LED, 500, 500); } } +#endif void ledMQTTCallback(unsigned int type, const char * topic, const char * payload) { @@ -142,7 +144,9 @@ void ledSetup() { } void ledLoop() { - if (ledAuto) showStatus(); + #if WIFI_LED + if (ledAuto) showStatus(); + #endif } #else diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index a701910d..3c93ef7b 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -15,6 +15,7 @@ Copyright (C) 2016-2017 by Xose PĂ©rez typedef struct { unsigned char pin; bool reverse; + unsigned char led; } relay_t; std::vector _relays; @@ -133,6 +134,10 @@ bool relayStatus(unsigned char id, bool status, bool report) { digitalWrite(_relays[id].pin, _relays[id].reverse ? !status : status); #endif + if (_relays[id].led > 0) { + ledStatus(_relays[id].led - 1, status); + } + if (report) relayMQTT(id); if (!recursive) { relayPulse(id); @@ -426,16 +431,16 @@ void relaySetup() { #else #ifdef RELAY1_PIN - _relays.push_back((relay_t) { RELAY1_PIN, RELAY1_PIN_INVERSE }); + _relays.push_back((relay_t) { RELAY1_PIN, RELAY1_PIN_INVERSE, RELAY1_LED }); #endif #ifdef RELAY2_PIN - _relays.push_back((relay_t) { RELAY2_PIN, RELAY2_PIN_INVERSE }); + _relays.push_back((relay_t) { RELAY2_PIN, RELAY2_PIN_INVERSE, RELAY2_LED }); #endif #ifdef RELAY3_PIN - _relays.push_back((relay_t) { RELAY3_PIN, RELAY3_PIN_INVERSE }); + _relays.push_back((relay_t) { RELAY3_PIN, RELAY3_PIN_INVERSE, RELAY3_LED }); #endif #ifdef RELAY4_PIN - _relays.push_back((relay_t) { RELAY4_PIN, RELAY4_PIN_INVERSE }); + _relays.push_back((relay_t) { RELAY4_PIN, RELAY4_PIN_INVERSE, RELAY4_LED }); #endif #endif