1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-02-24 08:21:15 +01:00

CMF Watch Pro: Send gps location to the watch

This commit is contained in:
José Rebelo 2024-07-21 12:22:25 +01:00
parent 89a3fcc920
commit 7115b1e9f1

View File

@ -21,6 +21,7 @@ import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattCharacteristic;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.location.Location;
import android.media.AudioManager; import android.media.AudioManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build; 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.BLETypeConversions;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction; 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.service.serial.GBDeviceProtocol;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.MediaManager; import nodomain.freeyourgadget.gadgetbridge.util.MediaManager;
@ -261,6 +263,10 @@ public class CmfWatchProSupport extends AbstractBTLEDeviceSupport implements Cmf
setTime(phase2builder); setTime(phase2builder);
sendCommand(phase2builder, CmfCommand.FIRMWARE_VERSION_GET); sendCommand(phase2builder, CmfCommand.FIRMWARE_VERSION_GET);
sendCommand(phase2builder, CmfCommand.SERIAL_NUMBER_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.STANDING_REMINDER_GET);
//sendCommand(phase2builder, CmfCommand.WATER_REMINDER_GET); //sendCommand(phase2builder, CmfCommand.WATER_REMINDER_GET);
//sendCommand(phase2builder, CmfCommand.CONTACTS_GET); //sendCommand(phase2builder, CmfCommand.CONTACTS_GET);
@ -382,6 +388,24 @@ public class CmfWatchProSupport extends AbstractBTLEDeviceSupport implements Cmf
return authKeyBytes; 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 @Override
public void onNotification(final NotificationSpec notificationSpec) { public void onNotification(final NotificationSpec notificationSpec) {
if (!getDevicePrefs().getBoolean(DeviceSettingsPreferenceConst.PREF_SEND_APP_NOTIFICATIONS, true)) { if (!getDevicePrefs().getBoolean(DeviceSettingsPreferenceConst.PREF_SEND_APP_NOTIFICATIONS, true)) {