Simple Weather Service

Fix code formatting.
This commit is contained in:
Jean-François Milants 2023-12-23 17:22:32 +01:00 committed by JF
parent e5b73212f6
commit 6f83a3bade
3 changed files with 15 additions and 22 deletions

View File

@ -29,31 +29,24 @@ namespace {
enum class MessageType : uint8_t { CurrentWeather, Forecast, Unknown };
uint64_t ToUInt64(const uint8_t* data) {
return data[0] +
(data[1] << 8) +
(data[2] << 16) +
(data[3] << 24) +
(static_cast<uint64_t>(data[4]) << 32) +
(static_cast<uint64_t>(data[5]) << 48) +
(static_cast<uint64_t>(data[6]) << 48) +
(static_cast<uint64_t>(data[7]) << 56);
return data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24) + (static_cast<uint64_t>(data[4]) << 32) +
(static_cast<uint64_t>(data[5]) << 48) + (static_cast<uint64_t>(data[6]) << 48) + (static_cast<uint64_t>(data[7]) << 56);
}
int16_t ToInt16(const uint8_t* data) {
return data[0] +
(data[1] << 8);
return data[0] + (data[1] << 8);
}
SimpleWeatherService::CurrentWeather CreateCurrentWeather(const uint8_t* dataBuffer) {
SimpleWeatherService::Location cityName;
std::memcpy(cityName.data(), &dataBuffer[16], 32);
cityName[32] = '\0';
return SimpleWeatherService::CurrentWeather (ToUInt64(&dataBuffer[2]),
return SimpleWeatherService::CurrentWeather(ToUInt64(&dataBuffer[2]),
ToInt16(&dataBuffer[10]),
ToInt16(&dataBuffer[12]),
ToInt16(&dataBuffer[14]),
SimpleWeatherService::Icons{dataBuffer[16 + 32]},
std::move(cityName));
ToInt16(&dataBuffer[12]),
ToInt16(&dataBuffer[14]),
SimpleWeatherService::Icons {dataBuffer[16 + 32]},
std::move(cityName));
}
SimpleWeatherService::Forecast CreateForecast(const uint8_t* dataBuffer) {
@ -63,10 +56,9 @@ namespace {
const uint8_t nbDaysInBuffer = dataBuffer[10];
const uint8_t nbDays = std::min(SimpleWeatherService::MaxNbForecastDays, nbDaysInBuffer);
for (int i = 0; i < nbDays; i++) {
days[i] = SimpleWeatherService::Forecast::Day {
ToInt16(&dataBuffer[11 + (i * 5)]),
ToInt16(&dataBuffer[13 + (i * 5)]),
SimpleWeatherService::Icons{dataBuffer[15 + (i * 5)]}};
days[i] = SimpleWeatherService::Forecast::Day {ToInt16(&dataBuffer[11 + (i * 5)]),
ToInt16(&dataBuffer[13 + (i * 5)]),
SimpleWeatherService::Icons {dataBuffer[15 + (i * 5)]}};
}
return SimpleWeatherService::Forecast {timestamp, nbDays, days};
}

View File

@ -61,7 +61,8 @@ namespace Pinetime {
Unknown = 255
};
using Location = std::array<char, 33>; // 32 char + \0 (end of string)
using Location = std::array<char, 33>; // 32 char + \0 (end of string)
struct CurrentWeather {
CurrentWeather(uint64_t timestamp,
int16_t temperature,
@ -74,7 +75,7 @@ namespace Pinetime {
minTemperature {minTemperature},
maxTemperature {maxTemperature},
iconId {iconId},
location{std::move(location)} {
location {std::move(location)} {
}
uint64_t timestamp;

View File

@ -543,7 +543,7 @@ void WatchFacePineTimeStyle::Refresh() {
if (currentWeather.IsUpdated()) {
auto optCurrentWeather = currentWeather.Get();
if (optCurrentWeather) {
lv_label_set_text_fmt(temperature, "%d°", (optCurrentWeather->temperature)/100);
lv_label_set_text_fmt(temperature, "%d°", (optCurrentWeather->temperature) / 100);
lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId));
lv_obj_realign(temperature);
lv_obj_realign(weatherIcon);