Search in sources :

Example 1 with ConditionalWriteAction

use of nodomain.freeyourgadget.gadgetbridge.service.btle.actions.ConditionalWriteAction in project Gadgetbridge by Freeyourgadget.

the class MiBandSupport method setWearLocation.

/**
     * Part of device initialization process. Do not call manually.
     *
     * @param transaction
     * @return
     */
private MiBandSupport setWearLocation(TransactionBuilder transaction) {
    LOG.info("Attempting to set wear location...");
    BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
    if (characteristic != null) {
        transaction.add(new ConditionalWriteAction(characteristic) {

            @Override
            protected byte[] checkCondition() {
                if (getDeviceInfo() != null && getDeviceInfo().isAmazFit()) {
                    return null;
                }
                int location = MiBandCoordinator.getWearLocation(getDevice().getAddress());
                return new byte[] { MiBandService.COMMAND_SET_WEAR_LOCATION, (byte) location };
            }
        });
    } else {
        LOG.info("Unable to set Wear Location");
    }
    return this;
}
Also used : ConditionalWriteAction(nodomain.freeyourgadget.gadgetbridge.service.btle.actions.ConditionalWriteAction) BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Aggregations

BluetoothGattCharacteristic (android.bluetooth.BluetoothGattCharacteristic)1 ConditionalWriteAction (nodomain.freeyourgadget.gadgetbridge.service.btle.actions.ConditionalWriteAction)1