Store accelerometer readings in a buffer

  1. Import the following classes:
    • net.rim.device.api.system.AccelerometerChannelConfig;
    • net.rim.device.api.system.AccelerometerSensor.Channel;
  2. Create a configuration for a channel to the accelerometer.
    AccelerometerChannelConfig channelConfig = new AccelerometerChannelConfig( AccelerometerChannelConfig.TYPE_RAW );
  3. Invoke AccelerometerChannelConfig.setSamplesCount(), to specify the number of acceleration readings to store in the buffer. Each element in the buffer contains acceleration readings for the x, y, and z axes and data on when the reading took place.
    channelConfig.setSamplesCount( 500 );
  4. Invoke AccelerometerSensor.openChannel() to open a channel to the accelerometer.
    Channel bufferedChannel = AccelerometerSensor.openChannel( Application.getApplication(), channelConfig );

Was this information helpful? Send us your comments.