Note that there are some explanatory texts on larger screens.

plurals
  1. POaccess (faster polling) accelerometer via NativeActivity NDK
    primarykey
    data
    text
    <p>I've searched for a tutorial/an answer on polling accelerometer faster with NDK but didnt find solver yet. just found an androiddevelopers documentation <a href="http://developer.android.com/reference/android/app/NativeActivity.html" rel="noreferrer">here</a>.</p> <p>what i need is polling acceleration about 100 samples per second (100Hz), by default my device (Samsung Galaxy SL i9003 with gingerbread 2.3.5) with default SENSOR_DELAY_FASTEST can only get about 60 samples persecond (60Hz). Therefore i tried to access sensor via NativeActivity with NDK by generating .c files that i try to make based on sensor.h and looper.h:</p> <pre><code>#include &lt;jni.h&gt; #include &lt;string.h&gt; #include &lt;android/sensor.h&gt; #include &lt;android/log.h&gt; #include &lt;android/looper.h&gt; #define TAG "accelerondk" #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__) #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__) #define LOOPER_ID 1 #define SAMP_PER_SEC 100 //i've changed to 120, even 10, but nothing happen void Java_azka_web_ndk_AcceleroNDKActivity_startMonitoring(JNIEnv* env, jclass clazz) { ASensorManager* sensorManager = ASensorManager_getInstance(); ALooper* looper = ALooper_forThread(); if(looper == NULL) looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); ASensorRef accelerometerSensor = ASensorManager_getDefaultSensor(sensorManager,ASENSOR_TYPE_ACCELEROMETER); LOGI("accelerometerSensor: %s, vendor: %s", ASensor_getName(accelerometerSensor), ASensor_getVendor(accelerometerSensor)); ASensorEventQueue* queue = ASensorManager_createEventQueue(sensorManager, looper, LOOPER_ID, NULL, NULL); ASensorEventQueue_enableSensor(queue, accelerometerSensor); ASensorEventQueue_setEventRate(queue, accelerometerSensor, (1000L/SAMP_PER_SEC)*1000); int ident;//identifier int events; while (1) { while ((ident=ALooper_pollAll(-1, NULL, &amp;events, NULL) &gt;= 0)) { // If a sensor has data, process it now. if (ident == LOOPER_ID) { ASensorEvent event; while (ASensorEventQueue_getEvents(queue, &amp;event, 1) &gt; 0) { LOGI("aaaaaaa accelerometer X = %f y = %f z=%f ", event.acceleration.x, event.acceleration.y, event.acceleration.z); } } } } } </code></pre> <p>so far, i've been able to access accelerometer with NativeActivity, but there is no change with number sample had taken. even when i change ASensorEventQueue_setEventRate big enough or small enough the acceleration recorded still about 60 samples per second (1 samples per 15 milisec)</p> <p>is there any mistakes in my code? or something that i forget with?</p> <p>thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload