Skip to content

Commit

Permalink
Merge pull request InfiniTimeOrg#164 from FintasticMan/fix-weather
Browse files Browse the repository at this point in the history
Fix build after temperature type changes
  • Loading branch information
NeroBurner authored Nov 12, 2024
2 parents 4590378 + e71293e commit 832d38f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ class Framework {
void set_forecast(
uint64_t timestamp,
std::array<
Pinetime::Controllers::SimpleWeatherService::Forecast::Day,
std::optional<Pinetime::Controllers::SimpleWeatherService::Forecast::Day>,
Pinetime::Controllers::SimpleWeatherService::MaxNbForecastDays> days)
{
std::array<uint8_t, 36> dataBuffer {};
Expand All @@ -871,10 +871,13 @@ class Framework {
dataBuffer.at(10) = static_cast<uint8_t>(days.size());
for (int i = 0; i < days.size(); i++)
{
const Pinetime::Controllers::SimpleWeatherService::Forecast::Day &day = days.at(i);
write_int16(data.subspan(11+(i*5)), day.minTemperature);
write_int16(data.subspan(13+(i*5)), day.maxTemperature);
dataBuffer.at(15+(i*5)) = static_cast<uint8_t>(day.iconId);
const std::optional<Pinetime::Controllers::SimpleWeatherService::Forecast::Day> &day = days.at(i);
if (!day.has_value()) {
continue;
}
write_int16(data.subspan(11+(i*5)), day->minTemperature.PreciseCelsius());
write_int16(data.subspan(13+(i*5)), day->maxTemperature.PreciseCelsius());
dataBuffer.at(15+(i*5)) = static_cast<uint8_t>(day->iconId);
}
// send Forecast to SimpleWeatherService
systemTask.nimble().weather().OnCommand(&ctxt);
Expand All @@ -883,7 +886,7 @@ class Framework {
void generate_weather_data(bool clear) {
if (clear) {
set_current_weather(0, 0, 0);
std::array<Pinetime::Controllers::SimpleWeatherService::Forecast::Day, Pinetime::Controllers::SimpleWeatherService::MaxNbForecastDays> days;
std::array<std::optional<Pinetime::Controllers::SimpleWeatherService::Forecast::Day>, Pinetime::Controllers::SimpleWeatherService::MaxNbForecastDays> days;
set_forecast(0, days);
return;
}
Expand All @@ -895,10 +898,12 @@ class Framework {
set_current_weather((uint64_t)timestamp, temperature, rand() % 9);

// Generate forecast data
std::array<Pinetime::Controllers::SimpleWeatherService::Forecast::Day, Pinetime::Controllers::SimpleWeatherService::MaxNbForecastDays> days;
std::array<std::optional<Pinetime::Controllers::SimpleWeatherService::Forecast::Day>, Pinetime::Controllers::SimpleWeatherService::MaxNbForecastDays> days;
for (int i = 0; i < Pinetime::Controllers::SimpleWeatherService::MaxNbForecastDays; i++) {
days[i] = Pinetime::Controllers::SimpleWeatherService::Forecast::Day {
(int16_t)(temperature - rand() % 10 * 100), (int16_t)(temperature + rand() % 10 * 100), Pinetime::Controllers::SimpleWeatherService::Icons(rand() % 9)
Pinetime::Controllers::SimpleWeatherService::Temperature(temperature - rand() % 10 * 100),
Pinetime::Controllers::SimpleWeatherService::Temperature(temperature + rand() % 10 * 100),
Pinetime::Controllers::SimpleWeatherService::Icons(rand() % 9),
};
}
set_forecast((uint64_t)timestamp, days);
Expand Down

0 comments on commit 832d38f

Please sign in to comment.