@@ -854,7 +854,7 @@ class Framework {
854
854
void set_forecast (
855
855
uint64_t timestamp,
856
856
std::array<
857
- Pinetime::Controllers::SimpleWeatherService::Forecast::Day,
857
+ std::optional< Pinetime::Controllers::SimpleWeatherService::Forecast::Day> ,
858
858
Pinetime::Controllers::SimpleWeatherService::MaxNbForecastDays> days)
859
859
{
860
860
std::array<uint8_t , 36 > dataBuffer {};
@@ -871,10 +871,13 @@ class Framework {
871
871
dataBuffer.at (10 ) = static_cast <uint8_t >(days.size ());
872
872
for (int i = 0 ; i < days.size (); i++)
873
873
{
874
- const Pinetime::Controllers::SimpleWeatherService::Forecast::Day &day = days.at (i);
875
- write_int16 (data.subspan (11 +(i*5 )), day.minTemperature );
876
- write_int16 (data.subspan (13 +(i*5 )), day.maxTemperature );
877
- dataBuffer.at (15 +(i*5 )) = static_cast <uint8_t >(day.iconId );
874
+ const std::optional<Pinetime::Controllers::SimpleWeatherService::Forecast::Day> &day = days.at (i);
875
+ if (!day.has_value ()) {
876
+ continue ;
877
+ }
878
+ write_int16 (data.subspan (11 +(i*5 )), day->minTemperature .PreciseCelsius ());
879
+ write_int16 (data.subspan (13 +(i*5 )), day->maxTemperature .PreciseCelsius ());
880
+ dataBuffer.at (15 +(i*5 )) = static_cast <uint8_t >(day->iconId );
878
881
}
879
882
// send Forecast to SimpleWeatherService
880
883
systemTask.nimble ().weather ().OnCommand (&ctxt);
@@ -883,7 +886,7 @@ class Framework {
883
886
void generate_weather_data (bool clear) {
884
887
if (clear) {
885
888
set_current_weather (0 , 0 , 0 );
886
- std::array<Pinetime::Controllers::SimpleWeatherService::Forecast::Day, Pinetime::Controllers::SimpleWeatherService::MaxNbForecastDays> days;
889
+ std::array<std::optional< Pinetime::Controllers::SimpleWeatherService::Forecast::Day> , Pinetime::Controllers::SimpleWeatherService::MaxNbForecastDays> days;
887
890
set_forecast (0 , days);
888
891
return ;
889
892
}
@@ -895,10 +898,12 @@ class Framework {
895
898
set_current_weather ((uint64_t )timestamp, temperature, rand () % 9 );
896
899
897
900
// Generate forecast data
898
- std::array<Pinetime::Controllers::SimpleWeatherService::Forecast::Day, Pinetime::Controllers::SimpleWeatherService::MaxNbForecastDays> days;
901
+ std::array<std::optional< Pinetime::Controllers::SimpleWeatherService::Forecast::Day> , Pinetime::Controllers::SimpleWeatherService::MaxNbForecastDays> days;
899
902
for (int i = 0 ; i < Pinetime::Controllers::SimpleWeatherService::MaxNbForecastDays; i++) {
900
903
days[i] = Pinetime::Controllers::SimpleWeatherService::Forecast::Day {
901
- (int16_t )(temperature - rand () % 10 * 100 ), (int16_t )(temperature + rand () % 10 * 100 ), Pinetime::Controllers::SimpleWeatherService::Icons (rand () % 9 )
904
+ Pinetime::Controllers::SimpleWeatherService::Temperature (temperature - rand () % 10 * 100 ),
905
+ Pinetime::Controllers::SimpleWeatherService::Temperature (temperature + rand () % 10 * 100 ),
906
+ Pinetime::Controllers::SimpleWeatherService::Icons (rand () % 9 ),
902
907
};
903
908
}
904
909
set_forecast ((uint64_t )timestamp, days);
0 commit comments