diff --git a/ESP32_AP-Flasher/include/contentmanager.h b/ESP32_AP-Flasher/include/contentmanager.h index 47dba399..f4948a6b 100644 --- a/ESP32_AP-Flasher/include/contentmanager.h +++ b/ESP32_AP-Flasher/include/contentmanager.h @@ -48,4 +48,5 @@ void getLocation(JsonObject &cfgobj); void prepareNFCReq(const uint8_t *dst, const char *url); void prepareLUTreq(const uint8_t *dst, const String &input); void prepareConfigFile(const uint8_t *dst, const JsonObject &config); +void prepareTIME_RAW(const uint8_t *dst, time_t now); void getTemplate(JsonDocument &json, const uint8_t id, const uint8_t hwtype); diff --git a/ESP32_AP-Flasher/src/contentmanager.cpp b/ESP32_AP-Flasher/src/contentmanager.cpp index 5012f5c6..29f860d1 100644 --- a/ESP32_AP-Flasher/src/contentmanager.cpp +++ b/ESP32_AP-Flasher/src/contentmanager.cpp @@ -10,6 +10,7 @@ #define CONTENT_TIMESTAMP #define CONTENT_BUIENRADAR #define CONTENT_CAL +#define CONTENT_TIME_RAWDATA #endif #define CONTENT_TAGCFG @@ -573,6 +574,13 @@ void drawNew(const uint8_t mac[8], tagRecord *&taginfo) { taginfo->nextupdate = 3216153600; break; } +#ifdef CONTENT_TIME_RAWDATA + case 29: // Time and raw data like strings etc. in the future + + taginfo->nextupdate = now + 1800; + prepareTIME_RAW(mac, now); + break; +#endif } taginfo->modeConfigJson = doc.as(); @@ -2481,6 +2489,60 @@ void prepareConfigFile(const uint8_t *dst, const JsonObject &config) { } #endif +#ifdef CONTENT_TIME_RAWDATA +bool is_leap_year(int year) {// Somehow mktime did not return the local unix time so lets to it in a manual way + year += 1900; + return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); +} +int days_in_month(int month, int year) { + static const int days[] = { 31, 28, 31, 30, 31, 30, + 31, 31, 30, 31, 30, 31 }; + if (month == 1 && is_leap_year(year)) { + return 29; + } + return days[month]; +} +uint32_t convert_tm_to_seconds(struct tm *t) { + const int SECONDS_PER_MINUTE = 60; + const int SECONDS_PER_HOUR = 3600; + const int SECONDS_PER_DAY = 86400; + long long total_days = 0; + for (int year = 70; year < t->tm_year; year++) { + total_days += is_leap_year(year) ? 366 : 365; + } + for (int month = 0; month < t->tm_mon; month++) { + total_days += days_in_month(month, t->tm_year); + } + total_days += (t->tm_mday - 1); + long long total_seconds = total_days * SECONDS_PER_DAY; + total_seconds += t->tm_hour * SECONDS_PER_HOUR; + total_seconds += t->tm_min * SECONDS_PER_MINUTE; + total_seconds += t->tm_sec; + return total_seconds; +} + +void prepareTIME_RAW(const uint8_t *dst, time_t now) { + uint8_t *data; + size_t len = 1 + 4 + 4; + struct tm timeinfo; + localtime_r(&now, &timeinfo); + uint32_t local_time = convert_tm_to_seconds(&timeinfo) + 20;// Adding 20 seconds for the average of upload time + uint32_t unix_time = now + 20; + data = new uint8_t[len + 1]; + data[0] = len;// Length all + data[1] = 0x01;// Version of Time and RAW + data[2] = ((uint8_t*)&local_time)[0]; + data[3] = ((uint8_t*)&local_time)[1]; + data[4] = ((uint8_t*)&local_time)[2]; + data[5] = ((uint8_t*)&local_time)[3]; + data[6] = ((uint8_t*)&unix_time)[0]; + data[7] = ((uint8_t*)&unix_time)[1]; + data[8] = ((uint8_t*)&unix_time)[2]; + data[9] = ((uint8_t*)&unix_time)[3]; + prepareDataAvail(data, len + 1, DATATYPE_TIME_RAW_DATA, dst); +} +#endif + void getTemplate(JsonDocument &json, const uint8_t id, const uint8_t hwtype) { JsonDocument filter; JsonDocument doc; diff --git a/ESP32_AP-Flasher/wwwroot/content_cards.json b/ESP32_AP-Flasher/wwwroot/content_cards.json index 1c7f2bba..00af7db6 100644 --- a/ESP32_AP-Flasher/wwwroot/content_cards.json +++ b/ESP32_AP-Flasher/wwwroot/content_cards.json @@ -742,5 +742,12 @@ "type": "binfile" } ] + }, + { + "id": 29, + "name": "Current Time", + "desc": "Displays the current time on the tag, only rarely supported even if shown here! It uses a fast LUT when possible otherwise a full refresh which is not very battery friendly and will anoy by flickering every minute", + "param": [ + ] } ] diff --git a/oepl-definitions.h b/oepl-definitions.h index 50049a12..2ffb5baf 100755 --- a/oepl-definitions.h +++ b/oepl-definitions.h @@ -133,6 +133,7 @@ #define DATATYPE_TAG_CONFIG_DATA 0xA8 // Config data for tag #define DATATYPE_COMMAND_DATA 0xAF // Command for the tag to execute (contained in availableData Reply) #define DATATYPE_CUSTOM_LUT_OTA 0xB0 // Custom OTA updated LUT +#define DATATYPE_TIME_RAW_DATA 0xC0 // Used for showning the time and preparation for more data #define CMD_DO_REBOOT 0 #define CMD_DO_SCAN 1 diff --git a/resources/tagtypes/54.json b/resources/tagtypes/54.json index f421cd88..f4bf5fc0 100644 --- a/resources/tagtypes/54.json +++ b/resources/tagtypes/54.json @@ -1,5 +1,5 @@ { - "version": 3, + "version": 4, "name": "HS BW 2.13\"", "width": 256, "height": 128, @@ -12,7 +12,7 @@ "shortlut": 0, "zlib_compression": "27", "options": [ "led" ], - "contentids": [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 16, 17, 19, 20, 21, 22, 23, 27 ], + "contentids": [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 16, 17, 19, 20, 21, 22, 23, 27, 29 ], "template": { "1": { diff --git a/resources/tagtypes/55.json b/resources/tagtypes/55.json index 1d22c378..36c53eeb 100644 --- a/resources/tagtypes/55.json +++ b/resources/tagtypes/55.json @@ -1,5 +1,5 @@ { - "version": 4, + "version": 5, "name": "HS BWR 2.13\"", "width": 256, "height": 128, @@ -13,7 +13,7 @@ "shortlut": 0, "zlib_compression": "27", "options": [ "led" ], - "contentids": [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 16, 17, 19, 20, 21, 22, 23, 27 ], + "contentids": [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 16, 17, 19, 20, 21, 22, 23, 27, 29 ], "template": { "1": { diff --git a/resources/tagtypes/56.json b/resources/tagtypes/56.json index 5622a40b..e78dc88d 100644 --- a/resources/tagtypes/56.json +++ b/resources/tagtypes/56.json @@ -1,5 +1,5 @@ { - "version": 5, + "version": 6, "name": "HS BWR 2.66\"", "width": 296, "height": 152, @@ -13,7 +13,7 @@ "shortlut": 0, "zlib_compression": "27", "options": [ "led" ], - "contentids": [ 22, 23, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 16, 17, 18, 19, 20, 21, 27 ], + "contentids": [ 22, 23, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 16, 17, 18, 19, 20, 21, 27, 29 ], "template": { "1": { "weekday": [ 148, 9, "Signika-SB.ttf", 60 ], diff --git a/resources/tagtypes/60.json b/resources/tagtypes/60.json index 361d78fd..69c65efe 100644 --- a/resources/tagtypes/60.json +++ b/resources/tagtypes/60.json @@ -1,5 +1,5 @@ { - "version": 5, + "version": 6, "name": "HS BWY 3.5\"", "width": 384, "height": 184, @@ -19,7 +19,7 @@ "shortlut": 0, "zlib_compression": "27", "options": [ "led" ], - "contentids": [ 22, 23, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 17, 18, 19, 20, 27 ], + "contentids": [ 22, 23, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 17, 18, 19, 20, 27, 29 ], "usetemplate": 51, "template": { "27": {