Search in sources :

Example 1 with BluetoothGattDescriptor

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;
    }
}
Also used : BluetoothGattDescriptor(tinyb.BluetoothGattDescriptor)

Example 2 with BluetoothGattDescriptor

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);
    }
}
Also used : BluetoothDescriptor(org.eclipse.smarthome.binding.bluetooth.BluetoothDescriptor) BluetoothService(org.eclipse.smarthome.binding.bluetooth.BluetoothService) BluetoothCharacteristic(org.eclipse.smarthome.binding.bluetooth.BluetoothCharacteristic) BluetoothGattService(tinyb.BluetoothGattService) BluetoothGattDescriptor(tinyb.BluetoothGattDescriptor) BluetoothGattCharacteristic(tinyb.BluetoothGattCharacteristic)

Aggregations

BluetoothGattDescriptor (tinyb.BluetoothGattDescriptor)2 BluetoothCharacteristic (org.eclipse.smarthome.binding.bluetooth.BluetoothCharacteristic)1 BluetoothDescriptor (org.eclipse.smarthome.binding.bluetooth.BluetoothDescriptor)1 BluetoothService (org.eclipse.smarthome.binding.bluetooth.BluetoothService)1 BluetoothGattCharacteristic (tinyb.BluetoothGattCharacteristic)1 BluetoothGattService (tinyb.BluetoothGattService)1