| 863 | } |
| 864 | |
| 865 | void drawDate(String &filename, JsonObject &cfgobj, tagRecord *&taginfo, imgParam &imageParams) { |
| 866 | time_t now; |
| 867 | time(&now); |
| 868 | struct tm timeinfo; |
| 869 | localtime_r(&now, &timeinfo); |
| 870 | |
| 871 | const int month_number = timeinfo.tm_mon; |
| 872 | const int year_number = timeinfo.tm_year + 1900; |
| 873 | |
| 874 | if (taginfo->hwType == SOLUM_SEG_UK) { |
| 875 | sprintf(imageParams.segments, "%2d%2d%-2.2s%04d", timeinfo.tm_mday, month_number + 1, languageDays[timeinfo.tm_wday], year_number); |
| 876 | imageParams.symbols = 0x04; |
| 877 | return; |
| 878 | } |
| 879 | |
| 880 | JsonDocument loc; |
| 881 | getTemplate(loc, 1, taginfo->hwType); |
| 882 | |
| 883 | TFT_eSprite spr = TFT_eSprite(&tft); |
| 884 | initSprite(spr, imageParams.width, imageParams.height, imageParams); |
| 885 | |
| 886 | auto date = loc["date"]; |
| 887 | auto weekday = loc["weekday"]; |
| 888 | const auto &month = loc["month"]; |
| 889 | const auto &day = loc["day"]; |
| 890 | |
| 891 | if (cfgobj["location"]) { |
| 892 | const String lat = cfgobj["#lat"]; |
| 893 | const String lon = cfgobj["#lon"]; |
| 894 | JsonDocument doc; |
| 895 | |
| 896 | const bool success = util::httpGetJson("https://api.farmsense.net/v1/daylengths/?d=" + String(now) + "&lat=" + lat + "&lon=" + lon + "&tz=UTC", doc, 5000); |
| 897 | if (success && loc["sunrise"].is<JsonArray>()) { |
| 898 | String sunrise = formatUtcToLocal(doc[0]["Sunrise"]); |
| 899 | String sunset = formatUtcToLocal(doc[0]["Sunset"]); |
| 900 | const auto &sunriseicon = loc["sunrise"]; |
| 901 | const auto &sunseticon = loc["sunset"]; |
| 902 | drawString(spr, String("\uF046 "), sunriseicon[0], sunriseicon[1].as<int>(), "/fonts/weathericons.ttf", TR_DATUM, TFT_BLACK, sunriseicon[3]); |
| 903 | drawString(spr, String("\uF047 "), sunseticon[0], sunseticon[1].as<int>(), "/fonts/weathericons.ttf", TR_DATUM, TFT_BLACK, sunseticon[3]); |
| 904 | drawString(spr, sunrise, sunriseicon[0], sunriseicon[1], sunriseicon[2], TL_DATUM, TFT_BLACK, sunriseicon[3]); |
| 905 | drawString(spr, sunset, sunseticon[0], sunseticon[1], sunseticon[2], TL_DATUM, TFT_BLACK, sunseticon[3]); |
| 906 | |
| 907 | const bool success = util::httpGetJson("https://api.farmsense.net/v1/moonphases/?d=" + String(now), doc, 5000); |
| 908 | if (success && loc["moonicon"].is<JsonArray>()) { |
| 909 | uint8_t moonage = doc[0]["Index"].as<int>(); |
| 910 | const auto &moonicon = loc["moonicon"]; |
| 911 | uint16_t moonIconId = 0xf095 + moonage; |
| 912 | String moonIcon = utf8FromCodepoint(moonIconId); |
| 913 | drawString(spr, moonIcon, moonicon[0], moonicon[1], "/fonts/weathericons.ttf", TC_DATUM, TFT_BLACK, moonicon[2]); |
| 914 | } |
| 915 | |
| 916 | date = loc["altdate"]; |
| 917 | weekday = loc["altweekday"]; |
| 918 | } |
| 919 | } |
| 920 | if (date.is<JsonArray>()) { |
| 921 | drawString(spr, languageDays[timeinfo.tm_wday], weekday[0], weekday[1], weekday[2], TC_DATUM, imageParams.highlightColor, weekday[3]); |
| 922 | drawString(spr, String(timeinfo.tm_mday) + " " + languageMonth[timeinfo.tm_mon], date[0], date[1], date[2], TC_DATUM, TFT_BLACK, date[3]); |
no test coverage detected