From e4d3d698147fea427e5c6eed60d3318d0ae497d5 Mon Sep 17 00:00:00 2001 From: BlueAndi Date: Wed, 7 Aug 2024 01:01:57 +0200 Subject: [PATCH] Add day name abbreviation at top of every forecast day. --- lib/Views/library.json | 4 +- .../src/layouts/OpenWeatherView64x64.cpp | 58 +++++++++++++++---- lib/Views/src/layouts/OpenWeatherView64x64.h | 3 +- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/lib/Views/library.json b/lib/Views/library.json index 4bd477e8..d281eae8 100644 --- a/lib/Views/library.json +++ b/lib/Views/library.json @@ -9,7 +9,9 @@ "maintainer": true }], "license": "MIT", - "dependencies": [], + "dependencies": [{ + "name": "IRtc" + }], "frameworks": "*", "platforms": "*" } diff --git a/lib/Views/src/layouts/OpenWeatherView64x64.cpp b/lib/Views/src/layouts/OpenWeatherView64x64.cpp index ae7bfe67..5c880c44 100644 --- a/lib/Views/src/layouts/OpenWeatherView64x64.cpp +++ b/lib/Views/src/layouts/OpenWeatherView64x64.cpp @@ -34,6 +34,7 @@ *****************************************************************************/ #include "OpenWeatherView64x64.h" #include +#include /****************************************************************************** * Compiler Switches @@ -103,14 +104,21 @@ OpenWeatherView64x64::OpenWeatherView64x64() : m_fontType(Fonts::FONT_TYPE_DEFAULT), m_weatherIconCurrent(BITMAP_WIDTH, BITMAP_HEIGHT, BITMAP_X, BITMAP_Y), m_weatherInfoCurrentText(TEXT_WIDTH, TEXT_HEIGHT, TEXT_X, TEXT_Y), + m_forecastDayNames{ + { 12U, 8U, 0 * 12U + 2U, 32U }, + { 12U, 8U, 1 * 12U + 2U, 32U }, + { 12U, 8U, 2 * 12U + 2U, 32U }, + { 12U, 8U, 3 * 12U + 2U, 32U }, + { 12U, 8U, 4 * 12U + 2U, 32U }, + }, m_forecastIcons{ - { 12U, 16U, 0 * 12U + 2U, 32U }, - { 12U, 16U, 1 * 12U + 2U, 32U }, - { 12U, 16U, 2 * 12U + 2U, 32U }, - { 12U, 16U, 3 * 12U + 2U, 32U }, - { 12U, 16U, 4 * 12U + 2U, 32U } + { 12U, 8U, 0 * 12U + 2U, 40U }, + { 12U, 8U, 1 * 12U + 2U, 40U }, + { 12U, 8U, 2 * 12U + 2U, 40U }, + { 12U, 8U, 3 * 12U + 2U, 40U }, + { 12U, 8U, 4 * 12U + 2U, 40U } }, - m_forecastTemperatues{ + m_forecastTemperatures{ { 12U, 16U, 0 * 12U + 2U, 48U }, { 12U, 16U, 1 * 12U + 2U, 48U }, { 12U, 16U, 2 * 12U + 2U, 48U }, @@ -139,11 +147,14 @@ OpenWeatherView64x64::OpenWeatherView64x64() : for(day = 0U; day < FORECAST_DAYS; ++day) { + m_forecastDayNames[day].setVerticalAlignment(Alignment::Vertical::VERTICAL_CENTER); + m_forecastDayNames[day].setHorizontalAlignment(Alignment::Horizontal::HORIZONTAL_CENTER); + m_forecastIcons[day].setVerticalAlignment(Alignment::Vertical::VERTICAL_CENTER); m_forecastIcons[day].setHorizontalAlignment(Alignment::Horizontal::HORIZONTAL_CENTER); - m_forecastTemperatues[day].setVerticalAlignment(Alignment::Vertical::VERTICAL_CENTER); - m_forecastTemperatues[day].setHorizontalAlignment(Alignment::Horizontal::HORIZONTAL_CENTER); + m_forecastTemperatures[day].setVerticalAlignment(Alignment::Vertical::VERTICAL_CENTER); + m_forecastTemperatures[day].setHorizontalAlignment(Alignment::Horizontal::HORIZONTAL_CENTER); } } @@ -159,8 +170,9 @@ void OpenWeatherView64x64::update(YAGfx& gfx) for(day = 0U; day < FORECAST_DAYS; ++day) { + m_forecastDayNames[day].update(gfx); m_forecastIcons[day].update(gfx); - m_forecastTemperatues[day].update(gfx); + m_forecastTemperatures[day].update(gfx); } } @@ -307,12 +319,34 @@ void OpenWeatherView64x64::updateWeatherInfoCurrentOnView() void OpenWeatherView64x64::updateWeatherInfoForecastOnView() { - int8_t day; - + int8_t day; + ClockDrv& clockDrv = ClockDrv::getInstance(); + struct tm timeInfo = { 0 }; + bool isClockAvailable = clockDrv.getTime(timeInfo); + uint8_t nextDayOfWeek = static_cast(timeInfo.tm_wday + 1) % 7U; + for(day = 0U; day < FORECAST_DAYS; ++day) { String temperatures; + if (true == isClockAvailable) + { + const uint32_t MAX_DAY_NAME_BUFFER_SIZE = 32U; + char dayName[MAX_DAY_NAME_BUFFER_SIZE]; + + timeInfo.tm_wday = nextDayOfWeek; + if (0U != strftime(dayName, sizeof(dayName), "%a", &timeInfo)) + { + /* Use only the first two characters of the day name. */ + dayName[2U] = '\0'; + + m_forecastDayNames[day].setFormatStr(dayName); + } + + ++nextDayOfWeek; + nextDayOfWeek %= 7U; + } + if (true == m_isWeatherIconForecastUpdated[day]) { String iconFullPath; @@ -332,7 +366,7 @@ void OpenWeatherView64x64::updateWeatherInfoForecastOnView() temperatures += "\n"; appendTemperature(temperatures, m_weatherInfoForecast[day].temperatureMax, true, true); - m_forecastTemperatues[day].setFormatStr(temperatures); + m_forecastTemperatures[day].setFormatStr(temperatures); } } diff --git a/lib/Views/src/layouts/OpenWeatherView64x64.h b/lib/Views/src/layouts/OpenWeatherView64x64.h index f65dd415..33e309eb 100644 --- a/lib/Views/src/layouts/OpenWeatherView64x64.h +++ b/lib/Views/src/layouts/OpenWeatherView64x64.h @@ -328,8 +328,9 @@ class OpenWeatherView64x64 : public IOpenWeatherView Fonts::FontType m_fontType; /**< Font type which shall be used if there is no conflict with the layout. */ BitmapWidget m_weatherIconCurrent; /**< Current weather icon. */ TextWidget m_weatherInfoCurrentText; /**< Current weather info text. */ + TextWidget m_forecastDayNames[FORECAST_DAYS]; /**< Forecast day names */ BitmapWidget m_forecastIcons[FORECAST_DAYS]; /**< Forecast weather icons. */ - TextWidget m_forecastTemperatues[FORECAST_DAYS]; /**< Forecast temperature (min. and max.) */ + TextWidget m_forecastTemperatures[FORECAST_DAYS]; /**< Forecast temperature (min. and max.) */ uint32_t m_viewDuration; /**< The duration in ms, this view will be shown on the display. */ SimpleTimer m_viewDurationTimer; /**< The timer used to determine which weather info to show on the display. */ String m_units; /**< Units (default, metric, imperial) */