1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-23 02:16:48 +01:00

pinetime: Add sunrise and sunset weather data

This commit is contained in:
Victor Kareh 2024-02-08 16:01:09 -05:00
parent 212289645f
commit 769c592940

View File

@ -973,7 +973,14 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
private void onSendWeatherSimple(WeatherSpec weatherSpec) {
long timestampLocal = weatherSpec.timestamp + Calendar.getInstance().getTimeZone().getOffset(Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis()) / 1000L;
ByteBuffer currentPacket = ByteBuffer.allocate(49).order(ByteOrder.LITTLE_ENDIAN);
int weatherMemAlloc = 49;
byte version = 0;
if (isFirmwareAtLeastVersion0_15()) {
weatherMemAlloc = 53;
version = 1;
}
ByteBuffer currentPacket = ByteBuffer.allocate(weatherMemAlloc).order(ByteOrder.LITTLE_ENDIAN);
currentPacket.put(1, version);
currentPacket.putLong(2, timestampLocal);
currentPacket.putShort(10, (short) ((weatherSpec.currentTemp - 273.15) * 100));
currentPacket.putShort(12, (short) ((weatherSpec.todayMinTemp - 273.15) * 100));
@ -986,6 +993,14 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
}
currentPacket.put(48, mapOpenWeatherConditionToPineTimeCondition(weatherSpec.currentConditionCode).value);
if (isFirmwareAtLeastVersion0_15()) {
// Calculate sunrise and sunset minutes since midnight
short sunriseMinutes = (short) ((weatherSpec.sunRise + Calendar.getInstance().getTimeZone().getOffset(Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis()) / 1000L) / 60 % 1440);
short sunsetMinutes = (short) ((weatherSpec.sunSet + Calendar.getInstance().getTimeZone().getOffset(Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis()) / 1000L) / 60 % 1440);
currentPacket.putShort(49, sunriseMinutes);
currentPacket.putShort(51, sunsetMinutes);
}
TransactionBuilder currentBuilder = createTransactionBuilder("SimpleWeatherData");
safeWriteToCharacteristic(currentBuilder,
PineTimeJFConstants.UUID_CHARACTERISTIC_SIMPLE_WEATHER_DATA,