Search in sources :

Example 1 with SetDeviceBusyAction

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

the class FetchActivityOperation method doPerform.

@Override
protected void doPerform() throws IOException {
    TransactionBuilder builder = performInitialized("fetching activity data");
    getSupport().setLowLatency(builder);
    builder.add(new SetDeviceBusyAction(getDevice(), getContext().getString(R.string.busy_task_fetch_activity_data), getContext()));
    BluetoothGattCharacteristic characteristicFetch = getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC4);
    builder.notify(characteristicFetch, true);
    BluetoothGattCharacteristic characteristicActivityData = getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_5_ACTIVITY_DATA);
    GregorianCalendar sinceWhen = getLastSuccessfulSyncTime();
    builder.write(characteristicFetch, BLETypeConversions.join(new byte[] { MiBand2Service.COMMAND_ACTIVITY_DATA_START_DATE, 0x01 }, getSupport().getTimeBytes(sinceWhen, TimeUnit.MINUTES)));
    // TODO: actually wait for the success-reply
    builder.add(new WaitAction(1000));
    builder.notify(characteristicActivityData, true);
    builder.write(characteristicFetch, new byte[] { MiBand2Service.COMMAND_FETCH_ACTIVITY_DATA });
    builder.queue(getQueue());
}
Also used : GregorianCalendar(java.util.GregorianCalendar) TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) SetDeviceBusyAction(nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction) BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic) WaitAction(nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WaitAction)

Example 2 with SetDeviceBusyAction

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

the class FetchActivityOperation method doPerform.

@Override
protected void doPerform() throws IOException {
    //        scheduleTaskExecutor = Executors.newScheduledThreadPool(1);
    TransactionBuilder builder = performInitialized("fetch activity data");
    getSupport().setLowLatency(builder);
    builder.add(new SetDeviceBusyAction(getDevice(), getContext().getString(R.string.busy_task_fetch_activity_data), getContext()));
    builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT), fetch);
    builder.queue(getQueue());
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) SetDeviceBusyAction(nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction)

Example 3 with SetDeviceBusyAction

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

the class UpdateFirmwareOperation method sendFwInfo.

public boolean sendFwInfo() {
    try {
        TransactionBuilder builder = performInitialized("send firmware info");
        //                getSupport().setLowLatency(builder);
        builder.add(new SetDeviceBusyAction(getDevice(), getContext().getString(R.string.updating_firmware), getContext()));
        int fwSize = getFirmwareInfo().getSize();
        byte[] sizeBytes = BLETypeConversions.fromUint24(fwSize);
        int arraySize = 4;
        boolean isFirmwareCode = getFirmwareInfo().getFirmwareType() == FirmwareType.FIRMWARE;
        if (!isFirmwareCode) {
            arraySize++;
        }
        byte[] bytes = new byte[arraySize];
        int i = 0;
        bytes[i++] = MiBand2Service.COMMAND_FIRMWARE_INIT;
        bytes[i++] = sizeBytes[0];
        bytes[i++] = sizeBytes[1];
        bytes[i++] = sizeBytes[2];
        if (!isFirmwareCode) {
            bytes[i++] = getFirmwareInfo().getFirmwareType().getValue();
        }
        builder.write(fwCControlChar, bytes);
        builder.queue(getQueue());
        return true;
    } catch (IOException e) {
        LOG.error("Error sending firmware info: " + e.getLocalizedMessage(), e);
        return false;
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) SetDeviceBusyAction(nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction) IOException(java.io.IOException)

Aggregations

TransactionBuilder (nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder)3 SetDeviceBusyAction (nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction)3 BluetoothGattCharacteristic (android.bluetooth.BluetoothGattCharacteristic)1 IOException (java.io.IOException)1 GregorianCalendar (java.util.GregorianCalendar)1 WaitAction (nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WaitAction)1