2014-03-06 23 views
1

我需要處理來自加速度傳感器和我的本機庫中的硬件的事件。 我實現了傳感器和正常工作:在本機庫中使用AInputQueue_attachLooper()

looper = ALooper_forThread(); 
if (looper == NULL) 
    looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); 

sensorManager = ASensorManager_getInstance(); 
accSensor = ASensorManager_getDefaultSensor(sensorManager, 
     ASENSOR_TYPE_ACCELEROMETER); 
if (accSensor == NULL) 
    LOGE("get Default Sensor"); 

sensorEventQueue = ASensorManager_createEventQueue(sensorManager, looper, 
LOOPER_ID, get_sensor_events, NULL); 

if (ASensorEventQueue_enableSensor(sensorEventQueue, accSensor) < 0) 
    LOGE("Enable sensor"); 

ASensorEventQueue_setEventRate(sensorEventQueue, accSensor, 
     (1000L/SAMP_PER_SEC) * 1000); 

不過,對於硬鍵我缺少一個InputQueue做同樣的伎倆:

looper = ALooper_forThread(); 
if (looper == NULL) 
    looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); 
AInputQueue_attachLooper(inputQueue, looper, LOOPER_ID, get_input_events, NULL); 

一個解決辦法是閱讀事件文件直接在我的案例/dev/input/event3,但我沒有正確的權限。我可以更改init.rc文件中的權限,但由於事件編號可能發生變化,我認爲這不是正確的解決方案。我找不到內核驅動程序創建輸入設備時設置權限的方法。

有什麼建議嗎?

回答

0

在本地的活動,你可能想實現onInputQueueCreated回調:

static void OnInputQueueCreated (ANativeActivity* activity, AInputQueue* queue) 

隊列 PARAM將持有的指針,你正在尋找的輸入隊列。