Added uploading IR.json from settings page.

This commit is contained in:
Blaz Kristan 2021-06-04 18:25:33 +02:00
parent b0bfe341df
commit 517e9f92ba
4 changed files with 513 additions and 475 deletions

View File

@ -41,6 +41,7 @@
return true;
}
function trySubmit(e) {
d.Sf.data.value = '';
e.preventDefault();
if (!pinsOK()) {e.stopPropagation();return false;} // Prevent form submission and contact with server
if (bquot > 100) {var msg = "Too many LEDs for me to handle!"; if (maxM < 10000) msg += "\n\rConsider using an ESP32."; alert(msg);}
@ -225,6 +226,7 @@
s2 += "A is enough)<br>";
gId('psu').innerHTML = s;
gId('psu2').innerHTML = isWS2815 ? "" : s2;
gId("json").style.display = d.Sf.IT.value==8 ? "" : "none";
}
function lastEnd(i) {
if (i<1) return 0;
@ -312,6 +314,17 @@ Reverse (rotated 180°): <input type="checkbox" name="CV${i}">
c += `</select>`;
c += `<span style="cursor: pointer;" onclick="off('${bt}')">&nbsp;&#215;</span><br>`;
gId("btns").innerHTML = c;
}
function uploadFile() {
var req = new XMLHttpRequest();
//req.addEventListener('load', function(){console.log(this.responseText);});
req.addEventListener('error', function(e){console.error(e.stack);});
req.open("POST", "/upload");
var formData = new FormData();
formData.append("data", d.Sf.data.files[0], "/ir.json");
req.send(formData);
d.Sf.data.value = '';
return false;
}
function GetV()
{
@ -324,6 +337,7 @@ Reverse (rotated 180°): <input type="checkbox" name="CV${i}">
</style>
</head>
<body onload="S()">
<div style="display:hidden;"><form id="fileUL" name="fUL" method="POST" enctype="multipart/form-data" action="/upload" target="asFr"><iframe id="asFr" name="asFr" height="0" width="0" frameborder="0"></iframe></form></div>
<form id="form_s" name="Sf" method="post">
<div class="toprow">
<div class="helpB"><button type="button" onclick="H()">?</button></div>
@ -371,7 +385,7 @@ Reverse (rotated 180°): <input type="checkbox" name="CV${i}">
</div><hr style="width:260px">
<div id="btns"></div>
Touch threshold: <input type="number" min="0" max="100" name="TT" required><br>
IR pin: <input type="number" min="-1" max="40" name="IR" onchange="UI()" style="width:35px"><select name="IT">
IR pin: <input type="number" min="-1" max="40" name="IR" onchange="UI()" style="width:35px"><select name="IT" onchange="UI()">
<option value="0">Remote disabled</option>
<option value="1">24-key RGB</option>
<option value="2">24-key with CT</option>
@ -382,6 +396,7 @@ Reverse (rotated 180°): <input type="checkbox" name="CV${i}">
<option value="7">9-key red</option>
<option value="8">JSON remote</option>
</select><span style="cursor: pointer;" onclick="off('IR')">&nbsp;&#215;</span><br>
<div id="json" style="display:none;">JSON file: <input type="file" name="data" accept=".json"> <input type="button" value="Upload" onclick="uploadFile();"><br></div>
<a href="https://github.com/Aircoookie/WLED/wiki/Infrared-Control" target="_blank">IR info</a><br>
Relay pin: <input type="number" min="-1" max="40" name="RL" onchange="UI()" style="width:35px"> invert <input type="checkbox" name="RM"><span style="cursor: pointer;" onclick="off('RL')">&nbsp;&#215;</span><br>
<hr style="width:260px">

File diff suppressed because one or more lines are too long

View File

@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2106031
#define VERSION 2106041
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG

View File

@ -15,6 +15,19 @@ bool isIp(String str) {
return true;
}
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){
if(!index){
request->_tempFile = WLED_FS.open(filename, "w");
}
if (len) {
request->_tempFile.write(data,len);
}
if(final){
request->_tempFile.close();
request->send(200, "text/plain", F("File Uploaded!"));
}
}
bool captivePortal(AsyncWebServerRequest *request)
{
if (ON_STA_FILTER(request)) return false; //only serve captive in AP mode
@ -142,6 +155,11 @@ void initServer()
serveMessage(request, 418, F("418. I'm a teapot."), F("(Tangible Embedded Advanced Project Of Twinkling)"), 254);
});
server.on("/upload", HTTP_POST, [](AsyncWebServerRequest *request) {},
[](AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data,
size_t len, bool final) {handleUpload(request, filename, index, data, len, final);}
);
//if OTA is allowed
if (!otaLock){
#ifdef WLED_ENABLE_FS_EDITOR