Switch to simpler temperature interface
This commit is contained in:
@@ -42,9 +42,9 @@ namespace {
|
||||
std::memcpy(cityName.data(), &dataBuffer[16], 32);
|
||||
cityName[32] = '\0';
|
||||
return SimpleWeatherService::CurrentWeather(ToUInt64(&dataBuffer[2]),
|
||||
SimpleWeatherService::Temperature {ToInt16(&dataBuffer[10])},
|
||||
SimpleWeatherService::Temperature {ToInt16(&dataBuffer[12])},
|
||||
SimpleWeatherService::Temperature {ToInt16(&dataBuffer[14])},
|
||||
SimpleWeatherService::Temperature(ToInt16(&dataBuffer[10])),
|
||||
SimpleWeatherService::Temperature(ToInt16(&dataBuffer[12])),
|
||||
SimpleWeatherService::Temperature(ToInt16(&dataBuffer[14])),
|
||||
SimpleWeatherService::Icons {dataBuffer[16 + 32]},
|
||||
std::move(cityName));
|
||||
}
|
||||
@@ -56,8 +56,8 @@ 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 {SimpleWeatherService::Temperature {ToInt16(&dataBuffer[11 + (i * 5)])},
|
||||
SimpleWeatherService::Temperature {ToInt16(&dataBuffer[13 + (i * 5)])},
|
||||
days[i] = SimpleWeatherService::Forecast::Day {SimpleWeatherService::Temperature(ToInt16(&dataBuffer[11 + (i * 5)])),
|
||||
SimpleWeatherService::Temperature(ToInt16(&dataBuffer[13 + (i * 5)])),
|
||||
SimpleWeatherService::Icons {dataBuffer[15 + (i * 5)]}};
|
||||
}
|
||||
return SimpleWeatherService::Forecast {timestamp, nbDays, days};
|
||||
@@ -98,9 +98,9 @@ int SimpleWeatherService::OnCommand(struct ble_gatt_access_ctxt* ctxt) {
|
||||
currentWeather = CreateCurrentWeather(dataBuffer);
|
||||
NRF_LOG_INFO("Current weather :\n\tTimestamp : %d\n\tTemperature:%d\n\tMin:%d\n\tMax:%d\n\tIcon:%d\n\tLocation:%s",
|
||||
currentWeather->timestamp,
|
||||
currentWeather->temperature,
|
||||
currentWeather->minTemperature,
|
||||
currentWeather->maxTemperature,
|
||||
currentWeather->temperature.PreciseCelsius(),
|
||||
currentWeather->minTemperature.PreciseCelsius(),
|
||||
currentWeather->maxTemperature.PreciseCelsius(),
|
||||
currentWeather->iconId,
|
||||
currentWeather->location.data());
|
||||
}
|
||||
@@ -112,8 +112,8 @@ int SimpleWeatherService::OnCommand(struct ble_gatt_access_ctxt* ctxt) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
NRF_LOG_INFO("\t[%d] Min: %d - Max : %d - Icon : %d",
|
||||
i,
|
||||
forecast->days[i].minTemperature,
|
||||
forecast->days[i].maxTemperature,
|
||||
forecast->days[i].minTemperature.PreciseCelsius(),
|
||||
forecast->days[i].maxTemperature.PreciseCelsius(),
|
||||
forecast->days[i].iconId);
|
||||
}
|
||||
}
|
||||
@@ -154,14 +154,13 @@ std::optional<SimpleWeatherService::Forecast> SimpleWeatherService::GetForecast(
|
||||
}
|
||||
|
||||
bool SimpleWeatherService::CurrentWeather::operator==(const SimpleWeatherService::CurrentWeather& other) const {
|
||||
return this->iconId == other.iconId && this->temperature.temp == other.temperature.temp && this->timestamp == other.timestamp &&
|
||||
this->maxTemperature.temp == other.maxTemperature.temp && this->minTemperature.temp == other.maxTemperature.temp &&
|
||||
return this->iconId == other.iconId && this->temperature == other.temperature && this->timestamp == other.timestamp &&
|
||||
this->maxTemperature == other.maxTemperature && this->minTemperature == other.maxTemperature &&
|
||||
std::strcmp(this->location.data(), other.location.data()) == 0;
|
||||
}
|
||||
|
||||
bool SimpleWeatherService::Forecast::Day::operator==(const SimpleWeatherService::Forecast::Day& other) const {
|
||||
return this->iconId == other.iconId && this->maxTemperature.temp == other.maxTemperature.temp &&
|
||||
this->minTemperature.temp == other.maxTemperature.temp;
|
||||
return this->iconId == other.iconId && this->maxTemperature == other.maxTemperature && this->minTemperature == other.maxTemperature;
|
||||
}
|
||||
|
||||
bool SimpleWeatherService::Forecast::operator==(const SimpleWeatherService::Forecast& other) const {
|
||||
|
||||
@@ -61,8 +61,33 @@ namespace Pinetime {
|
||||
Unknown = 255
|
||||
};
|
||||
|
||||
struct Temperature {
|
||||
int16_t temp;
|
||||
class Temperature {
|
||||
public:
|
||||
explicit Temperature(int16_t raw = 0) : raw {raw} {
|
||||
}
|
||||
|
||||
[[nodiscard]] int16_t PreciseCelsius() const {
|
||||
return raw;
|
||||
}
|
||||
|
||||
[[nodiscard]] int16_t PreciseFahrenheit() const {
|
||||
return raw * 9 / 5 + 3200;
|
||||
}
|
||||
|
||||
[[nodiscard]] int16_t Celsius() const {
|
||||
return (PreciseCelsius() + 50) / 100;
|
||||
}
|
||||
|
||||
[[nodiscard]] int16_t Fahrenheit() const {
|
||||
return (PreciseFahrenheit() + 50) / 100;
|
||||
}
|
||||
|
||||
bool operator==(const Temperature& other) const {
|
||||
return raw == other.raw;
|
||||
}
|
||||
|
||||
private:
|
||||
int16_t raw;
|
||||
};
|
||||
|
||||
using Location = std::array<char, 33>; // 32 char + \0 (end of string)
|
||||
|
||||
Reference in New Issue
Block a user