use of tinyb.BluetoothGattDescriptor in project smarthome by eclipse.
the class BlueZBluetoothDevice method enableNotifications.
@Override
public boolean enableNotifications(BluetoothDescriptor descriptor) {
if (device == null || !device.getConnected()) {
throw new IllegalStateException("TinyB device is not set or not connected");
}
BluetoothGattDescriptor d = getTinybDescriptorByUUID(descriptor.getUuid().toString());
if (d != null) {
d.enableValueNotifications(value -> {
logger.debug("Received new value '{}' for descriptor '{}' of device '{}'", value, descriptor.getUuid(), address);
descriptor.setValue(value);
notifyListeners(BluetoothEventType.DESCRIPTOR_UPDATED, descriptor);
});
return true;
} else {
logger.warn("Descriptor '{}' is missing on device '{}'.", descriptor.getUuid(), address);
return false;
}
}
use of tinyb.BluetoothGattDescriptor in project smarthome by eclipse.
the class BlueZBluetoothDevice method refreshServices.
protected void refreshServices() {
if (device.getServices().size() > getServices().size()) {
for (BluetoothGattService tinybService : device.getServices()) {
BluetoothService service = new BluetoothService(UUID.fromString(tinybService.getUUID()), tinybService.getPrimary());
for (BluetoothGattCharacteristic tinybCharacteristic : tinybService.getCharacteristics()) {
BluetoothCharacteristic characteristic = new BluetoothCharacteristic(UUID.fromString(tinybCharacteristic.getUUID()), 0);
for (BluetoothGattDescriptor tinybDescriptor : tinybCharacteristic.getDescriptors()) {
BluetoothDescriptor descriptor = new BluetoothDescriptor(characteristic, UUID.fromString(tinybDescriptor.getUUID()));
characteristic.addDescriptor(descriptor);
}
service.addCharacteristic(characteristic);
}
addService(service);
}
notifyListeners(BluetoothEventType.SERVICES_DISCOVERED);
}
}
Aggregations