Simple Weather Service
Fix code formatting.
This commit is contained in:
parent
e5b73212f6
commit
6f83a3bade
|
@ -29,31 +29,24 @@ namespace {
|
||||||
enum class MessageType : uint8_t { CurrentWeather, Forecast, Unknown };
|
enum class MessageType : uint8_t { CurrentWeather, Forecast, Unknown };
|
||||||
|
|
||||||
uint64_t ToUInt64(const uint8_t* data) {
|
uint64_t ToUInt64(const uint8_t* data) {
|
||||||
return data[0] +
|
return data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24) + (static_cast<uint64_t>(data[4]) << 32) +
|
||||||
(data[1] << 8) +
|
(static_cast<uint64_t>(data[5]) << 48) + (static_cast<uint64_t>(data[6]) << 48) + (static_cast<uint64_t>(data[7]) << 56);
|
||||||
(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) {
|
int16_t ToInt16(const uint8_t* data) {
|
||||||
return data[0] +
|
return data[0] + (data[1] << 8);
|
||||||
(data[1] << 8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleWeatherService::CurrentWeather CreateCurrentWeather(const uint8_t* dataBuffer) {
|
SimpleWeatherService::CurrentWeather CreateCurrentWeather(const uint8_t* dataBuffer) {
|
||||||
SimpleWeatherService::Location cityName;
|
SimpleWeatherService::Location cityName;
|
||||||
std::memcpy(cityName.data(), &dataBuffer[16], 32);
|
std::memcpy(cityName.data(), &dataBuffer[16], 32);
|
||||||
cityName[32] = '\0';
|
cityName[32] = '\0';
|
||||||
return SimpleWeatherService::CurrentWeather (ToUInt64(&dataBuffer[2]),
|
return SimpleWeatherService::CurrentWeather(ToUInt64(&dataBuffer[2]),
|
||||||
ToInt16(&dataBuffer[10]),
|
ToInt16(&dataBuffer[10]),
|
||||||
ToInt16(&dataBuffer[12]),
|
ToInt16(&dataBuffer[12]),
|
||||||
ToInt16(&dataBuffer[14]),
|
ToInt16(&dataBuffer[14]),
|
||||||
SimpleWeatherService::Icons{dataBuffer[16 + 32]},
|
SimpleWeatherService::Icons {dataBuffer[16 + 32]},
|
||||||
std::move(cityName));
|
std::move(cityName));
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleWeatherService::Forecast CreateForecast(const uint8_t* dataBuffer) {
|
SimpleWeatherService::Forecast CreateForecast(const uint8_t* dataBuffer) {
|
||||||
|
@ -63,10 +56,9 @@ namespace {
|
||||||
const uint8_t nbDaysInBuffer = dataBuffer[10];
|
const uint8_t nbDaysInBuffer = dataBuffer[10];
|
||||||
const uint8_t nbDays = std::min(SimpleWeatherService::MaxNbForecastDays, nbDaysInBuffer);
|
const uint8_t nbDays = std::min(SimpleWeatherService::MaxNbForecastDays, nbDaysInBuffer);
|
||||||
for (int i = 0; i < nbDays; i++) {
|
for (int i = 0; i < nbDays; i++) {
|
||||||
days[i] = SimpleWeatherService::Forecast::Day {
|
days[i] = SimpleWeatherService::Forecast::Day {ToInt16(&dataBuffer[11 + (i * 5)]),
|
||||||
ToInt16(&dataBuffer[11 + (i * 5)]),
|
ToInt16(&dataBuffer[13 + (i * 5)]),
|
||||||
ToInt16(&dataBuffer[13 + (i * 5)]),
|
SimpleWeatherService::Icons {dataBuffer[15 + (i * 5)]}};
|
||||||
SimpleWeatherService::Icons{dataBuffer[15 + (i * 5)]}};
|
|
||||||
}
|
}
|
||||||
return SimpleWeatherService::Forecast {timestamp, nbDays, days};
|
return SimpleWeatherService::Forecast {timestamp, nbDays, days};
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,8 @@ namespace Pinetime {
|
||||||
Unknown = 255
|
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 {
|
struct CurrentWeather {
|
||||||
CurrentWeather(uint64_t timestamp,
|
CurrentWeather(uint64_t timestamp,
|
||||||
int16_t temperature,
|
int16_t temperature,
|
||||||
|
@ -74,7 +75,7 @@ namespace Pinetime {
|
||||||
minTemperature {minTemperature},
|
minTemperature {minTemperature},
|
||||||
maxTemperature {maxTemperature},
|
maxTemperature {maxTemperature},
|
||||||
iconId {iconId},
|
iconId {iconId},
|
||||||
location{std::move(location)} {
|
location {std::move(location)} {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t timestamp;
|
uint64_t timestamp;
|
||||||
|
|
|
@ -543,7 +543,7 @@ void WatchFacePineTimeStyle::Refresh() {
|
||||||
if (currentWeather.IsUpdated()) {
|
if (currentWeather.IsUpdated()) {
|
||||||
auto optCurrentWeather = currentWeather.Get();
|
auto optCurrentWeather = currentWeather.Get();
|
||||||
if (optCurrentWeather) {
|
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_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId));
|
||||||
lv_obj_realign(temperature);
|
lv_obj_realign(temperature);
|
||||||
lv_obj_realign(weatherIcon);
|
lv_obj_realign(weatherIcon);
|
||||||
|
|
Loading…
Reference in a new issue