From 7115b1e9f14c3603aac704df295c857e021f5147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sun, 21 Jul 2024 12:22:25 +0100 Subject: [PATCH] CMF Watch Pro: Send gps location to the watch --- .../cmfwatchpro/CmfWatchProSupport.java | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cmfwatchpro/CmfWatchProSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cmfwatchpro/CmfWatchProSupport.java index 576c92444..70be70761 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cmfwatchpro/CmfWatchProSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/cmfwatchpro/CmfWatchProSupport.java @@ -21,6 +21,7 @@ import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCharacteristic; import android.content.Context; import android.content.SharedPreferences; +import android.location.Location; import android.media.AudioManager; import android.net.Uri; import android.os.Build; @@ -64,6 +65,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSuppo import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction; +import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.webview.CurrentPosition; import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol; import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.MediaManager; @@ -261,6 +263,10 @@ public class CmfWatchProSupport extends AbstractBTLEDeviceSupport implements Cmf setTime(phase2builder); sendCommand(phase2builder, CmfCommand.FIRMWARE_VERSION_GET); sendCommand(phase2builder, CmfCommand.SERIAL_NUMBER_GET); + final Location location = new CurrentPosition().getLastKnownLocation(); + if (location.getLatitude() != 0 && location.getLongitude() != 0) { + sendGpsCoords(phase2builder, location); + } //sendCommand(phase2builder, CmfCommand.STANDING_REMINDER_GET); //sendCommand(phase2builder, CmfCommand.WATER_REMINDER_GET); //sendCommand(phase2builder, CmfCommand.CONTACTS_GET); @@ -382,6 +388,24 @@ public class CmfWatchProSupport extends AbstractBTLEDeviceSupport implements Cmf return authKeyBytes; } + @Override + public void onSetGpsLocation(final Location location) { + final TransactionBuilder builder = createTransactionBuilder("set gps location"); + sendGpsCoords(builder, location); + builder.queue(getQueue()); + } + + private void sendGpsCoords(final TransactionBuilder builder, final Location location) { + final ByteBuffer buf = ByteBuffer.allocate(16) + .order(ByteOrder.BIG_ENDIAN); + + buf.putInt((int) (location.getTime() / 1000)); + buf.putInt((int) (location.getLatitude() * 10000000)); + buf.putInt((int) (location.getLongitude() * 10000000)); + + sendCommand(builder, CmfCommand.GPS_COORDS, buf.array()); + } + @Override public void onNotification(final NotificationSpec notificationSpec) { if (!getDevicePrefs().getBoolean(DeviceSettingsPreferenceConst.PREF_SEND_APP_NOTIFICATIONS, true)) { @@ -595,7 +619,7 @@ public class CmfWatchProSupport extends AbstractBTLEDeviceSupport implements Cmf // There are 7 of those weather entries - 7*9 bytes // Then there are 24-hour entries of temp and weather condition (2 bytes each) // Then finally the location name as bytes - allow for 30 bytes, watch auto-scrolls - final ByteBuffer buf = ByteBuffer.allocate((7*9) + (24*2) + 30).order(ByteOrder.BIG_ENDIAN); + final ByteBuffer buf = ByteBuffer.allocate((7 * 9) + (24 * 2) + 30).order(ByteOrder.BIG_ENDIAN); // start with the current day's weather buf.put(Weather.mapToCmfCondition(weatherSpec.currentConditionCode)); buf.put((byte) (weatherSpec.currentTemp - 273 + 100)); // convert Kelvin to C, add 100 @@ -609,7 +633,7 @@ public class CmfWatchProSupport extends AbstractBTLEDeviceSupport implements Cmf // find out how many future days' forecasts are available int maxForecastsAvailable = weatherSpec.forecasts.size(); // For each day of the forecast - for (int i=0; i < 6; i++) { + for (int i = 0; i < 6; i++) { if (i < maxForecastsAvailable) { WeatherSpec.Daily forecastDay = weatherSpec.forecasts.get(i); buf.put((byte) (Weather.mapToCmfCondition(forecastDay.conditionCode))); // weather condition flag @@ -635,7 +659,7 @@ public class CmfWatchProSupport extends AbstractBTLEDeviceSupport implements Cmf } // now add the hourly data for today - just condition and temperature int maxHourlyForecastsAvailable = weatherSpec.hourly.size(); - for (int i=0; i < 24; i++) { + for (int i = 0; i < 24; i++) { if (i < maxHourlyForecastsAvailable) { WeatherSpec.Hourly forecastHr = weatherSpec.hourly.get(i); buf.put((byte) (forecastHr.temp - 273 + 100)); // temperature