steckl
unread,May 7, 2012, 5:07:55 PM5/7/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to android-ndk
Hi,
I'm writing an app, that should read out sensor values as fast as
possible. For this I use a native activity. But it's not faster than
doing the same from SDK. For the magnetic sensor I get a sample rate
of about 100Hz, that's good enough, but for the Acc-Sensor the sample
rate is only about 50Hz. Can this sample rate be improved somehow?
Here is the Code I used:
void Java_de_tum_ndktest_TestJNIActivity_sensorValue( JNIEnv* env,
jobject thiz ) {
ASensorEvent event;
int events, ident;
ASensorManager* sensorManager;
const ASensor* accSensor;
void* sensor_data = malloc(1000);
ALooper* looper = ALooper_forThread();
if(looper == NULL)
{
looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
}
sensorManager = ASensorManager_getInstance();
accSensor = ASensorManager_getDefaultSensor(sensorManager,
ASENSOR_TYPE_ACCELEROMETER);
sensorEventQueue = ASensorManager_createEventQueue(sensorManager,
looper, 3, get_sensor_events, sensor_data);
ASensorEventQueue_enableSensor(sensorEventQueue, accSensor);
int a = ASensor_getMinDelay(accSensor);
ASensorEventQueue_setEventRate(sensorEventQueue, accSensor, a);
LOGI("sensorValue() - START");
}
static int get_sensor_events(int fd, int events, void* data) {
ASensorEvent event;
//ASensorEventQueue* sensorEventQueue;
while (ASensorEventQueue_getEvents(sensorEventQueue, &event, 1) > 0)
{
if(event.type == ASENSOR_TYPE_ACCELEROMETER) {
if(SensorSamplingRate == 0)
{
LOGI("Time1 of SensorValue %lld", event.timestamp);
}
if(SensorSamplingRate == 1000)
{
LOGI("Time2 of SensorValue %lld", event.timestamp);
}
SensorSamplingRate++;
}
}
//should return 1 to continue receiving callbacks, or 0 to
unregister
return 1;
}