From f2a794d5180118bedbe76f422eed92185a2f0a4e Mon Sep 17 00:00:00 2001 From: lumapu Date: Mon, 17 Oct 2022 14:14:23 +0200 Subject: [PATCH] fix setup for multiple inverters --- tools/esp8266/html/api.js | 4 ++++ tools/esp8266/html/setup.html | 20 +++++++++++++++++--- tools/esp8266/html/style.css | 4 ++++ tools/esp8266/web.cpp | 6 ++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/tools/esp8266/html/api.js b/tools/esp8266/html/api.js index c896c42b..f793551a 100644 --- a/tools/esp8266/html/api.js +++ b/tools/esp8266/html/api.js @@ -79,3 +79,7 @@ function span(val, cl=null, id=null) { if(null != id) e.id = id; return e; } + +function br() { + return document.createElement('br'); +} diff --git a/tools/esp8266/html/setup.html b/tools/esp8266/html/setup.html index adfddea7..2021a11f 100644 --- a/tools/esp8266/html/setup.html +++ b/tools/esp8266/html/setup.html @@ -47,7 +47,7 @@
Inverter

- +

General

@@ -132,8 +132,8 @@ const re = /11[2,4,6]1.*/; - document.getElementsByName("btnAdd")[0].addEventListener("click", function() { - if(highestId < (maxInv-1)) + document.getElementById("btnAdd").addEventListener("click", function() { + if(highestId <= (maxInv-1)) ivHtml(JSON.parse('{"name":"","serial":"","channels":4,"ch_max_power":[0,0,0,0],"ch_name":["","","",""]}'), highestId + 1); }); @@ -174,6 +174,14 @@ getAjax("/api/setup", apiCbMqtt, "POST", JSON.stringify(obj)); } + function delIv() { + var id = this.id.substring(0,4); + var e = document.getElementsByName(id + "Addr")[0]; + e.value = ""; + e.dispatchEvent(new Event("keyup")); + document.getElementsByName(id + "Name")[0].value = ""; + } + function ivHtml(obj, id) { highestId = id; if(highestId == (maxInv - 1)) @@ -182,6 +190,7 @@ iv.appendChild(des("Inverter " + id)); id = "inv" + id; + iv.appendChild(lbl(id + "Addr", "Address*")); var addr = inp(id + "Addr", obj["serial"], 12) iv.appendChild(addr); @@ -226,6 +235,11 @@ } iv.appendChild(d); } + iv.appendChild(br()); + iv.appendChild(lbl(id + "lbldel", "Delete")); + var del = inp(id+"del", "X", 0, ["btn", "btnDel"], id+"del", "button"); + iv.appendChild(del); + del.addEventListener("click", delIv); } function ivGlob(obj) { diff --git a/tools/esp8266/html/style.css b/tools/esp8266/html/style.css index e58efab3..d6f0070c 100644 --- a/tools/esp8266/html/style.css +++ b/tools/esp8266/html/style.css @@ -129,6 +129,10 @@ input.sh { margin-right: 10px; } +input.btnDel { + background-color: #c00 !important; +} + input.btn { background-color: #006ec0; color: #fff; diff --git a/tools/esp8266/web.cpp b/tools/esp8266/web.cpp index 0b64f6ba..5891fbe1 100644 --- a/tools/esp8266/web.cpp +++ b/tools/esp8266/web.cpp @@ -236,6 +236,12 @@ void web::showSave(AsyncWebServerRequest *request) { if(strlen(buf) == 0) memset(buf, 0, 20); iv->serial.u64 = mMain->Serial2u64(buf); + switch(iv->serial.b[4]) { + case 0x21: iv->type = INV_TYPE_1CH; iv->channels = 1; break; + case 0x41: iv->type = INV_TYPE_2CH; iv->channels = 2; break; + case 0x61: iv->type = INV_TYPE_4CH; iv->channels = 4; break; + default: break; + } // name request->arg("inv" + String(i) + "Name").toCharArray(iv->name, MAX_NAME_LENGTH);