Skip to content
This repository has been archived by the owner on Aug 8, 2021. It is now read-only.

Commit

Permalink
Restore old LE params after write.
Browse files Browse the repository at this point in the history
  • Loading branch information
lwis committed Jan 2, 2015
1 parent 6f50a66 commit f76cee8
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/main/java/com/lewisjuggins/miband/BLECommunicationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.content.Context;
import android.util.Log;
import com.lewisjuggins.miband.bluetooth.AsyncBluetoothGatt;
import org.jdeferred.DoneCallback;

import java.util.Set;
import java.util.UUID;
Expand Down Expand Up @@ -48,6 +49,8 @@ public class BLECommunicationManager
advInt: 1500ms
*/

public byte[] mCurrentLeParams;

public static final byte[] mLowLatencyLeParams = new byte[]{0x27, 0x00, 0x31, 0x00, 0x00, 0x00, (byte)0xf4, 0x01, 0x00, 0x00, 0x00, 0x00};

public static final byte[] mHighLatencyLeParams = new byte[]{(byte)0xcc, 0x01, (byte)0xf4, 0x01, 0x00, 0x00, (byte)0xf4, 0x01, 0x00, 0x00, 0x00, 0x00};
Expand Down Expand Up @@ -134,6 +137,14 @@ public synchronized void connectGatt()
{
mGatt.connect().waitSafely(10000);
mGatt.discoverServices().waitSafely(10000);
mGatt.readCharacteristic(getCharacteristic(MiBandConstants.UUID_CHARACTERISTIC_LE_PARAMS)).done(new DoneCallback<BluetoothGattCharacteristic>()
{
@Override public void onDone(final BluetoothGattCharacteristic result)
{
mCurrentLeParams = result.getValue();
Log.i(TAG, "Read LE Params");
}
}).waitSafely();
setLowLatency();
}
catch(InterruptedException e)
Expand All @@ -149,9 +160,18 @@ public synchronized void disconnectGatt()
{
if(mGatt != null)
{
//setMediumLatency();
mGatt.disconnect();
mGatt.close();
try
{
final BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandConstants.UUID_CHARACTERISTIC_LE_PARAMS);
characteristic.setValue(mCurrentLeParams);
mGatt.writeCharacteristic(characteristic).waitSafely();
mGatt.disconnect();
mGatt.close();
}
catch(InterruptedException e)
{
Log.d(TAG, "Failed to disconnect");
}
}
}

Expand Down Expand Up @@ -183,21 +203,6 @@ public void setLowLatency()
}
}

public void setHighLatency()
{
try
{
final BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandConstants.UUID_CHARACTERISTIC_LE_PARAMS);
characteristic.setValue(mHighLatencyLeParams);
mGatt.writeCharacteristic(characteristic).waitSafely();
}
catch(InterruptedException e)
{
Log.i(TAG, e.toString());
setLowLatency();
}
}

private BluetoothGattService getMiliService()
{
return mGatt.getService(MiBandConstants.UUID_SERVICE_MILI_SERVICE);
Expand Down

0 comments on commit f76cee8

Please sign in to comment.