InfiniTime.git

commit d29eb1ea994c1a8445bafc67d718aa017a5eba20

Author: Jean-François Milants <jf@codingfield.com>

Simple Weather Service - code cleaning and improvements

Remove unused Weather debug app.
Fix formatting in SimpleWeatherService.cpp.

 src/components/ble/SimpleWeatherService.cpp | 12 
 src/displayapp/screens/Weather.cpp | 221 -----------------------
 src/displayapp/screens/Weather.h | 58 ------


diff --git a/src/components/ble/SimpleWeatherService.cpp b/src/components/ble/SimpleWeatherService.cpp
index 3635fdfdd092c46719bb7ec46070004c221b2ae5..61ad49267ed0cf6f5b3ecd24662e98d974a6ddad 100644
--- a/src/components/ble/SimpleWeatherService.cpp
+++ b/src/components/ble/SimpleWeatherService.cpp
@@ -55,13 +55,13 @@     }
     return SimpleWeatherService::Forecast {timestamp, nbDays, days};
   }
 
-    MessageType GetMessageType(const uint8_t* data) {
-      auto messageType = static_cast<MessageType>(*data);
-      if(messageType > MessageType::Unknown) {
-        return MessageType::Unknown;
-      }
-      return messageType;
+  MessageType GetMessageType(const uint8_t* data) {
+    auto messageType = static_cast<MessageType>(*data);
+    if (messageType > MessageType::Unknown) {
+      return MessageType::Unknown;
     }
+    return messageType;
+  }
 
   uint8_t GetVersion(const uint8_t* dataBuffer) {
     return dataBuffer[1];




diff --git a/src/displayapp/screens/Weather.cpp b/src/displayapp/screens/Weather.cpp
deleted file mode 100644
index dfeb1d413ff9b02fdc663a6afaad057ac81298d0..0000000000000000000000000000000000000000
--- a/src/displayapp/screens/Weather.cpp
+++ /dev/null
@@ -1,221 +0,0 @@
-/*  Copyright (C) 2021 Avamander
-
-    This file is part of InfiniTime.
-
-    InfiniTime is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published
-    by the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    InfiniTime is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <https://www.gnu.org/licenses/>.
-*/
-#include "Weather.h"
-#include <lvgl/lvgl.h>
-#include <components/ble/weather/SimpleWeatherService.h>
-#include "Label.h"
-#include "components/battery/BatteryController.h"
-#include "components/ble/BleController.h"
-#include "components/ble/weather/WeatherData.h"
-
-using namespace Pinetime::Applications::Screens;
-
-Weather::Weather(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::WeatherService& weather)
-  : app {app},
-    weatherService(weather),
-    screens {app,
-             0,
-             {[this]() -> std::unique_ptr<Screen> {
-                return CreateScreenTemperature();
-              },
-              [this]() -> std::unique_ptr<Screen> {
-                return CreateScreenAir();
-              },
-              [this]() -> std::unique_ptr<Screen> {
-                return CreateScreenClouds();
-              },
-              [this]() -> std::unique_ptr<Screen> {
-                return CreateScreenPrecipitation();
-              },
-              [this]() -> std::unique_ptr<Screen> {
-                return CreateScreenHumidity();
-              }},
-             Screens::ScreenListModes::UpDown} {
-}
-
-Weather::~Weather() {
-  lv_obj_clean(lv_scr_act());
-}
-
-void Weather::Refresh() {
-  if (running) {
-    // screens.Refresh();
-  }
-}
-
-bool Weather::OnButtonPushed() {
-  running = false;
-  return true;
-}
-
-bool Weather::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
-  return screens.OnTouchEvent(event);
-}
-
-std::unique_ptr<Screen> Weather::CreateScreenTemperature() {
-  lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
-  lv_label_set_recolor(label, true);
-  std::unique_ptr<Controllers::WeatherData::Temperature>& current = weatherService.GetCurrentTemperature();
-  if (current->timestamp == 0) {
-    // Do not use the data, it's invalid
-    lv_label_set_text_fmt(label,
-                          "#FFFF00 Temperature#\n\n"
-                          "#444444 %d#°C \n\n"
-                          "#444444 %d#\n\n"
-                          "%d\n"
-                          "%d\n",
-                          0,
-                          0,
-                          0,
-                          0);
-  } else {
-    lv_label_set_text_fmt(label,
-                          "#FFFF00 Temperature#\n\n"
-                          "#444444 %d#°C \n\n"
-                          "#444444 %hd#\n\n"
-                          "%llu\n"
-                          "%lu\n",
-                          current->temperature / 100,
-                          current->dewPoint,
-                          current->timestamp,
-                          current->expires);
-  }
-  lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
-  lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
-  return std::unique_ptr<Screen>(new Screens::Label(0, 5, label));
-}
-
-std::unique_ptr<Screen> Weather::CreateScreenAir() {
-  lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
-  lv_label_set_recolor(label, true);
-  std::unique_ptr<Controllers::WeatherData::AirQuality>& current = weatherService.GetCurrentQuality();
-  if (current->timestamp == 0) {
-    // Do not use the data, it's invalid
-    lv_label_set_text_fmt(label,
-                          "#FFFF00 Air quality#\n\n"
-                          "#444444 %s#\n"
-                          "#444444 %d#\n\n"
-                          "%d\n"
-                          "%d\n",
-                          "",
-                          0,
-                          0,
-                          0);
-  } else {
-    lv_label_set_text_fmt(label,
-                          "#FFFF00 Air quality#\n\n"
-                          "#444444 %s#\n"
-                          "#444444 %lu#\n\n"
-                          "%llu\n"
-                          "%lu\n",
-                          current->polluter.c_str(),
-                          (current->amount / 100),
-                          current->timestamp,
-                          current->expires);
-  }
-  lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
-  lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
-  return std::unique_ptr<Screen>(new Screens::Label(0, 5, label));
-}
-
-std::unique_ptr<Screen> Weather::CreateScreenClouds() {
-  lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
-  lv_label_set_recolor(label, true);
-  std::unique_ptr<Controllers::WeatherData::Clouds>& current = weatherService.GetCurrentClouds();
-  if (current->timestamp == 0) {
-    // Do not use the data, it's invalid
-    lv_label_set_text_fmt(label,
-                          "#FFFF00 Clouds#\n\n"
-                          "#444444 %d%%#\n\n"
-                          "%d\n"
-                          "%d\n",
-                          0,
-                          0,
-                          0);
-  } else {
-    lv_label_set_text_fmt(label,
-                          "#FFFF00 Clouds#\n\n"
-                          "#444444 %hhu%%#\n\n"
-                          "%llu\n"
-                          "%lu\n",
-                          current->amount,
-                          current->timestamp,
-                          current->expires);
-  }
-  lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
-  lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
-  return std::unique_ptr<Screen>(new Screens::Label(0, 5, label));
-}
-
-std::unique_ptr<Screen> Weather::CreateScreenPrecipitation() {
-  lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
-  lv_label_set_recolor(label, true);
-  std::unique_ptr<Controllers::WeatherData::Precipitation>& current = weatherService.GetCurrentPrecipitation();
-  if (current->timestamp == 0) {
-    // Do not use the data, it's invalid
-    lv_label_set_text_fmt(label,
-                          "#FFFF00 Precipitation#\n\n"
-                          "#444444 %d%%#\n\n"
-                          "%d\n"
-                          "%d\n",
-                          0,
-                          0,
-                          0);
-  } else {
-    lv_label_set_text_fmt(label,
-                          "#FFFF00 Precipitation#\n\n"
-                          "#444444 %hhu%%#\n\n"
-                          "%llu\n"
-                          "%lu\n",
-                          current->amount,
-                          current->timestamp,
-                          current->expires);
-  }
-  lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
-  lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
-  return std::unique_ptr<Screen>(new Screens::Label(0, 5, label));
-}
-
-std::unique_ptr<Screen> Weather::CreateScreenHumidity() {
-  lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
-  lv_label_set_recolor(label, true);
-  std::unique_ptr<Controllers::WeatherData::Humidity>& current = weatherService.GetCurrentHumidity();
-  if (current->timestamp == 0) {
-    // Do not use the data, it's invalid
-    lv_label_set_text_fmt(label,
-                          "#FFFF00 Humidity#\n\n"
-                          "#444444 %d%%#\n\n"
-                          "%d\n"
-                          "%d\n",
-                          0,
-                          0,
-                          0);
-  } else {
-    lv_label_set_text_fmt(label,
-                          "#FFFF00 Humidity#\n\n"
-                          "#444444 %hhu%%#\n\n"
-                          "%llu\n"
-                          "%lu\n",
-                          current->humidity,
-                          current->timestamp,
-                          current->expires);
-  }
-  lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
-  lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
-  return std::unique_ptr<Screen>(new Screens::Label(0, 5, label));
-}




diff --git a/src/displayapp/screens/Weather.h b/src/displayapp/screens/Weather.h
deleted file mode 100644
index 6b2599c816ce574a557006f643a86e7da5a533fb..0000000000000000000000000000000000000000
--- a/src/displayapp/screens/Weather.h
+++ /dev/null
@@ -1,58 +0,0 @@
-#pragma once
-
-#include <memory>
-#include "components/ble/weather/SimpleWeatherService.h"
-#include "Screen.h"
-#include "ScreenList.h"
-#include "displayapp/Apps.h"
-#include "displayapp/Controllers.h"
-#include "Symbols.h"
-
-namespace Pinetime {
-  namespace Applications {
-    class DisplayApp;
-
-    namespace Screens {
-      class Weather : public Screen {
-      public:
-        explicit Weather(DisplayApp* app, Pinetime::Controllers::WeatherService& weather);
-
-        ~Weather() override;
-
-        void Refresh() override;
-
-        bool OnButtonPushed() override;
-
-        bool OnTouchEvent(TouchEvents event) override;
-
-      private:
-        DisplayApp* app;
-        bool running = true;
-
-        Controllers::WeatherService& weatherService;
-
-        ScreenList<5> screens;
-
-        std::unique_ptr<Screen> CreateScreenTemperature();
-
-        std::unique_ptr<Screen> CreateScreenAir();
-
-        std::unique_ptr<Screen> CreateScreenClouds();
-
-        std::unique_ptr<Screen> CreateScreenPrecipitation();
-
-        std::unique_ptr<Screen> CreateScreenHumidity();
-      };
-    }
-
-    template <>
-    struct AppTraits<Apps::Weather> {
-      static constexpr Apps app = Apps::Weather;
-      static constexpr const char* icon = Screens::Symbols::sun;
-
-      static Screens::Screen* Create(AppControllers& controllers) {
-        return new Screens::Weather(controllers.displayApp, *controllers.weatherController);
-      };
-    };
-  }
-}