Search in sources :

Example 1 with WaitAction

use of nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WaitAction 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)

Aggregations

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