From 7f7cea75c1e0bdac1585774d812905dc3cfebf79 Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Sun, 19 Jul 2015 15:52:27 +0200 Subject: [PATCH] Spare some complexity by letting the writer change the status to non-busy. Before the code looked for the values written to the device with another method. --- .../gadgetbridge/miband/MiBandSupport.java | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java index 5de6c4dd..b73d6e1f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/miband/MiBandSupport.java @@ -687,12 +687,8 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { LOG.info("handleControlPoint got status:" + status); if (getDevice().isBusy()) { - if (isActivityDataSyncFinished(value)) { - unsetBusy(); - } else { if (value != null && value.length == 9 && value[0] == 0xa) { handleActivityCheckpoint(value); - } } } if (value != null) { @@ -720,18 +716,6 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { flushActivityDataHolder(); } - private boolean isActivityDataSyncFinished(byte[] value) { - // byte 0 is the kind of message - // byte 1 to 6 represent a timestamp - // byte 7 to 8 represent the amount of data left (0 = done) - if (value.length == 9) { - if (value[0] == 0xa && value[7] == 0 && value[8] == 0) { - return true; - } - } - return false; - } - private void unsetBusy() { getDevice().unsetBusyTask(); getDevice().sendDeviceUpdateIntent(getContext()); @@ -753,6 +737,11 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { TransactionBuilder builder = performInitialized("send acknowledge"); builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT), ack); builder.queue(getQueue()); + //The last data chunk sent by the miband has always length 0. + //When we ack this chunk, the transfer is done. + if(getDevice().isBusy() && bytesTransferred==0) { + unsetBusy(); + } } catch (IOException ex) { LOG.error("Unable to send ack to MI", ex); }