From c57d5d36596f4c25febb6fdc69a88a0a8dce3e2e Mon Sep 17 00:00:00 2001 From: Daniel Dakhno Date: Sun, 16 Feb 2020 01:41:14 +0100 Subject: [PATCH] added find my device support --- .../devices/qhybrid/QHybridSupport.java | 32 ++---------------- .../devices/qhybrid/adapter/WatchAdapter.java | 3 ++ .../adapter/fossil/FossilWatchAdapter.java | 33 +++++++++++++++++++ .../fossil_hr/FossilHRWatchAdapter.java | 22 +++++++++++++ 4 files changed, 60 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java index ab74a8b6b..040ccdea9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/QHybridSupport.java @@ -115,7 +115,7 @@ public class QHybridSupport extends QHybridBaseSupport { private PackageConfigHelper helper; - private volatile boolean searchDevice = false; + public volatile boolean searchDevice = false; private long timeOffset; @@ -511,35 +511,7 @@ public class QHybridSupport extends QHybridBaseSupport { @Override public void onFindDevice(boolean start) { - try { - if (watchAdapter.supportsExtendedVibration()) { - GB.toast("Device does not support brr brr", Toast.LENGTH_SHORT, GB.INFO); - } - } catch (UnsupportedOperationException e) { - notifiyException(e); - GB.toast("Please contact dakhnod@gmail.com\n", Toast.LENGTH_SHORT, GB.INFO); - } - - if (start && searchDevice) return; - - searchDevice = start; - - if (start) { - new Thread(new Runnable() { - @Override - public void run() { - int i = 0; - while (searchDevice) { - QHybridSupport.this.watchAdapter.vibrateFindMyDevicePattern(); - try { - Thread.sleep(2500); - } catch (InterruptedException e) { - GB.log("error", GB.ERROR, e); - } - } - } - }).start(); - } + watchAdapter.onFindDevice(start); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/WatchAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/WatchAdapter.java index 87776e5ec..383c0ffd8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/WatchAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/WatchAdapter.java @@ -121,4 +121,7 @@ public abstract class WatchAdapter { public void onSetCallState(CallSpec callSpec) { } + + public void onFindDevice(boolean start) { + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil/FossilWatchAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil/FossilWatchAdapter.java index 4f8ff123b..c9fc9ea25 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil/FossilWatchAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil/FossilWatchAdapter.java @@ -516,6 +516,39 @@ public class FossilWatchAdapter extends WatchAdapter { public void handleHeartRateCharacteristic(BluetoothGattCharacteristic characteristic) { } + @Override + public void onFindDevice(boolean start) { + try { + if (this.supportsExtendedVibration()) { + GB.toast("Device does not support brr brr", Toast.LENGTH_SHORT, GB.INFO); + } + } catch (UnsupportedOperationException e) { + getDeviceSupport().notifiyException(e); + GB.toast("Please contact dakhnod@gmail.com\n", Toast.LENGTH_SHORT, GB.INFO); + } + + if (start && getDeviceSupport().searchDevice) return; + + getDeviceSupport().searchDevice = start; + + if (start) { + new Thread(new Runnable() { + @Override + public void run() { + int i = 0; + while (getDeviceSupport().searchDevice) { + vibrateFindMyDevicePattern(); + try { + Thread.sleep(2500); + } catch (InterruptedException e) { + GB.log("error", GB.ERROR, e); + } + } + } + }).start(); + } + } + protected void handleBackgroundCharacteristic(BluetoothGattCharacteristic characteristic) { byte[] value = characteristic.getValue(); switch (value[1]) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java index 4d30bfca7..636b74c7f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java @@ -24,6 +24,7 @@ import java.util.GregorianCalendar; import java.util.HashMap; import java.util.Iterator; import java.util.TimeZone; +import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl; @@ -36,6 +37,8 @@ import nodomain.freeyourgadget.gadgetbridge.model.CallSpec; import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec; import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; +import nodomain.freeyourgadget.gadgetbridge.service.btle.Transaction; +import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FossilRequest; @@ -429,6 +432,25 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { return true; } + @Override + public void onFindDevice(boolean start) { + if(start){ + new TransactionBuilder("vibrate find") + .write( + getDeviceSupport().getCharacteristic(UUID.fromString("3dda0005-957f-7d4a-34a6-74696673696d")), + new byte[]{(byte) 0x01, (byte) 0x04, (byte) 0x30, (byte) 0x75, (byte) 0x00, (byte) 0x00} + ) + .queue(getDeviceSupport().getQueue()); + }else{ + new TransactionBuilder("vibrate find") + .write( + getDeviceSupport().getCharacteristic(UUID.fromString("3dda0005-957f-7d4a-34a6-74696673696d")), + new byte[]{(byte) 0x02, (byte) 0x05, (byte) 0x04} + ) + .queue(getDeviceSupport().getQueue()); + } + } + @Override public void onSetCallState(CallSpec callSpec) { super.onSetCallState(callSpec);