MCPcopy Create free account
hub / github.com/OpenEPaperLink/OpenEPaperLink / drawWeatherContent

Function drawWeatherContent

ESP32_AP-Flasher/src/contentmanager.cpp:995–1040  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

993}
994
995void drawWeatherContent(JsonDocument &doc, JsonDocument &loc, TFT_eSprite &spr, JsonObject &cfgobj, imgParam &imageParams, bool isForecast = false) {
996 const auto &currentWeather = doc["current_weather"];
997 const double temperature = currentWeather["temperature"].as<double>();
998 float windspeed = currentWeather["windspeed"].as<float>();
999 int windval = 0;
1000 const int winddirection = currentWeather["winddirection"].as<int>();
1001 const bool isNight = currentWeather["is_day"].as<int>() == 0;
1002 uint8_t weathercode = currentWeather["weathercode"].as<int>();
1003 if (weathercode > 40) weathercode -= 40;
1004
1005 const uint8_t beaufort = windSpeedToBeaufort(windspeed);
1006 if (cfgobj["units"] != "1") {
1007 windval = beaufort;
1008 } else {
1009 windval = int(windspeed);
1010 }
1011
1012 if (!isForecast) {
1013 const auto &location = loc["location"];
1014 drawString(spr, cfgobj["location"], location[0], location[1], location[2]);
1015 }
1016 const auto &wind = isForecast ? loc["currentwind"] : loc["wind"];
1017 drawString(spr, String(windval), wind[0], wind[1], wind[2], TR_DATUM, (beaufort > 4 ? imageParams.highlightColor : TFT_BLACK));
1018
1019 char tmpOutput[5];
1020 dtostrf(temperature, 2, 1, tmpOutput);
1021 const auto &temp = loc["temp"];
1022
1023 String temperatureStr = String(tmpOutput);
1024 if (temp[3] && temp[3] == 1) {
1025 temperatureStr += (cfgobj["units"] == "1") ? "°" : "°";
1026 }
1027 drawString(spr, temperatureStr, temp[0], temp[1], temp[2], TL_DATUM, (temperature < 0 ? imageParams.highlightColor : TFT_BLACK));
1028
1029 const int iconcolor = (weathercode == 55 || weathercode == 65 || weathercode == 75 || weathercode == 82 || weathercode == 86 || weathercode == 95 || weathercode == 96 || weathercode == 99)
1030 ? imageParams.highlightColor
1031 : TFT_BLACK;
1032 const auto &icon = isForecast ? loc["currenticon"] : loc["icon"];
1033 drawString(spr, getWeatherIcon(weathercode, isNight), icon[0], icon[1], "/fonts/weathericons.ttf", icon[3], iconcolor, icon[2]);
1034 const auto &dir = loc["dir"];
1035 drawString(spr, windDirectionIcon(winddirection), dir[0], dir[1], "/fonts/weathericons.ttf", TC_DATUM, TFT_BLACK, dir[2]);
1036 if (weathercode > 10) {
1037 const auto &umbrella = loc["umbrella"];
1038 drawString(spr, "\uf084", umbrella[0], umbrella[1], "/fonts/weathericons.ttf", TC_DATUM, imageParams.highlightColor, umbrella[2]);
1039 }
1040}
1041
1042void drawWeather(String &filename, JsonObject &cfgobj, const tagRecord *taginfo, imgParam &imageParams) {
1043 wsLog("get weather");

Callers 2

drawWeatherFunction · 0.85
drawForecastFunction · 0.85

Calls 4

windSpeedToBeaufortFunction · 0.85
drawStringFunction · 0.85
getWeatherIconFunction · 0.85
windDirectionIconFunction · 0.85

Tested by

no test coverage detected