This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tried my best but could not enable Accelerometer in Android on Keyfob CC2541 Mini Kit
final static public UUID ACC_NOTFIY = UUID.fromString("0000ffa1-0000-1000-8000-00805f9b34fb");
final static public UUID ACC_ENABLEX = UUID.fromString("0000ffa3-0000-1000-8000-00805f9b34fb");
if(ch.getUuid().compareTo(BleDefinedUUIDs.Characteristic.ACC_NOTFIY) == 0) {
Log.i(TAG, "Characterstic:" + "ACC_NOTFIY found");
setCharacteristicNotification(ch, enable);
waitIdle(GATT_TIMEOUT);
}
if(ch.getUuid().compareTo(BleDefinedUUIDs.Characteristic.ACC_ENABLEX) == 0) {
Log.i(TAG, "Characterstic:" + "ACC_ENABLEX found");
setCharacteristicNotification(ch, enable);
waitIdle(GATT_TIMEOUT);
}
Anybody can you please look at the code and let me know what I may be doing incorrect:
I am not able to turn Accelerometer on CC2541 keyfob using Android. I appreciate your help:
private static final UUID ACCEL_SERVICE_UUID = UUID.fromString("0000FFA0-0000-1000-8000-00805f9b34fb"); private static final UUID ACCEL_ENABLE_UUID = UUID.fromString("0000FFA1-0000-1000-8000-00805f9b34fb"); private static final UUID X_ENABLE_UUID = UUID.fromString("0000FFA3-0000-1000-8000-00805f9b34fb"); private static final UUID X_ENABLE_UUID_DESC = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"); public void EnableAccel(boolean enable) { BluetoothGattService keyService = mBluetoothGatt.getService(ACCEL_SERVICE_UUID); if(keyService == null) { Log.d(TAG, "Acceleration service not found!"); return; } BluetoothGattCharacteristic enableAcceleration = keyService.getCharacteristic(ACCEL_ENABLE_UUID); if(enableAcceleration == null) { Log.d(TAG, "Acceleration Enable charateristic not found!"); return; } setCharacteristicNotification(enableAcceleration, enable); BluetoothGattCharacteristic enableX = keyService.getCharacteristic(X_ENABLE_UUID); if(enableX == null) { Log.e(TAG, "Enable X charateristic not found!"); } else { BluetoothGattDescriptor gatDesc = enableX.getDescriptor(X_ENABLE_UUID_DESC); if(gatDesc == null) { Log.e(TAG, "Enable X BluetoothGattDescriptor not found!"); return; } setDescriptorNotification(gatDesc, enable); } }
public void setDescriptorNotification(BluetoothGattDescriptor descriptor, boolean enabled) { Log.i(TAG, "setDescriptorNotification " + descriptor.getUuid().toString()); byte[] val = enabled ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE; descriptor.setValue(val); mBluetoothGatt.writeDescriptor(descriptor); }