mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
igpsport: add hourly and daily forecast
This commit is contained in:
committed by
José Rebelo
parent
e339ad876a
commit
56e67e0761
+48
-1
@@ -20,6 +20,10 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
@@ -669,7 +673,12 @@ public class IGPSportDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
private void handleWeather(WeatherSpec weatherSpec) {
|
||||
//example weather packet
|
||||
//010302ff02ffff00fe3601ffffffffffffffff04080310021802221508ac021012180b20002a0a323032342d30382d3330221508ac021015180a20002a0a323032342d30382d3331221408651019180c20002a0a323032342d30392d30312a20081310651812200b2a10323032342d30382d33302030333a34373201303a0132322108651011180d2210323032342d30382d33302030353a30302a0331353832023133322108651012180d2210323032342d30382d33302030363a30302a033136373202313332210865101018112210323032342d30382d33302030373a30302a0331373932023133322208ac02100f18332210323032342d30382d33302030383a30302a03323031320231333a0308e807
|
||||
|
||||
try {
|
||||
LocalDateTime currentTime = LocalDateTime.now();
|
||||
DateTimeFormatter formatterNow = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
||||
TransactionBuilder builder = performInitialized("set weather");
|
||||
Back.back_msg.Builder weatherMsg = Back.back_msg.newBuilder();
|
||||
Back.weather_current_data_message.Builder currentWeatherMsg =Back.weather_current_data_message.newBuilder();
|
||||
@@ -678,13 +687,51 @@ public class IGPSportDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
currentWeatherMsg.setCurTemperature(weatherSpec.currentTemp-273);
|
||||
currentWeatherMsg.setCurWeather(weatherSpec.currentConditionCode);
|
||||
currentWeatherMsg.setWindDeg(String.valueOf(weatherSpec.windDirection));
|
||||
currentWeatherMsg.setWindSpd(String.valueOf(weatherSpec.windSpeed));
|
||||
currentWeatherMsg.setWindSpd(String.valueOf(Math.round(weatherSpec.windSpeed)));
|
||||
currentWeatherMsg.setTime(currentTime.format(formatterNow));
|
||||
|
||||
int currentDay=0;
|
||||
|
||||
for (final WeatherSpec.Daily forecast : weatherSpec.forecasts) {
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
currentDay++;
|
||||
LocalDateTime tomorrow = now.plusDays(currentDay);
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE; //"yyyy-MM-dd"
|
||||
weatherMsg.addThreeDaysMsg(Back.weather_three_days_data_message.newBuilder()
|
||||
.setWeatherIndex(forecast.conditionCode)
|
||||
.setRainProb(forecast.precipProbability)
|
||||
.setMaxTemp(forecast.maxTemp-273)
|
||||
.setMinTemp(forecast.minTemp-273)
|
||||
.setDate(tomorrow.format(formatter)).build());
|
||||
|
||||
if (currentDay > 2) //we only need 3 days
|
||||
break;
|
||||
}
|
||||
|
||||
int currentHour=0;
|
||||
for (final WeatherSpec.Hourly hourly : weatherSpec.hourly) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
weatherMsg.addThreeHoursMsg(Back.weather_three_hour_data_memsage.newBuilder()
|
||||
.setWatherIndex(hourly.conditionCode)
|
||||
.setRainProb(hourly.precipProbability)
|
||||
.setTemp(hourly.temp-273)
|
||||
.setTime(sdf.format(new Date(hourly.timestamp * 1000L)))
|
||||
.setWindDeg(String.valueOf(hourly.windDirection))
|
||||
.setWindSpd(String.valueOf(Math.round(hourly.windSpeed))).build());
|
||||
currentHour++;
|
||||
if (currentHour > 3 ) // its called three hour weather but shows actually 4 entries
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
weatherMsg.setCurMsg(currentWeatherMsg);
|
||||
weatherMsg.setServiceType(Common.service_type_index.enum_SERVICE_TYPE_INDEX_BACK);
|
||||
weatherMsg.setBackOperateType(Back.BACK_OPERATE_TYPE.enum_BACK_OPERATE_TYPE_SEND);
|
||||
weatherMsg.setBackServiceType(Back.BACK_SERVICE_TYPE.enum_BACK_SERVICE_TYPE_WEATHER);
|
||||
|
||||
|
||||
|
||||
byte[] weatherBytes = craftData(weatherMsg.getServiceType().getNumber(),
|
||||
weatherMsg.getBackServiceType().getNumber(),
|
||||
weatherMsg.getBackOperateType().getNumber(),
|
||||
|
||||
Reference in New Issue
Block a user