mirror of
https://github.com/wled/WLED.git
synced 2025-04-25 23:37:18 +00:00
Merge pull request #3920 from Suxsem/relay-3-states
Relay open drain output (allow esp32 to drive 5v relay modules)
This commit is contained in:
commit
b3acc97d03
@ -59,6 +59,7 @@ build_flags = ${common.build_flags} ${esp8266.build_flags}
|
|||||||
; -D IRPIN=4
|
; -D IRPIN=4
|
||||||
; -D RLYPIN=12
|
; -D RLYPIN=12
|
||||||
; -D RLYMDE=1
|
; -D RLYMDE=1
|
||||||
|
; -D RLYODRAIN=0
|
||||||
; -D LED_BUILTIN=2 # GPIO of built-in LED
|
; -D LED_BUILTIN=2 # GPIO of built-in LED
|
||||||
;
|
;
|
||||||
; Limit max buses
|
; Limit max buses
|
||||||
|
@ -379,7 +379,7 @@ void handleIO()
|
|||||||
esp32RMTInvertIdle();
|
esp32RMTInvertIdle();
|
||||||
#endif
|
#endif
|
||||||
if (rlyPin>=0) {
|
if (rlyPin>=0) {
|
||||||
pinMode(rlyPin, OUTPUT);
|
pinMode(rlyPin, rlyOpenDrain ? OUTPUT_OPEN_DRAIN : OUTPUT);
|
||||||
digitalWrite(rlyPin, rlyMde);
|
digitalWrite(rlyPin, rlyMde);
|
||||||
}
|
}
|
||||||
offMode = false;
|
offMode = false;
|
||||||
@ -400,7 +400,7 @@ void handleIO()
|
|||||||
esp32RMTInvertIdle();
|
esp32RMTInvertIdle();
|
||||||
#endif
|
#endif
|
||||||
if (rlyPin>=0) {
|
if (rlyPin>=0) {
|
||||||
pinMode(rlyPin, OUTPUT);
|
pinMode(rlyPin, rlyOpenDrain ? OUTPUT_OPEN_DRAIN : OUTPUT);
|
||||||
digitalWrite(rlyPin, !rlyMde);
|
digitalWrite(rlyPin, !rlyMde);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,12 +335,14 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
|||||||
CJSON(irApplyToAllSelected, hw["ir"]["sel"]);
|
CJSON(irApplyToAllSelected, hw["ir"]["sel"]);
|
||||||
|
|
||||||
JsonObject relay = hw[F("relay")];
|
JsonObject relay = hw[F("relay")];
|
||||||
|
|
||||||
|
rlyOpenDrain = relay[F("odrain")] | rlyOpenDrain;
|
||||||
int hw_relay_pin = relay["pin"] | -2;
|
int hw_relay_pin = relay["pin"] | -2;
|
||||||
if (hw_relay_pin > -2) {
|
if (hw_relay_pin > -2) {
|
||||||
pinManager.deallocatePin(rlyPin, PinOwner::Relay);
|
pinManager.deallocatePin(rlyPin, PinOwner::Relay);
|
||||||
if (pinManager.allocatePin(hw_relay_pin,true, PinOwner::Relay)) {
|
if (pinManager.allocatePin(hw_relay_pin,true, PinOwner::Relay)) {
|
||||||
rlyPin = hw_relay_pin;
|
rlyPin = hw_relay_pin;
|
||||||
pinMode(rlyPin, OUTPUT);
|
pinMode(rlyPin, rlyOpenDrain ? OUTPUT_OPEN_DRAIN : OUTPUT);
|
||||||
} else {
|
} else {
|
||||||
rlyPin = -1;
|
rlyPin = -1;
|
||||||
}
|
}
|
||||||
@ -868,6 +870,7 @@ void serializeConfig() {
|
|||||||
JsonObject hw_relay = hw.createNestedObject(F("relay"));
|
JsonObject hw_relay = hw.createNestedObject(F("relay"));
|
||||||
hw_relay["pin"] = rlyPin;
|
hw_relay["pin"] = rlyPin;
|
||||||
hw_relay["rev"] = !rlyMde;
|
hw_relay["rev"] = !rlyMde;
|
||||||
|
hw_relay[F("odrain")] = rlyOpenDrain;
|
||||||
|
|
||||||
hw[F("baud")] = serialBaud;
|
hw[F("baud")] = serialBaud;
|
||||||
|
|
||||||
|
@ -619,7 +619,8 @@ Swap: <select id="xw${i}" name="XW${i}">
|
|||||||
}
|
}
|
||||||
if (c.hw.relay) {
|
if (c.hw.relay) {
|
||||||
d.getElementsByName("RL")[0].value = c.hw.relay.pin;
|
d.getElementsByName("RL")[0].value = c.hw.relay.pin;
|
||||||
d.getElementsByName("RM")[0].checked = c.hw.relay.inv;
|
d.getElementsByName("RM")[0].checked = c.hw.relay.rev;
|
||||||
|
d.getElementsByName("RO")[0].checked = c.hw.relay.odrain;
|
||||||
}
|
}
|
||||||
UI();
|
UI();
|
||||||
}
|
}
|
||||||
@ -822,7 +823,7 @@ Swap: <select id="xw${i}" name="XW${i}">
|
|||||||
Apply IR change to main segment only: <input type="checkbox" name="MSO"><br>
|
Apply IR change to main segment only: <input type="checkbox" name="MSO"><br>
|
||||||
<div id="json" style="display:none;">JSON file: <input type="file" name="data" accept=".json"><button type="button" class="sml" onclick="uploadFile('/ir.json')">Upload</button><br></div>
|
<div id="json" style="display:none;">JSON file: <input type="file" name="data" accept=".json"><button type="button" class="sml" onclick="uploadFile('/ir.json')">Upload</button><br></div>
|
||||||
<a href="https://kno.wled.ge/interfaces/infrared/" target="_blank">IR info</a><br>
|
<a href="https://kno.wled.ge/interfaces/infrared/" target="_blank">IR info</a><br>
|
||||||
Relay GPIO: <input type="number" min="-1" max="48" name="RL" onchange="UI()" class="xs"> Invert <input type="checkbox" name="RM"><span style="cursor: pointer;" onclick="off('RL')"> ✕</span><br>
|
Relay GPIO: <input type="number" min="-1" max="48" name="RL" onchange="UI()" class="xs"><span style="cursor: pointer;" onclick="off('RL')"> ✕</span> Invert <input type="checkbox" name="RM"> Open drain <input type="checkbox" name="RO"><br>
|
||||||
<hr class="sml">
|
<hr class="sml">
|
||||||
<h3>Defaults</h3>
|
<h3>Defaults</h3>
|
||||||
Turn LEDs on after power up/reset: <input type="checkbox" name="BO"><br>
|
Turn LEDs on after power up/reset: <input type="checkbox" name="BO"><br>
|
||||||
|
@ -243,6 +243,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||||||
rlyPin = -1;
|
rlyPin = -1;
|
||||||
}
|
}
|
||||||
rlyMde = (bool)request->hasArg(F("RM"));
|
rlyMde = (bool)request->hasArg(F("RM"));
|
||||||
|
rlyOpenDrain = (bool)request->hasArg(F("RO"));
|
||||||
|
|
||||||
disablePullUp = (bool)request->hasArg(F("IP"));
|
disablePullUp = (bool)request->hasArg(F("IP"));
|
||||||
touchThreshold = request->arg(F("TT")).toInt();
|
touchThreshold = request->arg(F("TT")).toInt();
|
||||||
|
@ -293,6 +293,12 @@ WLED_GLOBAL bool rlyMde _INIT(true);
|
|||||||
#else
|
#else
|
||||||
WLED_GLOBAL bool rlyMde _INIT(RLYMDE);
|
WLED_GLOBAL bool rlyMde _INIT(RLYMDE);
|
||||||
#endif
|
#endif
|
||||||
|
//Use open drain (floating pin) when relay should be off
|
||||||
|
#ifndef RLYODRAIN
|
||||||
|
WLED_GLOBAL bool rlyOpenDrain _INIT(false);
|
||||||
|
#else
|
||||||
|
WLED_GLOBAL bool rlyOpenDrain _INIT(RLYODRAIN);
|
||||||
|
#endif
|
||||||
#ifndef IRPIN
|
#ifndef IRPIN
|
||||||
#define IRPIN -1
|
#define IRPIN -1
|
||||||
#endif
|
#endif
|
||||||
|
@ -458,6 +458,7 @@ void getSettingsJS(byte subPage, char* dest)
|
|||||||
sappend('i',SET_F("PB"),strip.paletteBlend);
|
sappend('i',SET_F("PB"),strip.paletteBlend);
|
||||||
sappend('v',SET_F("RL"),rlyPin);
|
sappend('v',SET_F("RL"),rlyPin);
|
||||||
sappend('c',SET_F("RM"),rlyMde);
|
sappend('c',SET_F("RM"),rlyMde);
|
||||||
|
sappend('c',SET_F("RO"),rlyOpenDrain);
|
||||||
for (uint8_t i=0; i<WLED_MAX_BUTTONS; i++) {
|
for (uint8_t i=0; i<WLED_MAX_BUTTONS; i++) {
|
||||||
oappend(SET_F("addBtn("));
|
oappend(SET_F("addBtn("));
|
||||||
oappend(itoa(i,nS,10)); oappend(",");
|
oappend(itoa(i,nS,10)); oappend(",");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user