InfiniTime.git

commit 3a8c7dc038605f7a0ebefa479b204d6d019743cd

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

Simple Weather Service - code cleaning and improvements

Add missing icons (heavy clouds, thunderstorm, snow).
Remove unneeded comparison operator (!=), improve conversion of Timestamp and MessageType, order includes.
Fix typo in documentation.
Remove not related change in StopWatch.

 doc/SimpleWeatherService.md | 6 +-
 src/components/ble/SimpleWeatherService.cpp | 39 ++++++----------
 src/components/ble/SimpleWeatherService.h | 1 
 src/displayapp/fonts/fonts.json | 2 
 src/displayapp/screens/StopWatch.cpp | 2 
 src/displayapp/screens/Symbols.h | 3 +
 src/displayapp/screens/WatchFacePineTimeStyle.cpp | 12 ++--


diff --git a/doc/SimpleWeatherService.md b/doc/SimpleWeatherService.md
index c510e4288c25ded058bba38edc2f8ed8b4320be4..369939000ce8cb2c8a4c48ba43d5e7f45c94f7fe 100644
--- a/doc/SimpleWeatherService.md
+++ b/doc/SimpleWeatherService.md
@@ -40,8 +40,8 @@    - 3 = Heavy clouds
    - 4 = Clouds & rain
    - 5 = Rain
    - 6 = Thunderstorm
-   - 7 = snow
-   - 8 = mist, smog
+   - 7 = Snow
+   - 8 = Mist, smog
 
 ### Forecast
 
@@ -65,4 +65,4 @@   - [21] Day 3 Maximum temperature
   - [22] Day 3 Icon ID
   - [23] Day 4 Minimum temperature
   - [24] Day 4 Maximum temperature
-  - [25] Day 4 Incon ID
\ No newline at end of file
+  - [25] Day 4 Icon ID
\ No newline at end of file




diff --git a/src/components/ble/SimpleWeatherService.cpp b/src/components/ble/SimpleWeatherService.cpp
index 9735f2d1e688c604af899f7442775c65cc2c8560..3635fdfdd092c46719bb7ec46070004c221b2ae5 100644
--- a/src/components/ble/SimpleWeatherService.cpp
+++ b/src/components/ble/SimpleWeatherService.cpp
@@ -15,24 +15,27 @@
     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 "components/ble/SimpleWeatherService.h"
+
 #include <algorithm>
-#include "SimpleWeatherService.h"
 #include <cstring>
 #include <nrf_log.h>
