From 9d396555314097498bd96b6331f135470af6b495 Mon Sep 17 00:00:00 2001 From: e2002 Date: Mon, 27 Feb 2023 16:58:13 +0300 Subject: [PATCH] ext_weather --- yoRadio/fonts/glcdfont.c | 2 +- yoRadio/locale/displayL10n_en.h | 20 ++++++++++++++- yoRadio/locale/displayL10n_ru.h | 20 ++++++++++++++- yoRadio/src/core/config.h | 4 ++- yoRadio/src/core/display.cpp | 2 +- yoRadio/src/core/network.cpp | 45 +++++++++++++++++++++++++++------ yoRadio/src/core/options.h | 2 +- 7 files changed, 81 insertions(+), 14 deletions(-) diff --git a/yoRadio/fonts/glcdfont.c b/yoRadio/fonts/glcdfont.c index 95bf7c0..1b35c7e 100644 --- a/yoRadio/fonts/glcdfont.c +++ b/yoRadio/fonts/glcdfont.c @@ -22,7 +22,7 @@ static const unsigned char font[] PROGMEM = { 0x18, 0x5C, 0x7F, 0x5C, 0x18, 0x00, 0x1C, 0x1C, 0x1C, 0x00, 0x7F, 0x63, 0x63, 0x63, 0x7F, -0x00, 0x1C, 0x14, 0x1C, 0x00, +0x06, 0x09, 0x09, 0x06, 0x00, 0x7F, 0x63, 0x6B, 0x63, 0x7F, 0x30, 0x48, 0x4D, 0x33, 0x07, 0x06, 0x29, 0x79, 0x29, 0x06, diff --git a/yoRadio/locale/displayL10n_en.h b/yoRadio/locale/displayL10n_en.h index 6cf95d4..948844f 100644 --- a/yoRadio/locale/displayL10n_en.h +++ b/yoRadio/locale/displayL10n_en.h @@ -35,9 +35,27 @@ const char oct[] PROGMEM = "october"; const char nov[] PROGMEM = "november"; const char dec[] PROGMEM = "december"; +const char wn_N[] PROGMEM = "N"; +const char wn_NNE[] PROGMEM = "NNE"; +const char wn_NE[] PROGMEM = "NE"; +const char wn_ENE[] PROGMEM = "ENE"; +const char wn_E[] PROGMEM = "E"; +const char wn_ESE[] PROGMEM = "ESE"; +const char wn_SE[] PROGMEM = "SE"; +const char wn_SSE[] PROGMEM = "SSE"; +const char wn_S[] PROGMEM = "S"; +const char wn_SSW[] PROGMEM = "SSW"; +const char wn_SW[] PROGMEM = "SW"; +const char wn_WSW[] PROGMEM = "WSW"; +const char wn_W[] PROGMEM = "W"; +const char wn_WNW[] PROGMEM = "WNW"; +const char wn_NW[] PROGMEM = "NW"; +const char wn_NNW[] PROGMEM = "NNW"; + const char* const dow[] PROGMEM = { sun, mon, tue, wed, thu, fri, sat }; const char* const dowf[] PROGMEM = { sunf, monf, tuef, wedf, thuf, frif, satf }; const char* const mnths[] PROGMEM = { jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec }; +const char* const wind[] PROGMEM = { wn_N, wn_NNE, wn_NE, wn_ENE, wn_E, wn_ESE, wn_SE, wn_SSE, wn_S, wn_SSW, wn_SW, wn_WSW, wn_W, wn_WNW, wn_NW, wn_NNW, wn_N }; const char const_PlReady[] PROGMEM = "[ready]"; const char const_PlStopped[] PROGMEM = "[stopped]"; @@ -52,7 +70,7 @@ const char apNameTxt[] PROGMEM = "AP NAME"; const char apPassTxt[] PROGMEM = "PASSWORD"; const char bootstrFmt[] PROGMEM = "Trying to %s"; const char apSettFmt[] PROGMEM = "SETTINGS PAGE ON: HTTP://%s/"; -const char weatherFmt[] PROGMEM = "%s, %.1f C * pressure: %d mm * humidity: %s%%"; +const char weatherFmt[] PROGMEM = "%s, %.1f\011C \007 feels like: %.1f\011C \007 pressure: %d мм * humidity: %s%% \007 wind: [%s] %.1f m/s"; const char weatherUnits[] PROGMEM = "metric"; /* standard, metric, imperial */ const char weatherLang[] PROGMEM = "en"; /* https://openweathermap.org/current#multi */ diff --git a/yoRadio/locale/displayL10n_ru.h b/yoRadio/locale/displayL10n_ru.h index e57dc73..80b278b 100644 --- a/yoRadio/locale/displayL10n_ru.h +++ b/yoRadio/locale/displayL10n_ru.h @@ -35,9 +35,27 @@ const char oct[] PROGMEM = "октября"; const char nov[] PROGMEM = "ноября"; const char dec[] PROGMEM = "декабря"; +const char wn_N[] PROGMEM = "С"; +const char wn_NNE[] PROGMEM = "ССВ"; +const char wn_NE[] PROGMEM = "СВ"; +const char wn_ENE[] PROGMEM = "ВСВ"; +const char wn_E[] PROGMEM = "В"; +const char wn_ESE[] PROGMEM = "ВЮВ"; +const char wn_SE[] PROGMEM = "ЮВ"; +const char wn_SSE[] PROGMEM = "ЮЮВ"; +const char wn_S[] PROGMEM = "Ю"; +const char wn_SSW[] PROGMEM = "ЮЮЗ"; +const char wn_SW[] PROGMEM = "ЮЗ"; +const char wn_WSW[] PROGMEM = "ЗЮЗ"; +const char wn_W[] PROGMEM = "З"; +const char wn_WNW[] PROGMEM = "ЗСЗ"; +const char wn_NW[] PROGMEM = "СЗ"; +const char wn_NNW[] PROGMEM = "ССЗ"; + const char* const dow[] PROGMEM = { sun, mon, tue, wed, thu, fri, sat }; const char* const dowf[] PROGMEM = { sunf, monf, tuef, wedf, thuf, frif, satf }; const char* const mnths[] PROGMEM = { jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec }; +const char* const wind[] PROGMEM = { wn_N, wn_NNE, wn_NE, wn_ENE, wn_E, wn_ESE, wn_SE, wn_SSE, wn_S, wn_SSW, wn_SW, wn_WSW, wn_W, wn_WNW, wn_NW, wn_NNW, wn_N }; const char const_PlReady[] PROGMEM = "[готов]"; const char const_PlStopped[] PROGMEM = "[остановлено]"; @@ -52,7 +70,7 @@ const char apNameTxt[] PROGMEM = "ТОЧКА ДОСТУПА"; const char apPassTxt[] PROGMEM = "ПАРОЛЬ"; const char bootstrFmt[] PROGMEM = "Соединяюсь с %s"; const char apSettFmt[] PROGMEM = "НАСТРОЙКИ: HTTP://%s/"; -const char weatherFmt[] PROGMEM = "%s, %.1f C * давление: %d мм * влажность: %s%%"; +const char weatherFmt[] PROGMEM = "%s, %.1f\011C \007 ощущается: %.1f\011C \007 давление: %d мм \007 влажность: %s%% \007 ветер: %s\013%.1f м/с"; const char weatherUnits[] PROGMEM = "metric"; /* standard, metric, imperial */ const char weatherLang[] PROGMEM = "ru"; /* https://openweathermap.org/current#multi */ diff --git a/yoRadio/src/core/config.h b/yoRadio/src/core/config.h index 8ac3add..c84b861 100644 --- a/yoRadio/src/core/config.h +++ b/yoRadio/src/core/config.h @@ -11,7 +11,9 @@ #define EEPROM_START 500 #define EEPROM_START_IR 0 #define EEPROM_START_2 10 -#define BUFLEN 140 +#ifndef BUFLEN + #define BUFLEN 170 +#endif #define PLAYLIST_PATH "/data/playlist.csv" #define SSIDS_PATH "/data/wifi.csv" #define TMP_PATH "/data/tmpfile.txt" diff --git a/yoRadio/src/core/display.cpp b/yoRadio/src/core/display.cpp index 94c8a3a..ccad4f1 100644 --- a/yoRadio/src/core/display.cpp +++ b/yoRadio/src/core/display.cpp @@ -116,7 +116,7 @@ void Display::_buildPager(){ #endif _nums.init(numConf, 10, false, config.theme.digit, config.theme.background); #ifndef HIDE_WEATHER - _weather = new ScrollWidget("*", weatherConf, config.theme.weather, config.theme.background); + _weather = new ScrollWidget("\007", weatherConf, config.theme.weather, config.theme.background); #endif if(_volbar) _footer.addWidget( _volbar); diff --git a/yoRadio/src/core/network.cpp b/yoRadio/src/core/network.cpp index fc96c90..fbcf5ff 100644 --- a/yoRadio/src/core/network.cpp +++ b/yoRadio/src/core/network.cpp @@ -249,17 +249,17 @@ bool getWeather(char *wstr) { tmpe = strstr(tmps, ",\""); if (tmpe == NULL) { Serial.println("## OPENWEATHERMAP ###: temp not found !"); return false;} strlcpy(temp, tmps, tmpe - tmps + 1); - cursor = tmpe + 2; + cursor = tmpe + 1; float tempf = atof(temp); - tmps = strstr(cursor, "\"pressure\":"); - if (tmps == NULL) { Serial.println("## OPENWEATHERMAP ###: pressure not found !"); return false;} - tmps += 11; + tmps = strstr(cursor, "\"feels_like\":"); + if (tmps == NULL) { Serial.println("## OPENWEATHERMAP ###: feels_like not found !"); return false;} + tmps += 13; tmpe = strstr(tmps, ",\""); - if (tmpe == NULL) { Serial.println("## OPENWEATHERMAP ###: pressure not found !"); return false;} - strlcpy(press, tmps, tmpe - tmps + 1); + if (tmpe == NULL) { Serial.println("## OPENWEATHERMAP ###: feels_like not found !"); return false;} + strlcpy(temp, tmps, tmpe - tmps + 1); cursor = tmpe + 2; - int pressi = (float)atoi(press) / 1.333; + float tempfl = atof(temp); tmps = strstr(cursor, "humidity\":"); if (tmps == NULL) { Serial.println("## OPENWEATHERMAP ###: humidity not found !"); return false;} @@ -269,6 +269,35 @@ bool getWeather(char *wstr) { if (tmpe == NULL) { Serial.println("## OPENWEATHERMAP ###: humidity not found !"); return false;} strlcpy(hum, tmps, tmpe - tmps + (tmpc>tmpe?1:0)); + tmps = strstr(cursor, "\"grnd_level\":"); + if (tmps == NULL) { Serial.println("## OPENWEATHERMAP ###: pressure not found !"); return false;} + tmps += 13; + tmpe = strstr(tmps, ",\""); + if (tmpe == NULL) { Serial.println("## OPENWEATHERMAP ###: pressure not found !"); return false;} + strlcpy(press, tmps, tmpe - tmps + 1); + cursor = tmpe + 2; + int pressi = (float)atoi(press) / 1.333; + + tmps = strstr(cursor, "\"speed\":"); + if (tmps == NULL) { Serial.println("## OPENWEATHERMAP ###: wind speed not found !"); return false;} + tmps += 8; + tmpe = strstr(tmps, ",\""); + if (tmpe == NULL) { Serial.println("## OPENWEATHERMAP ###: wind speed not found !"); return false;} + strlcpy(temp, tmps, tmpe - tmps + 1); + cursor = tmpe + 1; + float wind_speed = atof(temp); + + tmps = strstr(cursor, "\"deg\":"); + if (tmps == NULL) { Serial.println("## OPENWEATHERMAP ###: wind deg not found !"); return false;} + tmps += 6; + tmpe = strstr(tmps, ",\""); + if (tmpe == NULL) { Serial.println("## OPENWEATHERMAP ###: wind deg not found !"); return false;} + strlcpy(temp, tmps, tmpe - tmps + 1); + cursor = tmpe + 1; + int wind_deg = atof(temp)/22.5; + if(wind_deg<0) wind_deg = 16+wind_deg; + + #ifdef USE_NEXTION nextion.putcmdf("press_txt.txt=\"%dmm\"", pressi); nextion.putcmdf("hum_txt.txt=\"%d%%\"", atoi(hum)); @@ -294,7 +323,7 @@ bool getWeather(char *wstr) { #ifdef WEATHER_FMT_SHORT sprintf(wstr, weatherFmt, tempf, pressi, hum); #else - sprintf(wstr, weatherFmt, desc, tempf, pressi, hum); + sprintf(wstr, weatherFmt, desc, tempf, tempfl, pressi, hum, wind[wind_deg], wind_speed); #endif network.requestWeatherSync(); return true; diff --git a/yoRadio/src/core/options.h b/yoRadio/src/core/options.h index 19dbc89..6ed0815 100644 --- a/yoRadio/src/core/options.h +++ b/yoRadio/src/core/options.h @@ -1,7 +1,7 @@ #ifndef options_h #define options_h -#define YOVERSION "0.8.962" +#define YOVERSION "0.8.971" /******************************************************* DO NOT EDIT THIS FILE.