diff --git a/ESP32_AP-Flasher/src/main.cpp b/ESP32_AP-Flasher/src/main.cpp index 3197c1a9..0a67e62d 100644 --- a/ESP32_AP-Flasher/src/main.cpp +++ b/ESP32_AP-Flasher/src/main.cpp @@ -42,6 +42,8 @@ void timeTask(void* parameter) { if (now % 5 == 0 || apInfo.state != AP_STATE_ONLINE || config.runStatus != RUNSTATUS_RUN) { wsSendSysteminfo(); + } + if (now % 10 == 8 && config.runStatus != RUNSTATUS_STOP) { checkVars(); } if (now % 300 == 6 && config.runStatus != RUNSTATUS_STOP) saveDB("/current/tagDB.json"); diff --git a/ESP32_AP-Flasher/src/makeimage.cpp b/ESP32_AP-Flasher/src/makeimage.cpp index d85f7873..ea891d05 100644 --- a/ESP32_AP-Flasher/src/makeimage.cpp +++ b/ESP32_AP-Flasher/src/makeimage.cpp @@ -78,7 +78,7 @@ uint32_t colorDistance(Color &c1, Color &c2, Error &e1) { int32_t r_diff = gamma8[c1.r] + e1.r - gamma8[c2.r]; int32_t g_diff = gamma8[c1.g] + e1.g - gamma8[c2.g]; int32_t b_diff = gamma8[c1.b] + e1.b - gamma8[c2.b]; - return 22 * r_diff * r_diff + 50 * g_diff * g_diff + 20 * b_diff * b_diff; + return 3 * r_diff * r_diff + 6 * g_diff * g_diff + b_diff * b_diff; } void spr2color(TFT_eSprite &spr, imgParam &imageParams, uint8_t *buffer, size_t buffer_size, bool is_red) { diff --git a/ESP32_AP-Flasher/src/storage.cpp b/ESP32_AP-Flasher/src/storage.cpp index f7cfc948..b251be68 100644 --- a/ESP32_AP-Flasher/src/storage.cpp +++ b/ESP32_AP-Flasher/src/storage.cpp @@ -52,7 +52,6 @@ size_t DynStorage::freeSpace(){ return LittleFS.totalBytes() - LittleFS.usedBytes(); } -#ifdef HAS_SDCARD void copyFile(File in, File out) { Serial.print("Copying "); Serial.print(in.path()); @@ -66,6 +65,8 @@ void copyFile(File in, File out) { } } +#ifdef HAS_SDCARD + void copyBetweenFS(FS& sourceFS, const char* source_path, FS& targetFS) { File root = sourceFS.open(source_path); char next_path[128]; @@ -127,6 +128,7 @@ void DynStorage::begin() { copyIfNeeded("/index.html"); copyIfNeeded("/fonts"); copyIfNeeded("/www"); + copyIfNeeded("/tagtypes"); copyIfNeeded("/AP_FW_Pack.bin"); copyIfNeeded("/tag_md5_db.json"); copyIfNeeded("/update_actions.json"); diff --git a/ESP32_AP-Flasher/wwwroot/main.js b/ESP32_AP-Flasher/wwwroot/main.js index aaa941be..74e35d44 100644 --- a/ESP32_AP-Flasher/wwwroot/main.js +++ b/ESP32_AP-Flasher/wwwroot/main.js @@ -936,8 +936,8 @@ function dropUpload() { event.preventDefault(); const file = event.dataTransfer.files[0]; const tagCard = event.target.closest('.tagcard'); + const mac = tagCard.dataset.mac; if (tagCard && file && file.type.startsWith('image/')) { - tagCard.classList.remove('drophighlight'); const itemId = tagCard.id; const reader = new FileReader(); @@ -947,7 +947,6 @@ function dropUpload() { image.onload = function () { const hwtype = tagCard.dataset.hwtype; - const mac = tagCard.dataset.mac; const [width, height] = [tagTypes[hwtype].width, tagTypes[hwtype].height] || [0, 0]; const canvas = createCanvas(width, height); const ctx = canvas.getContext('2d'); @@ -991,9 +990,35 @@ function dropUpload() { console.error('Failed to load image.'); }; }; - reader.readAsDataURL(file); + + } else if (file.type === 'application/json') { + + const reader = new FileReader(); + reader.onload = function (event) { + const jsonContent = event.target.result; + const formData = new FormData(); + formData.append('mac', mac); + formData.append('json', jsonContent); + fetch('/jsonupload', { + method: 'POST', + body: formData, + }) + .then(response => { + if (response.ok) { + console.log('JSON uploaded successfully'); + } else { + console.error('JSON upload failed'); + } + }) + .catch(error => { + console.error('JSON upload failed', error); + }); + }; + reader.readAsText(file); + } + tagCard.classList.remove('drophighlight'); }); function createCanvas(width, height) {