Added support for ts_option to provide finer control of time stamps.

1. Fixed time stamp overlap on weather forecast content on  2.9" tags.
2. Fixed time stamp overlap on AP info screen on 160x80 TFT displays.
3. Changed black on white to white on black on TFT displays.
This commit is contained in:
Skip Hansen
2025-11-06 15:38:21 -05:00
parent ef5ddac368
commit bfff2ef0b9
6 changed files with 74 additions and 13 deletions

View File

@@ -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);

View File

@@ -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<int>()) {
// Overide ts_option if present in template
imageParams.ts_option = loc["ts_option"];
}
else {
const JsonArray jsonArray = loc.as<JsonArray>();
for (const JsonVariant &elem : jsonArray) {
if(elem["ts_option"].is<int>()) {
// 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

View File

@@ -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") {

View File

@@ -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 ],

View File

@@ -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}
]
}
}

View File

@@ -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}
]
}
}