#15 update device state to INITIALIZED when user info was sent

master
cpfeiffer 2015-04-19 15:11:50 +02:00
parent 0e34a449ca
commit 24c3903eef
1 changed files with 15 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import java.io.IOException;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBCommand;
import nodomain.freeyourgadget.gadgetbridge.GBDevice.State;
import nodomain.freeyourgadget.gadgetbridge.btle.AbstractBTLEDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.btle.TransactionBuilder;
@ -168,9 +169,23 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
UUID characteristicUUID = characteristic.getUuid();
if (MiBandService.UUID_CHARACTERISTIC_PAIR.equals(characteristicUUID)) {
handlePairResult(characteristic.getValue(), status);
} else if (MiBandService.UUID_CHARACTERISTIC_USER_INFO.equals(characteristicUUID)) {
handleUserInfoResult(characteristic.getValue(), status);
}
}
private void handleUserInfoResult(byte[] value, int status) {
// successfully transfered user info means we're initialized
if (status == BluetoothGatt.GATT_SUCCESS) {
setConnectionState(State.INITIALIZED);
}
}
private void setConnectionState(State newState) {
getDevice().setState(newState);
getDevice().sendDeviceUpdateIntent(getContext());
}
private void handlePairResult(byte[] pairResult, int status) {
if (status != BluetoothGatt.GATT_SUCCESS) {
Log.i(TAG, "Pairing MI device failed: " + status);