mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-06-22 04:50:08 +02:00
Add support for InfiniTime's new simple weather
Co-authored-by: Jean-François Milants <jf@codingfield.com>
This commit is contained in:
parent
4d5ce069aa
commit
127867441a
|
@ -48,6 +48,9 @@ public class PineTimeJFConstants {
|
|||
public static final UUID UUID_CHARACTERISTIC_WEATHER_DATA = UUID.fromString("00040001-78fc-48fe-8e23-433b3a1942d0");
|
||||
public static final UUID UUID_CHARACTERISTIC_WEATHER_CONTROL = UUID.fromString("00040002-78fc-48fe-8e23-433b3a1942d0");
|
||||
|
||||
public static final UUID UUID_SERVICE_SIMPLE_WEATHER = UUID.fromString("00050000-78fc-48fe-8e23-433b3a1942d0");
|
||||
public static final UUID UUID_CHARACTERISTIC_SIMPLE_WEATHER_DATA = UUID.fromString("00050001-78fc-48fe-8e23-433b3a1942d0");
|
||||
|
||||
// since 1.7. https://github.com/InfiniTimeOrg/InfiniTime/blob/develop/doc/MotionService.md
|
||||
public static final UUID UUID_SERVICE_MOTION = UUID.fromString("00030000-78fc-48fe-8e23-433b3a1942d0");
|
||||
public static final UUID UUID_CHARACTERISTIC_MOTION_STEP_COUNT = UUID.fromString("00030001-78fc-48fe-8e23-433b3a1942d0");
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
@ -264,6 +265,7 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
|
|||
addSupportedService(GattService.UUID_SERVICE_BATTERY_SERVICE);
|
||||
addSupportedService(PineTimeJFConstants.UUID_SERVICE_MUSIC_CONTROL);
|
||||
addSupportedService(PineTimeJFConstants.UUID_SERVICE_WEATHER);
|
||||
addSupportedService(PineTimeJFConstants.UUID_SERVICE_SIMPLE_WEATHER);
|
||||
addSupportedService(PineTimeJFConstants.UUID_SERVICE_NAVIGATION);
|
||||
addSupportedService(PineTimeJFConstants.UUID_CHARACTERISTIC_ALERT_NOTIFICATION_EVENT);
|
||||
addSupportedService(PineTimeJFConstants.UUID_SERVICE_MOTION);
|
||||
|
@ -731,12 +733,7 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSendWeather(WeatherSpec weatherSpec) {
|
||||
if (this.firmwareVersionMajor != 1 || this.firmwareVersionMinor <= 7) {
|
||||
// Not supported
|
||||
return;
|
||||
} else {
|
||||
private void onSendWeatherCBOR(WeatherSpec weatherSpec) {
|
||||
if (weatherSpec.location != null) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
|
@ -979,6 +976,63 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
|
|||
|
||||
LOG.debug("Wrote weather data");
|
||||
}
|
||||
|
||||
private void onSendWeatherSimple(WeatherSpec weatherSpec) {
|
||||
ByteBuffer currentPacket = ByteBuffer.allocate(49).order(ByteOrder.LITTLE_ENDIAN);
|
||||
currentPacket.putLong(2, (long) weatherSpec.timestamp * 1000000000L); // 10^9, for nanoseconds
|
||||
currentPacket.putShort(10, (short) ((weatherSpec.currentTemp - 273.15) * 100));
|
||||
currentPacket.putShort(12, (short) ((weatherSpec.todayMinTemp - 273.15) * 100));
|
||||
currentPacket.putShort(14, (short) ((weatherSpec.todayMaxTemp - 273.15) * 100));
|
||||
if (weatherSpec.location != null) {
|
||||
byte[] locationBytes = nodomain.freeyourgadget.gadgetbridge.util.StringUtils.truncateToBytes(weatherSpec.location, 32);
|
||||
for (int i = 0; i < locationBytes.length; i++) {
|
||||
currentPacket.put(16 + i, locationBytes[i]);
|
||||
}
|
||||
}
|
||||
// currentPacket.put(48, ); // condition
|
||||
|
||||
TransactionBuilder currentBuilder = createTransactionBuilder("SimpleWeatherData");
|
||||
safeWriteToCharacteristic(currentBuilder,
|
||||
PineTimeJFConstants.UUID_CHARACTERISTIC_SIMPLE_WEATHER_DATA,
|
||||
currentPacket.array());
|
||||
|
||||
currentBuilder.queue(getQueue());
|
||||
|
||||
if (weatherSpec.forecasts == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ByteBuffer forecastPacket = ByteBuffer.allocate(36).order(ByteOrder.LITTLE_ENDIAN);
|
||||
forecastPacket.put(0, (byte) 1);
|
||||
forecastPacket.putLong(2, (long) weatherSpec.timestamp * 1000000000L); // 10^9, for nanoseconds
|
||||
byte nbDays = (byte) Math.min(weatherSpec.forecasts.size(), 5);
|
||||
forecastPacket.put(10, nbDays);
|
||||
for (int i = 0; i < nbDays; i++) {
|
||||
forecastPacket.putShort(11 + i * 5, (short) ((weatherSpec.forecasts.get(i).minTemp - 273.15) * 100));
|
||||
forecastPacket.putShort(11 + i * 5 + 2, (short) ((weatherSpec.forecasts.get(i).maxTemp - 273.15) * 100));
|
||||
// forecastPacket.put(11 + i * 5 + 4, ); // condition
|
||||
}
|
||||
|
||||
TransactionBuilder forecastBuilder = createTransactionBuilder("SimpleWeatherData");
|
||||
safeWriteToCharacteristic(forecastBuilder,
|
||||
PineTimeJFConstants.UUID_CHARACTERISTIC_SIMPLE_WEATHER_DATA,
|
||||
currentPacket.array());
|
||||
|
||||
forecastBuilder.queue(getQueue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSendWeather(WeatherSpec weatherSpec) {
|
||||
if (this.firmwareVersionMajor < 1 || (this.firmwareVersionMajor == 1 && this.firmwareVersionMinor <= 7)) {
|
||||
// Not supported
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.firmwareVersionMajor == 1 && this.firmwareVersionMinor <= 13) {
|
||||
this.onSendWeatherCBOR(weatherSpec);
|
||||
} else {
|
||||
this.onSendWeatherSimple(weatherSpec);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user