2013-12-22 5 views
0

Я работаю над приложением для Android, которое подключается к CC2541. Я могу видеть все услуги и характеристики этих услуг. Я хочу использовать Charertistic Alert Level для Immediate Alert Service. Последний шаг моего приложения заключается в том, что когда я нажимаю на уровень предупреждения charc. Зуммер должен звучать, но я не могу этого сделать. Вот мой код:спецификация уровня предупреждения о предупреждении о побочных действиях

public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) 
{ 
    if (mBluetoothAdapter == null || mBluetoothGatt == null) 
    { 
     Log.w(TAG, "BluetoothAdapter not initialized"); 
     return; 
    } 
    mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); 

    // This is specific to Alert Level. 
    if (UUID_ALERT_LEVEL.equals(characteristic.getUuid())) 
    { 
     characteristic.setValue("0x0028".getBytes()); 
     mBluetoothGatt.writeCharacteristic(characteristic); 
     /* BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); 
     descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); 
     mBluetoothGatt.writeDescriptor(descriptor);*/ 
    } 
} 

Я не уверен использовать writeCharacteristic() или writeDescriptior() для достижения этой цели. Буду признателен за любую помощь.

http://imgur.com/OEs2s8z

ответ

0

меня примерить CC2541, он может сделать звуковой сигнал зуммера, когда я называю writeAlertLevel и дать ему alert level.

Например, alert level является ALERT_HIGH.

private static final int ALERT_HIGH = 2; 
private static final UUID IMMEDIATE_ALERT_UUID = UUID.fromString("00001802-0000-1000-8000-00805f9b34fb"); 
private static final UUID ALERT_LEVEL_UUID = UUID.fromString("00002a06-0000-1000-8000-00805f9b34fb"); 

public void writeAlertLevel(int level) { 
BluetoothGattService alertService = mBluetoothGatt.getService(IMMEDIATE_ALERT_UUID); 
if(alertService == null) { 
Log.d(TAG, "Immediate Alert service not found!"); 
return; 
} 
BluetoothGattCharacteristic alertLevel = alertService.getCharacteristic(ALERT_LEVEL_UUID); 
if(alertLevel == null) { 
Log.d(TAG, "Alert Level charateristic not found!"); 
return; 
} 
alertLevel.setValue(level, BluetoothGattCharacteristic.FORMAT_UINT8, 0); 
mBluetoothGatt.writeCharacteristic(alertLevel); 
} 
Смежные вопросы