-#include <array>
 
 using namespace Pinetime::Controllers;
 
 namespace {
-  enum class MessageType { CurrentWeather, Forecast, Unknown };
+  enum class MessageType : uint8_t { CurrentWeather, Forecast, Unknown };
+
+  uint64_t ToUInt64(const uint8_t* data) {
+    return *(reinterpret_cast<const uint64_t*>(data));
+  }
 
   SimpleWeatherService::CurrentWeather CreateCurrentWeather(const uint8_t* dataBuffer) {
     char cityName[33];
     std::memcpy(&cityName[0], &dataBuffer[13], 32);
     cityName[32] = '\0';
-    return SimpleWeatherService::CurrentWeather {dataBuffer[2] + (dataBuffer[3] << 8) + (dataBuffer[4] << 16) + (dataBuffer[5] << 24) +
-                                                   ((uint64_t) dataBuffer[6] << 32) + ((uint64_t) dataBuffer[7] << 40) +
-                                                   ((uint64_t) dataBuffer[8] << 48) + ((uint64_t) dataBuffer[9] << 54),
+    return SimpleWeatherService::CurrentWeather {ToUInt64(&dataBuffer[2]),
                                                  dataBuffer[10],
                                                  dataBuffer[11],
                                                  dataBuffer[12],
@@ -41,9 +44,7 @@                                                  cityName};
   }
 
   SimpleWeatherService::Forecast CreateForecast(const uint8_t* dataBuffer) {
-    uint64_t timestamp = static_cast<uint64_t>(dataBuffer[2] + (dataBuffer[3] << 8) + (dataBuffer[4] << 16) + (dataBuffer[5] << 24) +
-                                               ((uint64_t) dataBuffer[6] << 32) + ((uint64_t) dataBuffer[7] << 40) +
-                                               ((uint64_t) dataBuffer[8] << 48) + ((uint64_t) dataBuffer[9] << 54));
+    auto timestamp = static_cast<uint64_t>(ToUInt64(&dataBuffer[2]));
 
     std::array<SimpleWeatherService::Forecast::Day, SimpleWeatherService::MaxNbForecastDays> days;
     const uint8_t nbDaysInBuffer = dataBuffer[10];
@@ -54,19 +55,13 @@     }
     return SimpleWeatherService::Forecast {timestamp, nbDays, days};
   }
 
-  MessageType GetMessageType(const uint8_t* dataBuffer) {
-    switch (dataBuffer[0]) {
-      case 0:
-        return MessageType::CurrentWeather;
-        break;
-      case 1:
-        return MessageType::Forecast;
-        break;
-      default:
+    MessageType GetMessageType(const uint8_t* data) {
+      auto messageType = static_cast<MessageType>(*data);
+      if(messageType > MessageType::Unknown) {
         return MessageType::Unknown;
-        break;
+      }
+      return messageType;
     }
-  }
 
   uint8_t GetVersion(const uint8_t* dataBuffer) {
     return dataBuffer[1];
@@ -154,7 +149,3 @@ bool SimpleWeatherService::CurrentWeather::operator==(const SimpleWeatherService::CurrentWeather& other) const {
   return this->iconId == other.iconId && this->temperature == other.temperature && this->timestamp == other.timestamp &&
          this->maxTemperature == other.maxTemperature && this->minTemperature == other.maxTemperature;
 }
-
-bool SimpleWeatherService::CurrentWeather::operator!=(const SimpleWeatherService::CurrentWeather& other) const {
-  return !operator==(other);
-}




diff --git a/src/components/ble/SimpleWeatherService.h b/src/components/ble/SimpleWeatherService.h
index a16254646c195cdb05e2f08b3b1d3abb32a7680f..890497d7f2ee4173dc1303a2e54e926df889015a 100644
--- a/src/components/ble/SimpleWeatherService.h
+++ b/src/components/ble/SimpleWeatherService.h
@@ -85,7 +85,6 @@         Icons iconId;
         char location[33]; // 32 char + \0 (end of string)
 
         bool operator==(const CurrentWeather& other) const;
-        bool operator!=(const CurrentWeather& other) const;
       };
 
       struct Forecast {




diff --git a/src/displayapp/fonts/fonts.json b/src/displayapp/fonts/fonts.json
index 8416fc5ef3fabc5ea3f1a2ee1d1043848f4c82a3..48d382d006ec593b32ae11e04edafe79533e8507 100644
--- a/src/displayapp/fonts/fonts.json
+++ b/src/displayapp/fonts/fonts.json
@@ -68,7 +68,7 @@    "fontawesome_weathericons": {
       "sources": [
          {
             "file": "FontAwesome5-Solid+Brands+Regular.woff",
-            "range": "0xf185, 0xf6c4, 0xf743, 0xf740, 0xf75f, 0xf0c2, 0xf05e"
+            "range": "0xf185, 0xf6c4, 0xf743, 0xf740, 0xf75f, 0xf0c2, 0xf05e, 0xf73b, 0xf0e7, 0xf2dc"
          }
       ],
       "bpp": 1,




diff --git a/src/displayapp/screens/StopWatch.cpp b/src/displayapp/screens/StopWatch.cpp
index bdb3fde697da3bc18e04e6469569b79a7dd2f407..f0359da4d468003dc4b072268c7674aeed7c06a6 100644
--- a/src/displayapp/screens/StopWatch.cpp
+++ b/src/displayapp/screens/StopWatch.cpp
@@ -5,8 +5,6 @@ #include "displayapp/InfiniTimeTheme.h"
 
 using namespace Pinetime::Applications::Screens;
 
-constexpr int Pinetime::Applications::Screens::StopWatch::maxLapCount;
-
 namespace {
   TimeSeparated_t convertTicksToTimeSegments(const TickType_t timeElapsed) {
     // Centiseconds




diff --git a/src/displayapp/screens/Symbols.h b/src/displayapp/screens/Symbols.h
index 7154ff44c1c86ab06e905e85b1c1bd866b866b60..a6f1494a2e4cfa1c1a7f782e3fbca6a9f5d5cace 100644
--- a/src/displayapp/screens/Symbols.h
+++ b/src/displayapp/screens/Symbols.h
@@ -45,6 +45,9 @@         static constexpr const char* cloudSunRain = "\xEF\x9D\x83";
         static constexpr const char* cloudShowersHeavy = "\xEF\x9D\x80";
         static constexpr const char* smog = "\xEF\x9D\x9F";
         static constexpr const char* cloud = "\xEF\x83\x82";
+        static constexpr const char* cloud_meatball = "\xEF\x9C\xBB";
+        static constexpr const char* bolt = "\xEF\x83\xA7";
+        static constexpr const char* snowflake = "\xEF\x8B\x9C";
         static constexpr const char* ban = "\xEF\x81\x9E";
 
         // lv_font_sys_48.c




diff --git a/src/displayapp/screens/WatchFacePineTimeStyle.cpp b/src/displayapp/screens/WatchFacePineTimeStyle.cpp
index baa2e1845bf664fcf12b91b6d90da93bd490ba6d..d11114d6bd6a12fcb641d73728257d1381020e34 100644
--- a/src/displayapp/screens/WatchFacePineTimeStyle.cpp
+++ b/src/displayapp/screens/WatchFacePineTimeStyle.cpp
@@ -55,14 +55,14 @@       case Pinetime::Controllers::SimpleWeatherService::Icons::Clouds:
         return Symbols::cloud;
         break;
       case Pinetime::Controllers::SimpleWeatherService::Icons::BrokenClouds:
-        return Symbols::cloud;
-        break; // TODO missing symbol
+        return Symbols::cloud_meatball;
+        break;
       case Pinetime::Controllers::SimpleWeatherService::Icons::Thunderstorm:
-        return Symbols::cloud;
-        break; // TODO missing symbol
+        return Symbols::bolt;
+        break;
       case Pinetime::Controllers::SimpleWeatherService::Icons::Snow:
-        return Symbols::cloud;
-        break; // TODO missing symbol
+        return Symbols::snowflake;
+        break;
       case Pinetime::Controllers::SimpleWeatherService::Icons::CloudShowerHeavy:
         return Symbols::cloudShowersHeavy;
         break;