Browse Source

Issue #75. User defined links between relays and LEDs

fastled
Xose Pérez 7 years ago
parent
commit
833757a3a9
3 changed files with 36 additions and 8 deletions
  1. +19
    -0
      code/espurna/config/hardware.h
  2. +8
    -4
      code/espurna/led.ino
  3. +9
    -4
      code/espurna/relay.ino

+ 19
- 0
code/espurna/config/hardware.h View File

@ -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

+ 8
- 4
code/espurna/led.ino View File

@ -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


+ 9
- 4
code/espurna/relay.ino View File

@ -15,6 +15,7 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
typedef struct {
unsigned char pin;
bool reverse;
unsigned char led;
} relay_t;
std::vector<relay_t> _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


Loading…
Cancel
Save