Hardware Reference
In-Depth Information
Log . d ( LOGTAG , "Val: " + b );
}
}
Once the sensor's data is acquired, a few steps are still needed to process the data. The
code for the data processing of each sensor can be found in the SensorTag example
Android library or in the SensorTag Online User Guide .
You can copy/paste the processing algorithm for the accelerometer into the previous
code snippet, usually in the ACC_READ state part of the decoder. The same goes for the
data processing for all the other sensors.
Polling the remote sensor is one way to periodically extract data from it, but it's not
power efficient for both devices. The remote device needs to stay on constantly to catch
the read requests and the phone needs to stay awake to send the polling requests. A
more efficient way to do things is to have the device send notifications (thoroughly
described in “Server-Initiated Updates” on page 72 ) instead. You can set the period for
the notifications manually for some of the sensors.
Application Accelerator has a special method for enabling notifications. To enable no‐
tifications on Android, you normally have to locally enable the notification for the
particular characteristic you are interested in.
Once that's done, you also have to enable notifications on the peer device by writing to
the device's client characteristic configuration descriptor (CCCD), as described in “Cli‐
ent Characteristic Configuration Descriptor” on page 62 . Luckily, this is abstracted out
and both operations can be handled by a single method call.
The following code enables notifications for the accelerometer when the test button is
pushed:
private void testButton ()
{
BluetoothGatt gatt ;
BluetoothGattCharacteristic c ;
if (! mBleWrapper . isConnected ()) {
return ;
}
// set notification on characteristic
Log . d ( LOGTAG , "Setting notification" );
gatt = mBleWrapper . getGatt ();
c = gatt . getService ( UUID_IRT_SERV ). getCharacteristic ( UUID_IRT_DATA );
mBleWrapper . setNotificationForCharacteristic ( c , true );
mState = ACC_NOTIFy_ENB ;
}
One issue to look out for in the Application Accelerator is it doesn't implement the
onDescriptorWrite() callback available in the Android Bluetooth library. The most
Search WWH ::




Custom Search