From 769c59294083fbf39dd78e15a4f8c4935d4147de Mon Sep 17 00:00:00 2001 From: Victor Kareh Date: Thu, 8 Feb 2024 16:01:09 -0500 Subject: [PATCH] pinetime: Add sunrise and sunset weather data --- .../devices/pinetime/PineTimeJFSupport.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pinetime/PineTimeJFSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pinetime/PineTimeJFSupport.java index c9b6d9095..b0d621d4b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pinetime/PineTimeJFSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pinetime/PineTimeJFSupport.java @@ -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,