mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2025-12-22 00:44:26 +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() {
|
public void enableBatteryLevelCharacteristicNotifications() {
|
||||||
if (isConnected()) {
|
if (isConnected()) {
|
||||||
// If the Battery Level characteristic is null, the request will be ignored
|
// If the Battery Level characteristic is null, the request will be ignored
|
||||||
|
setNotificationCallback(mBatteryLevelCharacteristic)
|
||||||
|
.with(mBatteryLevelDataCallback);
|
||||||
enableNotifications(mBatteryLevelCharacteristic)
|
enableNotifications(mBatteryLevelCharacteristic)
|
||||||
.with(mBatteryLevelDataCallback)
|
|
||||||
.done(device -> log(LogContract.Log.Level.INFO, "Battery Level notifications enabled"))
|
.done(device -> log(LogContract.Log.Level.INFO, "Battery Level notifications enabled"))
|
||||||
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Battery Level characteristic not found"));
|
.fail((device, status) -> log(LogContract.Log.Level.WARNING, "Battery Level characteristic not found"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class BPMManager extends BatteryManager<BPMManagerCallbacks> {
|
|||||||
protected void initialize() {
|
protected void initialize() {
|
||||||
super.initialize();
|
super.initialize();
|
||||||
|
|
||||||
enableNotifications(mICPCharacteristic)
|
setNotificationCallback(mICPCharacteristic)
|
||||||
.with(new IntermediateCuffPressureDataCallback() {
|
.with(new IntermediateCuffPressureDataCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||||
@@ -104,8 +104,7 @@ public class BPMManager extends BatteryManager<BPMManagerCallbacks> {
|
|||||||
log(LogContract.Log.Level.WARNING, "Invalid ICP data received: " + data);
|
log(LogContract.Log.Level.WARNING, "Invalid ICP data received: " + data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
setIndicationCallback(mBPMCharacteristic)
|
||||||
enableIndications(mBPMCharacteristic)
|
|
||||||
.with(new BloodPressureMeasurementDataCallback() {
|
.with(new BloodPressureMeasurementDataCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
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);
|
log(LogContract.Log.Level.WARNING, "Invalid BPM data received: " + data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
enableNotifications(mICPCharacteristic);
|
||||||
|
enableIndications(mBPMCharacteristic);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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"));
|
}).fail((device, status) -> log(LogContract.Log.Level.WARNING, "Could not read CGM Status characteristic"));
|
||||||
|
|
||||||
// Enable Continuous Glucose Measurement notifications
|
// Set notification and indication callbacks
|
||||||
enableNotifications(mCGMMeasurementCharacteristic)
|
setNotificationCallback(mCGMMeasurementCharacteristic)
|
||||||
.with(new ContinuousGlucoseMeasurementDataCallback() {
|
.with(new ContinuousGlucoseMeasurementDataCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
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) {
|
public void onContinuousGlucoseMeasurementReceivedWithCrcError(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||||
log(LogContract.Log.Level.WARNING, "Continuous Glucose Measurement record received with CRC error");
|
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
|
setIndicationCallback(mCGMSpecificOpsControlPointCharacteristic)
|
||||||
enableIndications(mCGMSpecificOpsControlPointCharacteristic)
|
|
||||||
.with(new CGMSpecificOpsControlPointDataCallback() {
|
.with(new CGMSpecificOpsControlPointDataCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
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() {
|
.with(new RecordAccessControlPointDataCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||||
@@ -250,7 +248,14 @@ public class CGMSManager extends BatteryManager<CGMSManagerCallbacks> {
|
|||||||
mCallbacks.onOperationFailed(device);
|
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 + ")"));
|
.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
|
// Start Continuous Glucose session if hasn't been started before
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class CSCManager extends BatteryManager<CSCManagerCallbacks> {
|
|||||||
super.initialize();
|
super.initialize();
|
||||||
|
|
||||||
// CSC characteristic is required
|
// CSC characteristic is required
|
||||||
enableNotifications(mCSCMeasurementCharacteristic)
|
setNotificationCallback(mCSCMeasurementCharacteristic)
|
||||||
.with(new CyclingSpeedAndCadenceDataCallback() {
|
.with(new CyclingSpeedAndCadenceDataCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onDataReceived(@NonNull final BluetoothDevice device, final @NonNull Data data) {
|
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);
|
log(LogContract.Log.Level.WARNING, "Invalid CSC Measurement data received: " + data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
enableNotifications(mCSCMeasurementCharacteristic);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -112,8 +112,7 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
|||||||
}
|
}
|
||||||
device.setCharacteristicNotification(mRecordAccessControlPointCharacteristic, true);
|
device.setCharacteristicNotification(mRecordAccessControlPointCharacteristic, true);
|
||||||
*/
|
*/
|
||||||
|
setNotificationCallback(mGlucoseMeasurementCharacteristic)
|
||||||
enableNotifications(mGlucoseMeasurementCharacteristic)
|
|
||||||
.with(new GlucoseMeasurementDataCallback() {
|
.with(new GlucoseMeasurementDataCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
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() {
|
.with(new GlucoseMeasurementContextDataCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
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() {
|
.with(new RecordAccessControlPointDataCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
|
||||||
@@ -239,7 +239,11 @@ public class GlucoseManager extends BatteryManager<GlucoseManagerCallbacks> {
|
|||||||
mCallbacks.onOperationFailed(device);
|
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 + ")"));
|
.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