1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-24 10:56:50 +01:00

Casio GW-B5600: find phone

This commit is contained in:
Johannes Krude 2023-08-19 22:21:35 +02:00 committed by José Rebelo
parent 4a9fd49461
commit b155a13d17
2 changed files with 45 additions and 2 deletions

View File

@ -112,6 +112,12 @@ public final class CasioConstants {
public static final byte CATEGORY_SNS = 4;
public static final byte CATEGORY_VOICEMAIL = 3;
// Connection Reason - GW-B5600
public static final byte CONNECT_CNCT = 1;
public static final byte CONNECT_FIND = 2;
public static final byte CONNECT_AUTO = 3;
public static final byte CONNECT_TIME = 4;
public enum Model {
MODEL_CASIO_GENERIC,
MODEL_CASIO_6900B,

View File

@ -21,6 +21,9 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Locale;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -33,6 +36,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioConstants;
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.Casio2C2DSupport;
@ -70,12 +74,21 @@ public class CasioGWB5600DeviceSupport extends Casio2C2DSupport {
}
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext()));
requestWorldClocks(builder);
// which button was pressed?
requestFeature(builder, new FeatureRequest(FEATURE_BLE_FEATURES), data -> {
if (data.length > 8 && data[8] == CasioConstants.CONNECT_FIND) {
setInitialized();
} else {
requestWorldClocks();
}
});
return builder;
}
private void requestWorldClocks(TransactionBuilder builder) {
private void requestWorldClocks() {
TransactionBuilder builder = createTransactionBuilder("requestWorldClocks");
HashSet<FeatureRequest> requests = new HashSet();
for (byte i = 0; i < 6; i++) {
@ -88,6 +101,7 @@ public class CasioGWB5600DeviceSupport extends Casio2C2DSupport {
clockBuilder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
clockBuilder.queue(getQueue());
});
builder.queue(getQueue());
}
private void setClocks(TransactionBuilder builder, Map<FeatureRequest, byte[]> responses) {
@ -110,4 +124,27 @@ public class CasioGWB5600DeviceSupport extends Casio2C2DSupport {
writeCurrentTime(builder, ZonedDateTime.ofInstant(now, tz));
}
@Override
public boolean onCharacteristicChanged(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic) {
UUID characteristicUUID = characteristic.getUuid();
byte[] data = characteristic.getValue();
if (data.length == 0)
return true;
if (characteristicUUID.equals(CasioConstants.CASIO_ALL_FEATURES_CHARACTERISTIC_UUID)) {
if(data[0] == FEATURE_ALERT_LEVEL) {
GBDeviceEventFindPhone event = new GBDeviceEventFindPhone();
if(data[1] == 0x02) {
event.event = GBDeviceEventFindPhone.Event.START_VIBRATE;
} else {
event.event = GBDeviceEventFindPhone.Event.STOP;
}
evaluateGBDeviceEvent(event);
return true;
}
}
return super.onCharacteristicChanged(gatt, characteristic);
}
}