mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2025-12-21 16:34:23 +01:00
Added an option to call BLE requests in synchronous way. Not tested.
This commit is contained in:
@@ -68,8 +68,9 @@ public abstract class BatteryManager<T extends BatteryManagerCallbacks> extends
|
||||
public void enableBatteryLevelCharacteristicNotifications() {
|
||||
if (isConnected()) {
|
||||
// If the Battery Level characteristic is null, the request will be ignored
|
||||
setNotificationCallback(mBatteryLevelCharacteristic)
|
||||
.with(mBatteryLevelDataCallback);
|
||||
enableNotifications(mBatteryLevelCharacteristic)
|
||||
.with(mBatteryLevelDataCallback)
|
||||
.done(device -> log(LogContract.Log.Level.INFO, "Battery Level notifications enabled"))
|
||||
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Battery Level characteristic not found"));
|
||||
}
|
||||
|
||||
@@ -81,31 +81,30 @@ public class BPMManager extends BatteryManager<BPMManagerCallbacks> {
|
||||
protected void initialize() {
|
||||
super.initialize();
|
||||
|
||||
enableNotifications(mICPCharacteristic)
|
||||
setNotificationCallback(mICPCharacteristic)
|
||||
.with(new IntermediateCuffPressureDataCallback() {
|
||||
@Override
|
||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||
log(LogContract.Log.Level.APPLICATION, "\"" + IntermediateCuffPressureParser.parse(data) + "\" received");
|
||||
@Override
|
||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||
log(LogContract.Log.Level.APPLICATION, "\"" + IntermediateCuffPressureParser.parse(data) + "\" received");
|
||||
|
||||
// Pass through received data
|
||||
super.onDataReceived(device, data);
|
||||
}
|
||||
// Pass through received data
|
||||
super.onDataReceived(device, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIntermediateCuffPressureReceived(@NonNull final BluetoothDevice device,
|
||||
final float cuffPressure, final int unit,
|
||||
@Nullable final Float pulseRate, @Nullable final Integer userID,
|
||||
@Nullable final BPMStatus status, @Nullable final Calendar calendar) {
|
||||
mCallbacks.onIntermediateCuffPressureReceived(device, cuffPressure, unit, pulseRate, userID, status, calendar);
|
||||
}
|
||||
@Override
|
||||
public void onIntermediateCuffPressureReceived(@NonNull final BluetoothDevice device,
|
||||
final float cuffPressure, final int unit,
|
||||
@Nullable final Float pulseRate, @Nullable final Integer userID,
|
||||
@Nullable final BPMStatus status, @Nullable final Calendar calendar) {
|
||||
mCallbacks.onIntermediateCuffPressureReceived(device, cuffPressure, unit, pulseRate, userID, status, calendar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInvalidDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||
log(LogContract.Log.Level.WARNING, "Invalid ICP data received: " + data);
|
||||
}
|
||||
});
|
||||
|
||||
enableIndications(mBPMCharacteristic)
|
||||
@Override
|
||||
public void onInvalidDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||
log(LogContract.Log.Level.WARNING, "Invalid ICP data received: " + data);
|
||||
}
|
||||
});
|
||||
setIndicationCallback(mBPMCharacteristic)
|
||||
.with(new BloodPressureMeasurementDataCallback() {
|
||||
@Override
|
||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||
@@ -129,6 +128,9 @@ public class BPMManager extends BatteryManager<BPMManagerCallbacks> {
|
||||
log(LogContract.Log.Level.WARNING, "Invalid BPM data received: " + data);
|
||||
}
|
||||
});
|
||||
|
||||
enableNotifications(mICPCharacteristic);
|
||||
enableIndications(mBPMCharacteristic);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -124,8 +124,8 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
}
|
||||
}).fail((device, status) -> log(LogContract.Log.Level.WARNING, "Could not read CGM Status characteristic"));
|
||||
|
||||
// Enable Continuous Glucose Measurement notifications
|
||||
enableNotifications(mCGMMeasurementCharacteristic)
|
||||
// Set notification and indication callbacks
|
||||
setNotificationCallback(mCGMMeasurementCharacteristic)
|
||||
.with(new ContinuousGlucoseMeasurementDataCallback() {
|
||||
@Override
|
||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||
@@ -153,11 +153,9 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
public void onContinuousGlucoseMeasurementReceivedWithCrcError(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||
log(LogContract.Log.Level.WARNING, "Continuous Glucose Measurement record received with CRC error");
|
||||
}
|
||||
})
|
||||
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Failed to enable Continuous Glucose Measurement notifications (" + status + ")"));
|
||||
});
|
||||
|
||||
// Enable CGM Specific Ops indications
|
||||
enableIndications(mCGMSpecificOpsControlPointCharacteristic)
|
||||
setIndicationCallback(mCGMSpecificOpsControlPointCharacteristic)
|
||||
.with(new CGMSpecificOpsControlPointDataCallback() {
|
||||
@Override
|
||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||
@@ -198,7 +196,7 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
}
|
||||
});
|
||||
|
||||
enableIndications(mRecordAccessControlPointCharacteristic)
|
||||
setIndicationCallback(mRecordAccessControlPointCharacteristic)
|
||||
.with(new RecordAccessControlPointDataCallback() {
|
||||
@Override
|
||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||
@@ -250,7 +248,14 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
||||
mCallbacks.onOperationFailed(device);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// Enable notifications and indications
|
||||
enableNotifications(mCGMMeasurementCharacteristic)
|
||||
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Failed to enable Continuous Glucose Measurement notifications (" + status + ")"));
|
||||
enableIndications(mCGMSpecificOpsControlPointCharacteristic)
|
||||
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Failed to enable CGM Specific Ops Control Point indications notifications (" + status + ")"));
|
||||
enableIndications(mRecordAccessControlPointCharacteristic)
|
||||
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Failed to enabled Record Access Control Point indications (error " + status + ")"));
|
||||
|
||||
// Start Continuous Glucose session if hasn't been started before
|
||||
|
||||
@@ -69,7 +69,7 @@ public class CSCManager extends BatteryManager<CSCManagerCallbacks> {
|
||||
super.initialize();
|
||||
|
||||
// CSC characteristic is required
|
||||
enableNotifications(mCSCMeasurementCharacteristic)
|
||||
setNotificationCallback(mCSCMeasurementCharacteristic)
|
||||
.with(new CyclingSpeedAndCadenceDataCallback() {
|
||||
@Override
|
||||
public void onDataReceived(@NonNull final BluetoothDevice device, final @NonNull Data data) {
|
||||
@@ -99,6 +99,7 @@ public class CSCManager extends BatteryManager<CSCManagerCallbacks> {
|
||||
log(LogContract.Log.Level.WARNING, "Invalid CSC Measurement data received: " + data);
|
||||
}
|
||||
});
|
||||
enableNotifications(mCSCMeasurementCharacteristic);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -112,8 +112,7 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
||||
}
|
||||
device.setCharacteristicNotification(mRecordAccessControlPointCharacteristic, true);
|
||||
*/
|
||||
|
||||
enableNotifications(mGlucoseMeasurementCharacteristic)
|
||||
setNotificationCallback(mGlucoseMeasurementCharacteristic)
|
||||
.with(new GlucoseMeasurementDataCallback() {
|
||||
@Override
|
||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||
@@ -148,7 +147,8 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
||||
});
|
||||
}
|
||||
});
|
||||
enableNotifications(mGlucoseMeasurementContextCharacteristic)
|
||||
|
||||
setNotificationCallback(mGlucoseMeasurementContextCharacteristic)
|
||||
.with(new GlucoseMeasurementContextDataCallback() {
|
||||
@Override
|
||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||
@@ -190,7 +190,7 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
||||
}
|
||||
});
|
||||
|
||||
enableIndications(mRecordAccessControlPointCharacteristic)
|
||||
setIndicationCallback(mRecordAccessControlPointCharacteristic)
|
||||
.with(new RecordAccessControlPointDataCallback() {
|
||||
@Override
|
||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||
@@ -239,7 +239,11 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
||||
mCallbacks.onOperationFailed(device);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
enableNotifications(mGlucoseMeasurementCharacteristic);
|
||||
enableNotifications(mGlucoseMeasurementContextCharacteristic);
|
||||
enableIndications(mRecordAccessControlPointCharacteristic)
|
||||
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Failed to enabled Record Access Control Point indications (error " + status + ")"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user