Search in sources :

Example 1 with DeviceDef

use of com.chimeraiot.android.ble.sensor.DeviceDef in project BleSensorTag by StevenRudenko.

the class DeviceServicesActivity method displayGattServices.

private void displayGattServices(List<BluetoothGattService> gattServices) {
    if (gattServices == null) {
        return;
    }
    final DeviceDef def = getBleManager().getDeviceDefCollection().get(getDeviceName(), getDeviceAddress());
    gattServiceAdapter = new BleServicesAdapter(this, gattServices, def);
    gattServiceAdapter.setServiceListener(this);
    gattServicesList.setAdapter(gattServiceAdapter);
}
Also used : BleServicesAdapter(sample.ble.sensortag.ui.adapters.BleServicesAdapter) DeviceDef(com.chimeraiot.android.ble.sensor.DeviceDef)

Example 2 with DeviceDef

use of com.chimeraiot.android.ble.sensor.DeviceDef in project BleSensorTag by StevenRudenko.

the class DeviceServicesActivity method onChildClick.

@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
    if (gattServiceAdapter == null) {
        return false;
    }
    final BluetoothGattCharacteristic characteristic = gattServiceAdapter.getChild(groupPosition, childPosition);
    final DeviceDef def = getBleManager().getDeviceDefCollection().get(getDeviceName(), getDeviceAddress());
    if (def == null) {
        return false;
    }
    final Sensor<?> sensor = (Sensor<?>) def.getSensor(characteristic.getService().getUuid().toString());
    if (sensor == null) {
        return true;
    }
    if (sensor == activeSensor) {
        return true;
    }
    final String address = getDeviceAddress();
    if (sensor instanceof BaseSensor) {
        final BaseSensor<?> baseSensor = (BaseSensor<?>) sensor;
        if (activeSensor != null) {
            activeSensor.setEnabled(false);
            getBleManager().update(address, activeSensor, activeSensor.getConfigUUID(), null);
        }
        activeSensor = baseSensor;
        baseSensor.setEnabled(true);
        getBleManager().update(address, sensor, baseSensor.getConfigUUID(), null);
        getBleManager().listen(address, sensor, baseSensor.getDataUUID());
    } else {
        getBleManager().read(address, sensor, characteristic.getUuid().toString());
    }
    return true;
}
Also used : BaseSensor(sample.ble.sensortag.sensor.BaseSensor) BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic) DeviceDef(com.chimeraiot.android.ble.sensor.DeviceDef) TiPeriodicalSensor(sample.ble.sensortag.sensor.ti.TiPeriodicalSensor) Sensor(com.chimeraiot.android.ble.sensor.Sensor) BaseSensor(sample.ble.sensortag.sensor.BaseSensor)

Aggregations

DeviceDef (com.chimeraiot.android.ble.sensor.DeviceDef)2 BluetoothGattCharacteristic (android.bluetooth.BluetoothGattCharacteristic)1 Sensor (com.chimeraiot.android.ble.sensor.Sensor)1 BaseSensor (sample.ble.sensortag.sensor.BaseSensor)1 TiPeriodicalSensor (sample.ble.sensortag.sensor.ti.TiPeriodicalSensor)1 BleServicesAdapter (sample.ble.sensortag.ui.adapters.BleServicesAdapter)1