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; return true;
} }
function trySubmit(e) { function trySubmit(e) {
d.Sf.data.value = '';
e.preventDefault(); e.preventDefault();
if (!pinsOK()) {e.stopPropagation();return false;} // Prevent form submission and contact with server 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);} 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>"; s2 += "A is enough)<br>";
gId('psu').innerHTML = s; gId('psu').innerHTML = s;
gId('psu2').innerHTML = isWS2815 ? "" : s2; gId('psu2').innerHTML = isWS2815 ? "" : s2;
gId("json").style.display = d.Sf.IT.value==8 ? "" : "none";
} }
function lastEnd(i) { function lastEnd(i) {
if (i<1) return 0; if (i<1) return 0;
@ -312,6 +314,17 @@ Reverse (rotated 180°): <input type="checkbox" name="CV${i}">
c += `</select>`; c += `</select>`;
c += `<span style="cursor: pointer;" onclick="off('${bt}')">&nbsp;&#215;</span><br>`; c += `<span style="cursor: pointer;" onclick="off('${bt}')">&nbsp;&#215;</span><br>`;
gId("btns").innerHTML = c; 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() function GetV()
{ {
@ -324,6 +337,7 @@ Reverse (rotated 180°): <input type="checkbox" name="CV${i}">
</style> </style>
</head> </head>
<body onload="S()"> <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"> <form id="form_s" name="Sf" method="post">
<div class="toprow"> <div class="toprow">
<div class="helpB"><button type="button" onclick="H()">?</button></div> <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><hr style="width:260px">
<div id="btns"></div> <div id="btns"></div>
Touch threshold: <input type="number" min="0" max="100" name="TT" required><br> 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="0">Remote disabled</option>
<option value="1">24-key RGB</option> <option value="1">24-key RGB</option>
<option value="2">24-key with CT</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="7">9-key red</option>
<option value="8">JSON remote</option> <option value="8">JSON remote</option>
</select><span style="cursor: pointer;" onclick="off('IR')">&nbsp;&#215;</span><br> </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> <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> 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"> <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) // 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 //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG

View File

@ -15,6 +15,19 @@ bool isIp(String str) {
return true; 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) bool captivePortal(AsyncWebServerRequest *request)
{ {
if (ON_STA_FILTER(request)) return false; //only serve captive in AP mode 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); 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 OTA is allowed
if (!otaLock){ if (!otaLock){
#ifdef WLED_ENABLE_FS_EDITOR #ifdef WLED_ENABLE_FS_EDITOR