1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-15 14:39:26 +01:00

Garmin protocol: create specific field definition for day of week

This commit is contained in:
Daniele Gobbetti 2024-03-24 17:17:53 +01:00
parent e323e7fbde
commit 71f497ecbb
2 changed files with 34 additions and 2 deletions

View File

@ -189,7 +189,7 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
todayDailyForecast.setFieldByName("high_temperature", weather.todayMaxTemp - 273.15); todayDailyForecast.setFieldByName("high_temperature", weather.todayMaxTemp - 273.15);
todayDailyForecast.setFieldByName("condition", FitWeatherConditions.openWeatherCodeToFitWeatherStatus(weather.currentConditionCode)); todayDailyForecast.setFieldByName("condition", FitWeatherConditions.openWeatherCodeToFitWeatherStatus(weather.currentConditionCode));
todayDailyForecast.setFieldByName("precipitation_probability", weather.precipProbability); todayDailyForecast.setFieldByName("precipitation_probability", weather.precipProbability);
todayDailyForecast.setFieldByName("day_of_week", GarminTimeUtils.unixTimeToGarminDayOfWeek(weather.timestamp)); todayDailyForecast.setFieldByName("day_of_week", weather.timestamp);
weatherData.add(todayDailyForecast); weatherData.add(todayDailyForecast);
@ -204,7 +204,7 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
weatherDailyForecast.setFieldByName("high_temperature", daily.maxTemp - 273.15); weatherDailyForecast.setFieldByName("high_temperature", daily.maxTemp - 273.15);
weatherDailyForecast.setFieldByName("condition", FitWeatherConditions.openWeatherCodeToFitWeatherStatus(daily.conditionCode)); weatherDailyForecast.setFieldByName("condition", FitWeatherConditions.openWeatherCodeToFitWeatherStatus(daily.conditionCode));
weatherDailyForecast.setFieldByName("precipitation_probability", daily.precipProbability); weatherDailyForecast.setFieldByName("precipitation_probability", daily.precipProbability);
weatherDailyForecast.setFieldByName("day_of_week", GarminTimeUtils.unixTimeToGarminDayOfWeek(ts)); weatherDailyForecast.setFieldByName("day_of_week", ts);
weatherData.add(weatherDailyForecast); weatherData.add(weatherDailyForecast);
} }
} }

View File

@ -0,0 +1,32 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.fieldDefinitions;
import org.threeten.bp.DayOfWeek;
import org.threeten.bp.Instant;
import org.threeten.bp.ZoneId;
import java.nio.ByteBuffer;
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.FieldDefinition;
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.baseTypes.BaseType;
public class FieldDefinitionDayOfWeek extends FieldDefinition {
public FieldDefinitionDayOfWeek(int localNumber, int size, BaseType baseType, String name) {
super(localNumber, size, baseType, name, 1, 0);
}
@Override
public Object decode(ByteBuffer byteBuffer) {
int raw = (int) baseType.decode(byteBuffer, scale, offset);
return DayOfWeek.of(raw == 0 ? 7 : raw);
}
@Override
public void encode(ByteBuffer byteBuffer, Object o) {
if (o instanceof DayOfWeek) {
baseType.encode(byteBuffer, (((DayOfWeek) o).getValue() % 7), scale, offset);
return;
}
baseType.encode(byteBuffer, (Instant.ofEpochSecond((int) o).atZone(ZoneId.systemDefault()).getDayOfWeek().getValue() % 7), scale, offset);
}
}