mirror of
https://github.com/OpenEPaperLink/OpenEPaperLink.git
synced 2026-03-21 23:06:40 +01:00
Merge pull request #7 from nlimper/development
bugfixes and memory optimizations
This commit is contained in:
@@ -29,7 +29,7 @@ enum EinkClut {
|
||||
EinkClutThreeBlacksAndRed,
|
||||
};
|
||||
|
||||
void spr2grays(TFT_eSprite &spr, long w, long h, String fileout);
|
||||
void spr2grays(TFT_eSprite &spr, long w, long h, String &fileout);
|
||||
void jpg2grays(String filein, String fileout);
|
||||
void bmp2grays(String filein, String fileout);
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ void contentRunner() {
|
||||
void drawNew(uint8_t mac[8], bool buttonPressed, tagRecord *&taginfo) {
|
||||
time_t now;
|
||||
time(&now);
|
||||
struct tm *time_info = gmtime(&now);
|
||||
|
||||
char buffer[64];
|
||||
uint8_t src[8];
|
||||
@@ -45,16 +44,21 @@ void drawNew(uint8_t mac[8], bool buttonPressed, tagRecord *&taginfo) {
|
||||
|
||||
String filename = "/" + dst + ".bmp";
|
||||
|
||||
time_info->tm_hour = 0;
|
||||
time_info->tm_min = 0;
|
||||
time_info->tm_sec = 0;
|
||||
time_info->tm_mday++;
|
||||
time_t midnight = mktime(time_info);
|
||||
struct tm time_info;
|
||||
getLocalTime(&time_info);
|
||||
time_info.tm_hour = 0;
|
||||
time_info.tm_min = 0;
|
||||
time_info.tm_sec = 0;
|
||||
time_info.tm_mday++;
|
||||
time_t midnight = mktime(&time_info);
|
||||
|
||||
DynamicJsonDocument doc(500);
|
||||
deserializeJson(doc, taginfo->modeConfigJson);
|
||||
JsonObject cfgobj = doc.as<JsonObject>();
|
||||
|
||||
Serial.println("Updating " + dst + " mode " + String(taginfo->contentMode) + " nextupdate " + String(taginfo->nextupdate));
|
||||
taginfo->nextupdate = now + 600;
|
||||
|
||||
switch (taginfo->contentMode) {
|
||||
case Image:
|
||||
|
||||
@@ -71,16 +75,21 @@ void drawNew(uint8_t mac[8], bool buttonPressed, tagRecord *&taginfo) {
|
||||
|
||||
case Today:
|
||||
|
||||
Serial.println("heap voor drawDate: " + String(ESP.getFreeHeap()));
|
||||
drawDate(filename);
|
||||
updateTagImage(filename, mac, (midnight - now) / 60 - 10);
|
||||
Serial.println("heap na drawDate: " + String(ESP.getFreeHeap()));
|
||||
// updateTagImage(filename, mac, (midnight - now) / 60 - 10);
|
||||
updateTagImage(filename, mac, 60);
|
||||
taginfo->nextupdate = midnight;
|
||||
break;
|
||||
|
||||
case CountDays:
|
||||
|
||||
if (buttonPressed) cfgobj["counter"] = 0;
|
||||
Serial.println("heap voor drawnumber: " + String(ESP.getFreeHeap()));
|
||||
drawNumber(filename, (int32_t)cfgobj["counter"], (int32_t)cfgobj["thresholdred"]);
|
||||
updateTagImage(filename, mac, (midnight - now) / 60 - 5);
|
||||
Serial.println("heap na drawnumber: " + String(ESP.getFreeHeap()));
|
||||
updateTagImage(filename, mac, 60);
|
||||
cfgobj["counter"] = (int32_t)cfgobj["counter"] + 1;
|
||||
taginfo->nextupdate = midnight;
|
||||
break;
|
||||
@@ -88,7 +97,9 @@ void drawNew(uint8_t mac[8], bool buttonPressed, tagRecord *&taginfo) {
|
||||
case CountHours:
|
||||
|
||||
if (buttonPressed) cfgobj["counter"] = 0;
|
||||
Serial.println("heap voor drawnumber: " + String(ESP.getFreeHeap()));
|
||||
drawNumber(filename, (int32_t)cfgobj["counter"], (int32_t)cfgobj["thresholdred"]);
|
||||
Serial.println("heap na drawnumber: " + String(ESP.getFreeHeap()));
|
||||
// updateTagImage(&filename, mac, (3600 - now % 3600) / 60);
|
||||
// taginfo->nextupdate = now + 3600 - (now % 3600);
|
||||
updateTagImage(filename, mac, 3);
|
||||
@@ -110,8 +121,11 @@ void drawNew(uint8_t mac[8], bool buttonPressed, tagRecord *&taginfo) {
|
||||
} else {
|
||||
wsString("Error accessing " + filename);
|
||||
}
|
||||
cfgobj["filename"]="";
|
||||
taginfo->nextupdate = 3216153600;
|
||||
taginfo->contentMode = Image;
|
||||
} else {
|
||||
taginfo->nextupdate = now + 300;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -123,7 +137,7 @@ void drawNew(uint8_t mac[8], bool buttonPressed, tagRecord *&taginfo) {
|
||||
updateTagImage(filename, mac, cfgobj["interval"].as<int>());
|
||||
cfgobj["#fetched"] = now;
|
||||
}
|
||||
taginfo->nextupdate = now + 60 * cfgobj["interval"].as<int>();
|
||||
taginfo->nextupdate = now + 60 * (cfgobj["interval"].as<int>() < 5 ? 5 : cfgobj["interval"].as<int>()) ;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -151,6 +165,9 @@ void drawDate(String &filename) {
|
||||
LittleFS.begin();
|
||||
long w = 296, h = 128; // mag staand of liggend
|
||||
spr.createSprite(w, h);
|
||||
if (spr.getPointer() == nullptr) {
|
||||
Serial.println("Failed to create sprite in drawDate");
|
||||
}
|
||||
spr.setColorDepth(8);
|
||||
spr.fillSprite(TFT_WHITE);
|
||||
spr.setTextDatum(TC_DATUM);
|
||||
@@ -174,6 +191,9 @@ void drawNumber(String &filename, int32_t count, int32_t thresholdred) {
|
||||
LittleFS.begin();
|
||||
long w = 296, h = 128;
|
||||
spr.createSprite(w, h);
|
||||
if (spr.getPointer() == nullptr) {
|
||||
Serial.println("Failed to create sprite in drawNumber");
|
||||
}
|
||||
spr.setColorDepth(8);
|
||||
spr.fillSprite(TFT_WHITE);
|
||||
spr.setTextDatum(MC_DATUM);
|
||||
|
||||
@@ -21,6 +21,9 @@ void jpg2grays(String filein, String fileout) {
|
||||
Serial.println("jpeg conversion " + String(w) + "x" + String(h));
|
||||
|
||||
spr.createSprite(w, h);
|
||||
if (spr.getPointer() == nullptr) {
|
||||
Serial.println("Failed to create sprite in jpg2grays");
|
||||
}
|
||||
spr.setColorDepth(8);
|
||||
spr.fillSprite(TFT_WHITE);
|
||||
TJpgDec.drawFsJpg(0, 0, filein);
|
||||
@@ -38,10 +41,9 @@ static uint32_t repackPackedVals(uint32_t val, uint32_t pixelsPerPackedUnit, uin
|
||||
return ret;
|
||||
}
|
||||
|
||||
void spr2grays(TFT_eSprite &spr, long w, long h, String fileout) {
|
||||
void spr2grays(TFT_eSprite &spr, long w, long h, String &fileout) {
|
||||
// based on bmp2grays function by Dmitry.GR
|
||||
|
||||
Serial.println("start writing BMP");
|
||||
long t = millis();
|
||||
LittleFS.begin();
|
||||
|
||||
@@ -237,7 +239,6 @@ void spr2grays(TFT_eSprite &spr, long w, long h, String fileout) {
|
||||
void bmp2grays(String filein, String fileout) {
|
||||
// based on bmp2grays function by Dmitry.GR
|
||||
|
||||
Serial.println("start writing BMP2");
|
||||
long t = millis();
|
||||
LittleFS.begin();
|
||||
|
||||
|
||||
@@ -138,27 +138,35 @@ bool prepareDataAvail(String* filename, uint8_t dataType, uint8_t* dst, uint16_t
|
||||
pendinginfo->len = pending.availdatainfo.dataSize;
|
||||
pendinginfo->data = nullptr;
|
||||
pendinginfo->timeout = PENDING_TIMEOUT;
|
||||
pendinginfo->data = getDataForFile(&file);
|
||||
file.close();
|
||||
pendinginfo->timeout = 1800;
|
||||
//pendinginfo->data = getDataForFile(&file);
|
||||
pendinginfo->timeout = 1800; // ***fixme... a tag can sleep for a long time when ttl is used.
|
||||
pendingfiles.push_back(pendinginfo);
|
||||
|
||||
if (dataType != DATATYPE_UPDATE) {
|
||||
char dst_path[64];
|
||||
sprintf(dst_path, "/current/%02X%02X%02X%02X%02X%02X.pending\0", dst[5], dst[4], dst[3], dst[2], dst[1], dst[0]);
|
||||
file = LittleFS.open(dst_path, "w");
|
||||
int bytes_written = file.write(pendinginfo->data, pendinginfo->len);
|
||||
file.close();
|
||||
fs::File dstfile = LittleFS.open(dst_path, "w");
|
||||
//int bytes_written = dstfile.write(pendinginfo->data, pendinginfo->len);
|
||||
file.seek(0);
|
||||
const int chunkSize = 512;
|
||||
uint8_t buffer[chunkSize];
|
||||
size_t bytesRead = 0;
|
||||
while ((bytesRead = file.read(buffer, chunkSize)) > 0) {
|
||||
dstfile.write(buffer, bytesRead);
|
||||
}
|
||||
dstfile.close();
|
||||
|
||||
wsString("new image pending: " + String(dst_path));
|
||||
if (taginfo != nullptr) {
|
||||
taginfo->pending = true;
|
||||
taginfo->CheckinInMinPending = nextCheckin + 1;
|
||||
memcpy(taginfo->md5pending, md5bytes, sizeof(md5bytes));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Serial.println("firmware upload pending");
|
||||
}
|
||||
else {
|
||||
Serial.println("firmware upload pending");
|
||||
}
|
||||
file.close();
|
||||
|
||||
wsSendTaginfo(mac);
|
||||
|
||||
|
||||
@@ -72,7 +72,6 @@ void fillNode(JsonObject &tag, tagRecord* &taginfo) {
|
||||
void saveDB(String filename) {
|
||||
DynamicJsonDocument doc(2500);
|
||||
|
||||
Serial.println("start writing DB to file");
|
||||
long t = millis();
|
||||
|
||||
LittleFS.begin();
|
||||
@@ -100,7 +99,7 @@ void saveDB(String filename) {
|
||||
|
||||
file.close();
|
||||
Serial.println(millis() - t);
|
||||
Serial.println("finished writing file");
|
||||
Serial.println("finished writing DB");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user