mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-03 23:04:20 +01:00
Minor issues fixed
This commit is contained in:
@@ -10,6 +10,7 @@ import android.support.annotation.NonNull;
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.ble.BleManager;
|
||||
import no.nordicsemi.android.ble.callback.DataCallback;
|
||||
import no.nordicsemi.android.ble.common.callback.battery.BatteryLevelDataCallback;
|
||||
import no.nordicsemi.android.ble.data.Data;
|
||||
import no.nordicsemi.android.log.LogContract;
|
||||
@@ -42,22 +43,24 @@ public abstract class BatteryManager<T extends BatteryManagerCallbacks> extends
|
||||
@Override
|
||||
protected abstract BatteryManagerGattCallback getGattCallback();
|
||||
|
||||
private DataCallback mBatteryLevelDataCallback = new BatteryLevelDataCallback() {
|
||||
@Override
|
||||
public void onBatteryLevelChanged(@NonNull final BluetoothDevice device, final int batteryLevel) {
|
||||
log(LogContract.Log.Level.APPLICATION,"Battery Level received: " + batteryLevel + "%");
|
||||
mBatteryLevel = batteryLevel;
|
||||
mCallbacks.onBatteryLevelChanged(device, batteryLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInvalidDataReceived(@NonNull final BluetoothDevice device, final @NonNull Data data) {
|
||||
log(LogContract.Log.Level.WARNING, "Invalid Battery Level data received: " + data);
|
||||
}
|
||||
};
|
||||
|
||||
public void readBatteryLevelCharacteristic() {
|
||||
if (isConnected()) {
|
||||
readCharacteristic(mBatteryLevelCharacteristic)
|
||||
.with(new BatteryLevelDataCallback() {
|
||||
@Override
|
||||
public void onBatteryLevelChanged(@NonNull final BluetoothDevice device, final int batteryLevel) {
|
||||
log(LogContract.Log.Level.APPLICATION,"Battery Level received: " + batteryLevel + "%");
|
||||
mBatteryLevel = batteryLevel;
|
||||
mCallbacks.onBatteryLevelChanged(device, batteryLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInvalidDataReceived(@NonNull final BluetoothDevice device, final @NonNull Data data) {
|
||||
log(LogContract.Log.Level.WARNING, "Invalid Battery Level data received: " + data);
|
||||
}
|
||||
})
|
||||
.with(mBatteryLevelDataCallback)
|
||||
.fail(status -> log(LogContract.Log.Level.WARNING, "Battery Level characteristic not found"));
|
||||
}
|
||||
}
|
||||
@@ -66,18 +69,7 @@ public abstract class BatteryManager<T extends BatteryManagerCallbacks> extends
|
||||
if (isConnected()) {
|
||||
// If the Battery Level characteristic is null, the request will be ignored
|
||||
enableNotifications(mBatteryLevelCharacteristic)
|
||||
.with(new BatteryLevelDataCallback() {
|
||||
@Override
|
||||
public void onBatteryLevelChanged(@NonNull final BluetoothDevice device, final int batteryLevel) {
|
||||
mBatteryLevel = batteryLevel;
|
||||
mCallbacks.onBatteryLevelChanged(device, batteryLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInvalidDataReceived(@NonNull final BluetoothDevice device, final @NonNull Data data) {
|
||||
log(LogContract.Log.Level.WARNING, "Invalid Battery Level data received: " + data);
|
||||
}
|
||||
})
|
||||
.with(mBatteryLevelDataCallback)
|
||||
.done(() -> log(LogContract.Log.Level.INFO, "Battery Level notifications enabled"))
|
||||
.fail(status -> log(LogContract.Log.Level.WARNING, "Battery Level characteristic not found"));
|
||||
}
|
||||
|
||||
@@ -127,11 +127,6 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
switch (requestCode) {
|
||||
case CGM_OP_CODE_START_SESSION:
|
||||
mSessionStartTime = System.currentTimeMillis();
|
||||
log(LogContract.Log.Level.APPLICATION, "Session started");
|
||||
break;
|
||||
case CGM_OP_CODE_STOP_SESSION:
|
||||
mSessionStartTime = 0;
|
||||
log(LogContract.Log.Level.APPLICATION, "Session stopped");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -140,12 +135,8 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
public void onCGMSpecificOpsOperationError(@NonNull final BluetoothDevice device, final int requestCode, final int error, final boolean secured) {
|
||||
switch (requestCode) {
|
||||
case CGM_OP_CODE_START_SESSION:
|
||||
mSessionStartTime = 0;
|
||||
log(LogContract.Log.Level.WARNING, "Session not started, error " + error);
|
||||
break;
|
||||
case CGM_OP_CODE_STOP_SESSION:
|
||||
mSessionStartTime = 0;
|
||||
log(LogContract.Log.Level.APPLICATION, "Session stopped, error " + error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -185,7 +176,8 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
public void onNumberOfRecordsReceived(@NonNull final BluetoothDevice device, final int numberOfRecords) {
|
||||
mCallbacks.onNumberOfRecordsRequested(device, numberOfRecords);
|
||||
if (numberOfRecords > 0) {
|
||||
writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.reportNumberOfAllStoredRecords());
|
||||
final int sequenceNumber = mRecords.keyAt(mRecords.size() - 1) + 1;
|
||||
writeCharacteristic(mRecordAccessControlPointCharacteristic, RecordAccessControlPointData.reportStoredRecordsGreaterThenOrEqualTo(sequenceNumber));
|
||||
} else {
|
||||
mCallbacks.onOperationCompleted(device);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user