apconfig option to turn off preview images

- option to turn preview images off in apconfig
- better browser cache of preview images
- bit of memory optimization on the contentmanager
This commit is contained in:
Nic Limper
2023-07-11 13:58:03 +02:00
parent 9ef2737bc3
commit b178994bd6
8 changed files with 36 additions and 18 deletions

View File

@@ -116,6 +116,14 @@ Latency will be around 40 seconds.">
<option value="1">yes</option>
</select>
</p>
<p title="Turn off preview images on the webpage if you want to manage many tags,
to save file system space">
<label for="apcpreview">Preview images</label>
<select id="apcpreview">
<option value="1">yes</option>
<option value="0">no</option>
</select>
</p>
<p title="Wifi transmit power">
<label for="apcwifipower">Wifi power</label>
<select id="apcwifipower">

View File

@@ -199,7 +199,7 @@ function processTags(tagArray) {
}
if (div.dataset.hash != element.hash && div.dataset.hwtype > -1 && (element.isexternal == false || element.contentMode != 12)) {
loadImage(tagmac, '/current/' + tagmac + '.raw?' + (new Date()).getTime());
loadImage(tagmac, '/current/' + tagmac + '.raw?' + element.hash);
div.dataset.hash = element.hash;
}
if (element.isexternal == true && element.contentMode == 12) $('#tag' + tagmac + ' .tagimg').style.display = 'none';
@@ -452,6 +452,7 @@ $('#apconfigbutton').onclick = function () {
$("#apcfglanguage").value = data.language;
$("#apclatency").value = data.maxsleep;
$("#apcpreventsleep").value = data.stopsleep;
$("#apcpreview").value = data.preview;
$("#apcwifipower").value = data.wifipower;
$("#apctimezone").value = data.timezone;
})
@@ -466,6 +467,7 @@ $('#apcfgsave').onclick = function () {
formData.append('language', $('#apcfglanguage').value);
formData.append('maxsleep', $('#apclatency').value);
formData.append('stopsleep', $('#apcpreventsleep').value);
formData.append('preview', $('#apcpreview').value);
formData.append('wifipower', $('#apcwifipower').value);
formData.append('timezone', $('#apctimezone').value);
fetch("/save_apcfg", {
@@ -676,7 +678,7 @@ function processQueue() {
canvas.style.display = 'block';
const hwtype = $('#tag' + id).dataset.hwtype;
fetch(imageSrc)
fetch(imageSrc, { cache: "force-cache" })
.then(response => response.arrayBuffer())
.then(buffer => {
[canvas.width, canvas.height] = displaySizeLookup[hwtype] || [0, 0];

View File

@@ -63,6 +63,7 @@ struct Config {
uint8_t maxsleep;
uint8_t stopsleep;
uint8_t runStatus;
uint8_t preview;
uint8_t wifiPower;
char timeZone[52];
};

View File

@@ -340,6 +340,7 @@ void initSprite(TFT_eSprite &spr, int w, int h, imgParam &imageParams) {
spr.createSprite(w, h);
if (spr.getPointer() == nullptr) {
wsErr("low on memory. Fallback to 1bpp");
Serial.println("Maximum Continuous Heap Space: " + String(heap_caps_get_largest_free_block(MALLOC_CAP_DEFAULT)));
spr.setColorDepth(1);
spr.setBitmapColor(TFT_WHITE, TFT_BLACK);
imageParams.bpp = 1;
@@ -370,7 +371,7 @@ void drawDate(String &filename, tagRecord *&taginfo, imgParam &imageParams) {
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite spr = TFT_eSprite(&tft);
DynamicJsonDocument loc(1000);
StaticJsonDocument<512> loc;
getTemplate(loc, TEMPLATE, 1, hwdata[taginfo->hwType].basetype);
initSprite(spr, hwdata[taginfo->hwType].width, hwdata[taginfo->hwType].height, imageParams);
@@ -411,7 +412,7 @@ void drawNumber(String &filename, int32_t count, int32_t thresholdred, tagRecord
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite spr = TFT_eSprite(&tft);
DynamicJsonDocument loc(1000);
StaticJsonDocument<512> loc;
getTemplate(loc, TEMPLATE, 2, hwdata[taginfo->hwType].basetype);
initSprite(spr, hwdata[taginfo->hwType].width, hwdata[taginfo->hwType].height, imageParams);
@@ -483,7 +484,7 @@ void drawWeather(String &filename, JsonObject &cfgobj, tagRecord *&taginfo, imgP
return;
}
DynamicJsonDocument loc(1000);
StaticJsonDocument<512> loc;
getTemplate(loc, TEMPLATE, 4, hwdata[taginfo->hwType].basetype);
String weatherIcons[] = {"\uf00d", "\uf00c", "\uf002", "\uf013", "\uf013", "\uf014", "", "", "\uf014", "", "",
@@ -571,7 +572,7 @@ void drawForecast(String &filename, JsonObject &cfgobj, tagRecord *&taginfo, img
tft.setTextWrap(false, false);
DynamicJsonDocument loc(1000);
StaticJsonDocument<512> loc;
getTemplate(loc, TEMPLATE, 8, hwdata[taginfo->hwType].basetype);
initSprite(spr, hwdata[taginfo->hwType].width, hwdata[taginfo->hwType].height, imageParams);
@@ -679,7 +680,7 @@ bool getRssFeed(String &filename, String URL, String title, tagRecord *&taginfo,
U8g2_for_TFT_eSPI u8f;
u8f.begin(spr);
DynamicJsonDocument loc(1000);
StaticJsonDocument<512> loc;
getTemplate(loc, TEMPLATE, 9, hwdata[taginfo->hwType].basetype);
initSprite(spr, hwdata[taginfo->hwType].width, hwdata[taginfo->hwType].height, imageParams);
@@ -760,7 +761,7 @@ bool getCalFeed(String &filename, String URL, String title, tagRecord *&taginfo,
U8g2_for_TFT_eSPI u8f;
u8f.begin(spr);
DynamicJsonDocument loc(1000);
StaticJsonDocument<512> loc;
getTemplate(loc, TEMPLATE, 11, hwdata[taginfo->hwType].basetype);
initSprite(spr, hwdata[taginfo->hwType].width, hwdata[taginfo->hwType].height, imageParams);
@@ -812,7 +813,7 @@ void drawQR(String &filename, String qrcontent, String title, tagRecord *&taginf
int size = qrcode.size;
int xpos = 0, ypos = 0, dotsize = 1;
DynamicJsonDocument loc(1000);
StaticJsonDocument<512> loc;
getTemplate(loc, TEMPLATE, 10, hwdata[taginfo->hwType].basetype);
initSprite(spr, hwdata[taginfo->hwType].width, hwdata[taginfo->hwType].height, imageParams);
drawString(spr, title, loc["title"][0], loc["title"][1], loc["title"][2]);
@@ -854,7 +855,7 @@ void drawBuienradar(String &filename, JsonObject &cfgobj, tagRecord *&taginfo, i
U8g2_for_TFT_eSPI u8f;
u8f.begin(spr);
DynamicJsonDocument loc(1000);
StaticJsonDocument<512> loc;
getTemplate(loc, TEMPLATE, 16, hwdata[taginfo->hwType].basetype);
initSprite(spr, hwdata[taginfo->hwType].width, hwdata[taginfo->hwType].height, imageParams);
@@ -1043,7 +1044,7 @@ void getTemplate(JsonDocument &json, const char *filePath, uint8_t id, uint8_t h
StaticJsonDocument<50> filter;
filter[String(id)][String(hwtype)] = true;
DynamicJsonDocument doc(1024);
StaticJsonDocument<1024> doc;
DeserializationError error = deserializeJson(doc, jsonFile, DeserializationOption::Filter(filter));
jsonFile.close();

View File

@@ -38,6 +38,7 @@ void jpg2buffer(String filein, String fileout, imgParam &imageParams) {
spr.createSprite(w, h);
if (spr.getPointer() == nullptr) {
wsErr("low on memory. Fallback to 1bpp");
Serial.println("Maximum Continuous Heap Space: " + String(heap_caps_get_largest_free_block(MALLOC_CAP_DEFAULT)));
spr.setColorDepth(1);
spr.setBitmapColor(TFT_WHITE, TFT_BLACK);
imageParams.bpp = 1;
@@ -89,7 +90,7 @@ uint8_t *spr2color(TFT_eSprite &spr, imgParam &imageParams, size_t *buffer_size,
*buffer_size = (bufw * bufh) / 8;
uint8_t *buffer = (uint8_t*) malloc(*buffer_size);
if (!buffer) {
Serial.println("Fallied to allocated buffer");
Serial.println("Failed to allocate buffer");
return nullptr;
}
memset(buffer, 0, *buffer_size);

View File

@@ -384,11 +384,11 @@ void processXferComplete(struct espXferComplete* xfc, bool local) {
contentFS->remove(dst_path);
}
if (contentFS->exists(src_path)) {
#ifndef REMOVE_RAW
contentFS->rename(src_path, dst_path);
#else
contentFS->remove(src_path);
#endif
if (config.preview) {
contentFS->rename(src_path, dst_path);
} else {
contentFS->remove(src_path);
}
}
time_t now;

View File

@@ -286,6 +286,7 @@ void initAPconfig() {
config.language = APconfig["language"] | getDefaultLanguage();
config.maxsleep = APconfig["maxsleep"] | 10;
config.stopsleep = APconfig["stopsleep"] | 1;
config.preview = APconfig["preview"] | 1;
// default wifi power 8.5 dbM
// see https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/src/WiFiGeneric.h#L111
config.wifiPower = APconfig["wifipower"] | 34;
@@ -305,6 +306,7 @@ void saveAPconfig() {
APconfig["language"] = config.language;
APconfig["maxsleep"] = config.maxsleep;
APconfig["stopsleep"] = config.stopsleep;
APconfig["preview"] = config.preview;
APconfig["wifipower"] = config.wifiPower;
APconfig["timezone"] = config.timeZone;
serializeJsonPretty(APconfig, configFile);

View File

@@ -262,7 +262,7 @@ void init_web() {
ESP.restart();
});
server.serveStatic("/current", *contentFS, "/current/");
server.serveStatic("/current", *contentFS, "/current/").setCacheControl("max-age=604800");
server.serveStatic("/", *contentFS, "/www/").setDefaultFile("index.html");
server.on(
@@ -414,6 +414,9 @@ void init_web() {
if (request->hasParam("stopsleep", true)) {
config.stopsleep = static_cast<uint8_t>(request->getParam("stopsleep", true)->value().toInt());
}
if (request->hasParam("preview", true)) {
config.preview = static_cast<uint8_t>(request->getParam("preview", true)->value().toInt());
}
if (request->hasParam("wifipower", true)) {
config.wifiPower = static_cast<uint8_t>(request->getParam("wifipower", true)->value().toInt());
WiFi.setTxPower(static_cast<wifi_power_t>(config.wifiPower));