From 0a51b973cb990e1b2b92cfed4dd2c50d77708dc0 Mon Sep 17 00:00:00 2001 From: Sergey Ryazanov Date: Thu, 21 Dec 2023 12:11:21 +0400 Subject: [PATCH] Remove support of Four-line display Four line Display support removed because the Display font cannot draw the Celsius symbol and wind direction --- usermods/usermod_v2_yandex_weather/README.md | 3 - .../usermod_v2_yandex_weather.h | 60 ++++--------------- 2 files changed, 10 insertions(+), 53 deletions(-) diff --git a/usermods/usermod_v2_yandex_weather/README.md b/usermods/usermod_v2_yandex_weather/README.md index 286ecea6..16fa3971 100644 --- a/usermods/usermod_v2_yandex_weather/README.md +++ b/usermods/usermod_v2_yandex_weather/README.md @@ -21,8 +21,6 @@ build_flags = ${env:esp32dev.build_flags} - `void setEnable(bool enable)` – To change enable state - `bool isEnable()` – To query enable state - `WeatherInfo *currentWeather()` – To query current weather struct -- `inline bool drawWeatherOnDisplay(long howLong)` – Show current weather (if available) on four line display for _howLong_ milliseconds. -See _YA_WEATHER_DRAW_ in __Additional Build Flags__ section ### Access from other Usermod @@ -98,7 +96,6 @@ Enable post weather data to MQTT topic (/yandexWeather) | YA_WEATHER_DEBUG | Show debug message with _[YandexWeatherUsermod]_ prefix | | YA_WEATHER_ALLOW_ALL_TIMEOUT | Allows you to set UpdateInterval to less than 30 (Use for tests or if you have a paid ApiKey) | | YA_WEATHER_HIDE_REMAINING | Hide the remaining time to update in Info | -| YA_WEATHER_DRAW | Enable support of [Four Line Display](https://mm.kno.wled.ge/usermods/4LineDisplay) | ----- Author: diff --git a/usermods/usermod_v2_yandex_weather/usermod_v2_yandex_weather.h b/usermods/usermod_v2_yandex_weather/usermod_v2_yandex_weather.h index cee0ba30..a0c63ea4 100644 --- a/usermods/usermod_v2_yandex_weather/usermod_v2_yandex_weather.h +++ b/usermods/usermod_v2_yandex_weather/usermod_v2_yandex_weather.h @@ -6,13 +6,6 @@ // #define YA_WEATHER_DEBUG // Show debug message with [YandexWeatherUsermod] prefix // #define YA_WEATHER_ALLOW_ALL_TIMEOUT // Allows you to set UpdateInterval to less than 30 // #define YA_WEATHER_HIDE_REMAINING // Hide the remaining time to update in Info -// #define YA_WEATHER_DRAW // Enable support of Four Line Display - -#ifdef YA_WEATHER_DRAW -#ifndef USERMOD_FOUR_LINE_DISPLAY -#undef YA_WEATHER_DRAW -#endif -#endif class YandexWeatherUsermod: public Usermod { @@ -47,10 +40,6 @@ private: char errorMessage[100] = ""; WeatherInfo *_weatherInfo; - #ifdef YA_WEATHER_DRAW - FourLineDisplayUsermod* display; - #endif - // configurable parameters String _apiKey = ""; int _updateInterval = 30; @@ -108,25 +97,22 @@ private: inline String firstWeatherLine() { if (_weatherInfo == nullptr) return String(F("")); - String res = ""; - res += _weatherInfo->tempReal; - res += F("°C\n(like "); - res += _weatherInfo->tempFeels; - res += F("°C)"); - return res; + char r[20]; + sprintf_P(r, "%d (like %d)", _weatherInfo->tempReal, _weatherInfo->tempFeels); + return String(r); } inline String secondWeatherLine() { if (_weatherInfo == nullptr) return String(F("")); - String res = ""; - res += _weatherInfo->windSpeed; - res += F(" m/s"); + char r[15]; + sprintf(r, "%.2f m/s", _weatherInfo->windSpeed); + if (!_weatherInfo->windDir.isEmpty()) { - res += F(" ("); - res += String(windCharByString(_weatherInfo->windDir.c_str()).c_str()); - res += F(")"); + char wd[4]; + sprintf(wd, "(%s)", windCharByString(_weatherInfo->windDir.c_str()).c_str()); + strcat(r, wd); } - return res; + return String(r); } // Helping functions @@ -369,35 +355,9 @@ public: return apiGetWeather(errorMessage); } - /** - * Show weather (if exists) on Four line Display - * @param howLong Display time in milliseconds - * @return `true` – If displayed successfully, otherwise – `false` - */ - inline bool drawWeatherOnDisplay(long howLong) { - #ifdef YA_WEATHER_DRAW - if (display != nullptr) { - display->wakeDisplay(); - #if defined(USE_ALT_DISPLAY) || defined(USE_ALT_DISPlAY) - if (display->canDraw()) display->overlay(firstWeatherLine().c_str(), secondWeatherLine().c_str(), howLong); // WLEDMM bugfix - #else - display->overlay(firstWeatherLine().c_str(), secondWeatherLine().c_str(), howLong); - #endif - return true; - } else { - return false; - } - #else - return false; - #endif - } - // WLED lyfecycle void setup() { - #ifdef YA_WEATHER_DRAW - display = (FourLineDisplayUsermod*) usermods.lookup(USERMOD_ID_FOUR_LINE_DISP); - #endif initDone = true; }