diff --git a/ESP32_AP-Flasher/include/makeimage.h b/ESP32_AP-Flasher/include/makeimage.h index e99ee666..f94feb61 100644 --- a/ESP32_AP-Flasher/include/makeimage.h +++ b/ESP32_AP-Flasher/include/makeimage.h @@ -39,6 +39,7 @@ struct imgParam { uint8_t zlib; uint8_t g5; + uint8_t ts_option; }; void spr2buffer(TFT_eSprite &spr, String &fileout, imgParam &imageParams); diff --git a/ESP32_AP-Flasher/src/contentmanager.cpp b/ESP32_AP-Flasher/src/contentmanager.cpp index f6ef8bb8..8e2b8c20 100644 --- a/ESP32_AP-Flasher/src/contentmanager.cpp +++ b/ESP32_AP-Flasher/src/contentmanager.cpp @@ -259,6 +259,27 @@ void drawNew(const uint8_t mac[8], tagRecord *&taginfo) { } else if (interval < 180) interval = 60 * 60; + imageParams.ts_option = config.showtimestamp; + if(imageParams.ts_option) { + JsonDocument loc; + getTemplate(loc, taginfo->contentMode, taginfo->hwType); + + if(loc["ts_option"].is()) { + // Overide ts_option if present in template + imageParams.ts_option = loc["ts_option"]; + } + else { + const JsonArray jsonArray = loc.as(); + for (const JsonVariant &elem : jsonArray) { + if(elem["ts_option"].is()) { + // Overide ts_option if present in template + imageParams.ts_option = elem["ts_option"]; + break; + } + } + } + } + switch (taginfo->contentMode) { case 0: // Not configured case 22: // Static image diff --git a/ESP32_AP-Flasher/src/makeimage.cpp b/ESP32_AP-Flasher/src/makeimage.cpp index dd8d0f0a..893ba17c 100644 --- a/ESP32_AP-Flasher/src/makeimage.cpp +++ b/ESP32_AP-Flasher/src/makeimage.cpp @@ -365,23 +365,59 @@ uint8_t *g5Compress(uint16_t width, uint16_t height, uint8_t *buffer, uint16_t b } #endif -void doTimestamp(TFT_eSprite *spr) { +// The "ts_option" is a bitmapped variable with a default value of 1 +// which is black on white, long format @ bottom right. +// +// b2, b1, b0: +// 0 - no timestamp +// 1 - bottom right +// 2 - top right +// 3 - bottom left +// 4 - top left +// 5 -> 7 reserved +// b3: +// 0 - long format (year-month-day hr:min) +// 1 - short format (month-day hr:min) +// b4: +// 0 - black on white +// 1 - white on black +// b5 -> b7: reserved +// +void doTimestamp(TFT_eSprite *spr, uint8_t ts_option) { time_t now = time(nullptr); struct tm *timeinfo = localtime(&now); char buffer[20]; - strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M", timeinfo); + strftime(buffer, sizeof(buffer), + (ts_option & 0x8) ? "%m-%d %H:%M" : "%Y-%m-%d %H:%M",timeinfo); + int ts_chars = strlen(buffer); - // spr->drawRect(spr->width() - 16 * 6 - 4, spr->height() - 10 - 2, 16 * 6 + 3, 11, TFT_BLACK); - spr->drawRect(spr->width() - 16 * 6 - 3, spr->height() - 10 - 1, 16 * 6 + 1, 9, TFT_WHITE); - spr->setTextColor(TFT_BLACK, TFT_WHITE); - spr->setCursor(spr->width() - 16 * 6 - 2, spr->height() - 10, 1); + uint16_t char_color; + uint16_t bg_color; + + if(ts_option & 0x10) { + char_color = TFT_WHITE; + bg_color= TFT_BLACK; + } + else { + char_color = TFT_BLACK; + bg_color = TFT_WHITE; + } + + ts_option = (ts_option & 0x3) - 1; + + int32_t ts_x = (ts_option & 2) ? 1 : spr->width() - ts_chars * 6 - 2; + int32_t ts_y = (ts_option & 1) ? 1 : spr->height() - 10; + + spr->drawRect(ts_x - 1, ts_y - 1, ts_chars * 6 + 1, 9, bg_color); + spr->setTextColor(char_color, bg_color); + spr->setCursor(ts_x,ts_y); spr->print(buffer); } void spr2buffer(TFT_eSprite &spr, String &fileout, imgParam &imageParams) { long t = millis(); - if (config.showtimestamp) doTimestamp(&spr); + if (imageParams.ts_option) doTimestamp(&spr,imageParams.ts_option); #ifdef HAS_TFT extern uint8_t YellowSense; if (fileout == "direct") { diff --git a/resources/tagtypes/01.json b/resources/tagtypes/01.json index a8fbaa82..4b42912c 100644 --- a/resources/tagtypes/01.json +++ b/resources/tagtypes/01.json @@ -1,5 +1,5 @@ { - "version": 4, + "version": 5, "name": "M2 2.9\"", "width": 296, "height": 128, @@ -43,7 +43,8 @@ "day": [ 30, 18, "fonts/twcondensed20", 41, 108 ], "icon": [ 30, 55, 30 ], "wind": [ 18, 26 ], - "line": [ 20, 128 ] + "line": [ 20, 128 ], + "ts_option": 10 }, "9": { "title": [ 2, 0, "bahnschrift20.vlw", 25 ], diff --git a/resources/tagtypes/E0.json b/resources/tagtypes/E0.json index c8ce1f42..2ee7db30 100644 --- a/resources/tagtypes/E0.json +++ b/resources/tagtypes/E0.json @@ -1,5 +1,5 @@ { - "version": 1, + "version": 2, "name": "TFT 320x172", "width": 320, "height": 172, @@ -23,7 +23,8 @@ { "text": [ 10, 95, "Channel:", "bahnschrift20", "#888888", 0, 0, 1 ] }, { "text": [ 120, 95, "{ap_ch}", "bahnschrift20", 0, 0, 0, "1" ] }, { "text": [ 10, 120, "Tag count:", "bahnschrift20", "#888888", 0, 0, 1 ] }, - { "text": [ 120, 120, "{ap_tagcount}", "bahnschrift20", 0, 0, 0, "1" ] } + { "text": [ 120, 120, "{ap_tagcount}", "bahnschrift20", 0, 0, 0, "1" ] }, + { "ts_option": 17} ] } } diff --git a/resources/tagtypes/E1.json b/resources/tagtypes/E1.json index 2cbdb01a..6b1df8b2 100644 --- a/resources/tagtypes/E1.json +++ b/resources/tagtypes/E1.json @@ -1,5 +1,5 @@ { - "version": 1, + "version": 2, "name": "TFT 160x80", "width": 160, "height": 80, @@ -22,7 +22,8 @@ { "text": [ 1, 45, "Ch:", "REFSAN12.vlw", "#888888", 0, 0, 1 ] }, { "text": [ 45, 45, "{ap_ch}", "REFSAN12.vlw", 0, 0, 0, "1" ] }, { "text": [ 1, 62, "Tags:", "REFSAN12.vlw", "#888888", 0, 0, 1 ] }, - { "text": [ 45, 62, "{ap_tagcount}", "REFSAN12.vlw", 0, 0, 0, "1" ] } + { "text": [ 45, 62, "{ap_tagcount}", "REFSAN12.vlw", 0, 0, 0, "1" ] }, + { "ts_option": 25} ] } }