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.
This commit is contained in:
parent
fe4b07c610
commit
3a8c7dc038
|
@ -40,8 +40,8 @@ The byte array must contain the following data:
|
||||||
- 4 = Clouds & rain
|
- 4 = Clouds & rain
|
||||||
- 5 = Rain
|
- 5 = Rain
|
||||||
- 6 = Thunderstorm
|
- 6 = Thunderstorm
|
||||||
- 7 = snow
|
- 7 = Snow
|
||||||
- 8 = mist, smog
|
- 8 = Mist, smog
|
||||||
|
|
||||||
### Forecast
|
### Forecast
|
||||||
|
|
||||||
|
@ -65,4 +65,4 @@ The byte array must contain the following data:
|
||||||
- [22] Day 3 Icon ID
|
- [22] Day 3 Icon ID
|
||||||
- [23] Day 4 Minimum temperature
|
- [23] Day 4 Minimum temperature
|
||||||
- [24] Day 4 Maximum temperature
|
- [24] Day 4 Maximum temperature
|
||||||
- [25] Day 4 Incon ID
|
- [25] Day 4 Icon ID
|
|
@ -15,24 +15,27 @@
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "components/ble/SimpleWeatherService.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "SimpleWeatherService.h"
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <nrf_log.h>
|
#include <nrf_log.h>
|
||||||
#include <array>
|
|
||||||
|
|
||||||
using namespace Pinetime::Controllers;
|
using namespace Pinetime::Controllers;
|
||||||
|
|
||||||
namespace {
|
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) {
|
SimpleWeatherService::CurrentWeather CreateCurrentWeather(const uint8_t* dataBuffer) {
|
||||||
char cityName[33];
|
char cityName[33];
|
||||||
std::memcpy(&cityName[0], &dataBuffer[13], 32);
|
std::memcpy(&cityName[0], &dataBuffer[13], 32);
|
||||||
cityName[32] = '\0';
|
cityName[32] = '\0';
|
||||||
return SimpleWeatherService::CurrentWeather {dataBuffer[2] + (dataBuffer[3] << 8) + (dataBuffer[4] << 16) + (dataBuffer[5] << 24) +
|
return SimpleWeatherService::CurrentWeather {ToUInt64(&dataBuffer[2]),
|
||||||
((uint64_t) dataBuffer[6] << 32) + ((uint64_t) dataBuffer[7] << 40) +
|
|
||||||
((uint64_t) dataBuffer[8] << 48) + ((uint64_t) dataBuffer[9] << 54),
|
|
||||||
dataBuffer[10],
|
dataBuffer[10],
|
||||||
dataBuffer[11],
|
dataBuffer[11],
|
||||||
dataBuffer[12],
|
dataBuffer[12],
|
||||||
|
@ -41,9 +44,7 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleWeatherService::Forecast CreateForecast(const uint8_t* dataBuffer) {
|
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) +
|
auto timestamp = static_cast<uint64_t>(ToUInt64(&dataBuffer[2]));
|
||||||
((uint64_t) dataBuffer[6] << 32) + ((uint64_t) dataBuffer[7] << 40) +
|
|
||||||
((uint64_t) dataBuffer[8] << 48) + ((uint64_t) dataBuffer[9] << 54));
|
|
||||||
|
|
||||||
std::array<SimpleWeatherService::Forecast::Day, SimpleWeatherService::MaxNbForecastDays> days;
|
std::array<SimpleWeatherService::Forecast::Day, SimpleWeatherService::MaxNbForecastDays> days;
|
||||||
const uint8_t nbDaysInBuffer = dataBuffer[10];
|
const uint8_t nbDaysInBuffer = dataBuffer[10];
|
||||||
|
@ -54,19 +55,13 @@ namespace {
|
||||||
return SimpleWeatherService::Forecast {timestamp, nbDays, days};
|
return SimpleWeatherService::Forecast {timestamp, nbDays, days};
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageType GetMessageType(const uint8_t* dataBuffer) {
|
MessageType GetMessageType(const uint8_t* data) {
|
||||||
switch (dataBuffer[0]) {
|
auto messageType = static_cast<MessageType>(*data);
|
||||||
case 0:
|
if(messageType > MessageType::Unknown) {
|
||||||
return MessageType::CurrentWeather;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
return MessageType::Forecast;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return MessageType::Unknown;
|
return MessageType::Unknown;
|
||||||
break;
|
}
|
||||||
|
return messageType;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t GetVersion(const uint8_t* dataBuffer) {
|
uint8_t GetVersion(const uint8_t* dataBuffer) {
|
||||||
return dataBuffer[1];
|
return dataBuffer[1];
|
||||||
|
@ -154,7 +149,3 @@ bool SimpleWeatherService::CurrentWeather::operator==(const SimpleWeatherService
|
||||||
return this->iconId == other.iconId && this->temperature == other.temperature && this->timestamp == other.timestamp &&
|
return this->iconId == other.iconId && this->temperature == other.temperature && this->timestamp == other.timestamp &&
|
||||||
this->maxTemperature == other.maxTemperature && this->minTemperature == other.maxTemperature;
|
this->maxTemperature == other.maxTemperature && this->minTemperature == other.maxTemperature;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SimpleWeatherService::CurrentWeather::operator!=(const SimpleWeatherService::CurrentWeather& other) const {
|
|
||||||
return !operator==(other);
|
|
||||||
}
|
|
||||||
|
|
|
@ -85,7 +85,6 @@ namespace Pinetime {
|
||||||
char location[33]; // 32 char + \0 (end of string)
|
char location[33]; // 32 char + \0 (end of string)
|
||||||
|
|
||||||
bool operator==(const CurrentWeather& other) const;
|
bool operator==(const CurrentWeather& other) const;
|
||||||
bool operator!=(const CurrentWeather& other) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Forecast {
|
struct Forecast {
|
||||||
|
|
|
@ -68,7 +68,7 @@
|
||||||
"sources": [
|
"sources": [
|
||||||
{
|
{
|
||||||
"file": "FontAwesome5-Solid+Brands+Regular.woff",
|
"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,
|
"bpp": 1,
|
||||||
|
|
|
@ -5,8 +5,6 @@
|
||||||
|
|
||||||
using namespace Pinetime::Applications::Screens;
|
using namespace Pinetime::Applications::Screens;
|
||||||
|
|
||||||
constexpr int Pinetime::Applications::Screens::StopWatch::maxLapCount;
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
TimeSeparated_t convertTicksToTimeSegments(const TickType_t timeElapsed) {
|
TimeSeparated_t convertTicksToTimeSegments(const TickType_t timeElapsed) {
|
||||||
// Centiseconds
|
// Centiseconds
|
||||||
|
|
|
@ -45,6 +45,9 @@ namespace Pinetime {
|
||||||
static constexpr const char* cloudShowersHeavy = "\xEF\x9D\x80";
|
static constexpr const char* cloudShowersHeavy = "\xEF\x9D\x80";
|
||||||
static constexpr const char* smog = "\xEF\x9D\x9F";
|
static constexpr const char* smog = "\xEF\x9D\x9F";
|
||||||
static constexpr const char* cloud = "\xEF\x83\x82";
|
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";
|
static constexpr const char* ban = "\xEF\x81\x9E";
|
||||||
|
|
||||||
// lv_font_sys_48.c
|
// lv_font_sys_48.c
|
||||||
|
|
|
@ -55,14 +55,14 @@ namespace {
|
||||||
return Symbols::cloud;
|
return Symbols::cloud;
|
||||||
break;
|
break;
|
||||||
case Pinetime::Controllers::SimpleWeatherService::Icons::BrokenClouds:
|
case Pinetime::Controllers::SimpleWeatherService::Icons::BrokenClouds:
|
||||||
return Symbols::cloud;
|
return Symbols::cloud_meatball;
|
||||||
break; // TODO missing symbol
|
break;
|
||||||
case Pinetime::Controllers::SimpleWeatherService::Icons::Thunderstorm:
|
case Pinetime::Controllers::SimpleWeatherService::Icons::Thunderstorm:
|
||||||
return Symbols::cloud;
|
return Symbols::bolt;
|
||||||
break; // TODO missing symbol
|
break;
|
||||||
case Pinetime::Controllers::SimpleWeatherService::Icons::Snow:
|
case Pinetime::Controllers::SimpleWeatherService::Icons::Snow:
|
||||||
return Symbols::cloud;
|
return Symbols::snowflake;
|
||||||
break; // TODO missing symbol
|
break;
|
||||||
case Pinetime::Controllers::SimpleWeatherService::Icons::CloudShowerHeavy:
|
case Pinetime::Controllers::SimpleWeatherService::Icons::CloudShowerHeavy:
|
||||||
return Symbols::cloudShowersHeavy;
|
return Symbols::cloudShowersHeavy;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue