Files
Crosspoint/lib/Weather/WeatherIcons.cpp
T
2026-04-02 20:19:19 +02:00

174 lines
6.4 KiB
C++

#include "WeatherIcons.h"
#include "WeatherIcons48.h"
// Weather icon glyph source attribution:
// https://github.com/erikflowers/weather-icons
// Large icons are provided by generated WI48_* arrays in WeatherIcons48.h.
// ============================================================================
// 24x24 Small Weather Icons (1-bit, MSB-first)
// Each row = 24 pixels = 3 bytes. Total = 24 * 3 = 72 bytes per icon.
// ============================================================================
#if WEATHER_ENABLE_SMALL_ICONS
// clang-format off
// Small Clear Day - Sun
static const uint8_t ICON_CLEAR_DAY_24[] = {
0xFF,0xFF,0xFF, 0xFF,0xE7,0xFF, 0xFF,0xE7,0xFF, 0xFF,0xE7,0xFF,
0xF3,0xE7,0xCF, 0xF9,0x00,0x9F, 0xFF,0x00,0xFF, 0xFE,0x00,0x7F,
0xFC,0x00,0x3F, 0xFC,0x00,0x3F, 0xE0,0x00,0x07, 0xE0,0x00,0x07,
0xE0,0x00,0x07, 0xE0,0x00,0x07, 0xFC,0x00,0x3F, 0xFC,0x00,0x3F,
0xFE,0x00,0x7F, 0xFF,0x00,0xFF, 0xF9,0x00,0x9F, 0xF3,0xE7,0xCF,
0xFF,0xE7,0xFF, 0xFF,0xE7,0xFF, 0xFF,0xE7,0xFF, 0xFF,0xFF,0xFF,
};
// Small Clear Night - Moon
static const uint8_t ICON_CLEAR_NIGHT_24[] = {
0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xF0,0xFF, 0xFF,0xE0,0x7F,
0xFF,0xC0,0x3F, 0xFF,0x80,0x3F, 0xFF,0x80,0x7F, 0xFF,0x00,0xFF,
0xFF,0x01,0xFF, 0xFF,0x03,0xFF, 0xFF,0x03,0xFF, 0xFF,0x03,0xFF,
0xFF,0x03,0xFF, 0xFF,0x03,0xFF, 0xFF,0x01,0xFF, 0xFF,0x00,0xFF,
0xFF,0x80,0x7F, 0xFF,0x80,0x3F, 0xFF,0xC0,0x3F, 0xFF,0xE0,0x7F,
0xFF,0xF0,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,
};
// Small Partly Cloudy
static const uint8_t ICON_PARTLY_CLOUDY_24[] = {
0xFF,0xFF,0xFF, 0xFF,0xE7,0xFF, 0xFB,0xE7,0xDF, 0xFD,0x00,0xBF,
0xFF,0x00,0xFF, 0xFE,0x00,0x7F, 0xFE,0x00,0x7F, 0xFC,0x00,0x3F,
0xFF,0x00,0x7F, 0xFE,0x00,0x3F, 0xFC,0x00,0x1F, 0xF8,0x00,0x0F,
0xF0,0x00,0x0F, 0xF0,0x00,0x07, 0xE0,0x00,0x07, 0xE0,0x00,0x07,
0xE0,0x00,0x07, 0xE0,0x00,0x07, 0xF0,0x00,0x0F, 0xF8,0x00,0x1F,
0xFF,0x00,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,
};
// Small Overcast - Cloud
static const uint8_t ICON_OVERCAST_24[] = {
0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,
0xFF,0xF0,0xFF, 0xFF,0xE0,0x7F, 0xFF,0xC0,0x3F, 0xFF,0x80,0x1F,
0xFF,0x00,0x1F, 0xFE,0x00,0x0F, 0xFC,0x00,0x07, 0xF8,0x00,0x07,
0xF0,0x00,0x03, 0xE0,0x00,0x03, 0xE0,0x00,0x03, 0xE0,0x00,0x03,
0xE0,0x00,0x03, 0xF0,0x00,0x07, 0xF8,0x00,0x0F, 0xFE,0x00,0x7F,
0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,
};
// Small Rain
static const uint8_t ICON_RAIN_24[] = {
0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xF0,0xFF, 0xFF,0xE0,0x7F,
0xFF,0x80,0x1F, 0xFF,0x00,0x0F, 0xFE,0x00,0x07, 0xFC,0x00,0x07,
0xF0,0x00,0x03, 0xE0,0x00,0x03, 0xE0,0x00,0x03, 0xE0,0x00,0x03,
0xF0,0x00,0x07, 0xF8,0x00,0x0F, 0xFF,0x00,0xFF, 0xFF,0xFF,0xFF,
0xFE,0xF7,0xBF, 0xFD,0xEF,0x7F, 0xFD,0xEF,0x7F, 0xFB,0xDF,0x7F,
0xFB,0xDF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,
};
// Small Snow
static const uint8_t ICON_SNOW_24[] = {
0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xF0,0xFF, 0xFF,0xE0,0x7F,
0xFF,0x80,0x1F, 0xFF,0x00,0x0F, 0xFE,0x00,0x07, 0xFC,0x00,0x07,
0xF0,0x00,0x03, 0xE0,0x00,0x03, 0xE0,0x00,0x03, 0xE0,0x00,0x03,
0xF0,0x00,0x07, 0xF8,0x00,0x0F, 0xFF,0x00,0xFF, 0xFF,0xFF,0xFF,
0xFE,0xF7,0xBF, 0xFF,0x7B,0xDF, 0xFE,0xF7,0xBF, 0xFF,0x7B,0xDF,
0xFE,0xF7,0xBF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,
};
// Small Thunderstorm
static const uint8_t ICON_THUNDERSTORM_24[] = {
0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xF0,0xFF, 0xFF,0xE0,0x7F,
0xFF,0x80,0x1F, 0xFF,0x00,0x0F, 0xFE,0x00,0x07, 0xFC,0x00,0x07,
0xF0,0x00,0x03, 0xE0,0x00,0x03, 0xE0,0x00,0x03, 0xE0,0x00,0x03,
0xF0,0x00,0x07, 0xF8,0x00,0x0F, 0xFF,0x00,0xFF, 0xFF,0xFF,0xFF,
0xFF,0xF1,0xFF, 0xFF,0xE3,0xFF, 0xFF,0xC0,0xFF, 0xFF,0xF1,0xFF,
0xFF,0xE3,0xFF, 0xFF,0xC7,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,
};
// Small Fog
static const uint8_t ICON_FOG_24[] = {
0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xF0,0x00,0x0F, 0xE0,0x00,0x07,
0xF0,0x00,0x0F, 0xFF,0xFF,0xFF, 0xF8,0x00,0x1F, 0xF0,0x00,0x0F,
0xF8,0x00,0x1F, 0xFF,0xFF,0xFF, 0xF0,0x00,0x0F, 0xE0,0x00,0x07,
0xF0,0x00,0x0F, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,
};
// clang-format on
#endif // WEATHER_ENABLE_SMALL_ICONS
// ============================================================================
// Lookup functions
// ============================================================================
const uint8_t* getWeatherIconLarge(WeatherIconType type) {
switch (type) {
case WeatherIconType::CLEAR_DAY:
return WI48_CLEAR_DAY;
case WeatherIconType::CLEAR_NIGHT:
return WI48_CLEAR_NIGHT;
case WeatherIconType::PARTLY_CLOUDY_DAY:
return WI48_PARTLY_CLOUDY_DAY;
case WeatherIconType::PARTLY_CLOUDY_NIGHT:
return WI48_PARTLY_CLOUDY_NIGHT;
case WeatherIconType::OVERCAST:
return WI48_OVERCAST;
case WeatherIconType::FOG:
return WI48_FOG;
case WeatherIconType::DRIZZLE:
return WI48_DRIZZLE;
case WeatherIconType::RAIN:
case WeatherIconType::SHOWERS:
return WI48_RAIN;
case WeatherIconType::SNOW:
return WI48_SNOW;
case WeatherIconType::THUNDERSTORM:
return WI48_THUNDERSTORM;
default:
return WI48_OVERCAST;
}
}
#if WEATHER_ENABLE_SMALL_ICONS
const uint8_t* getWeatherIconSmall(WeatherIconType type) {
switch (type) {
case WeatherIconType::CLEAR_DAY:
return ICON_CLEAR_DAY_24;
case WeatherIconType::CLEAR_NIGHT:
return ICON_CLEAR_NIGHT_24;
case WeatherIconType::PARTLY_CLOUDY_DAY:
case WeatherIconType::PARTLY_CLOUDY_NIGHT:
return ICON_PARTLY_CLOUDY_24;
case WeatherIconType::OVERCAST:
return ICON_OVERCAST_24;
case WeatherIconType::FOG:
return ICON_FOG_24;
case WeatherIconType::DRIZZLE:
case WeatherIconType::RAIN:
case WeatherIconType::SHOWERS:
return ICON_RAIN_24;
case WeatherIconType::SNOW:
return ICON_SNOW_24;
case WeatherIconType::THUNDERSTORM:
return ICON_THUNDERSTORM_24;
default:
return ICON_OVERCAST_24;
}
}
#endif // WEATHER_ENABLE_SMALL_ICONS
const char* getWindDirectionText(int degrees) {
// Normalize to 0-360
degrees = ((degrees % 360) + 360) % 360;
if (degrees >= 338 || degrees < 23) return "N";
if (degrees < 68) return "NE";
if (degrees < 113) return "E";
if (degrees < 158) return "SE";
if (degrees < 203) return "S";
if (degrees < 248) return "SW";
if (degrees < 293) return "W";
return "NW";
}