2014-05-05 30 views
0

在之前的question中,我問如何解釋來自/ dev/input/mice的事件字節。現在意識到/ dev/input/mice沒有提供我需要的信息,因爲我使用的是使用stmpe-ts驅動程序的觸摸屏。它被設置在EVDEV節點/ dev/input/event2下,並且使用我建立的個人程序,我可以從這個文件中獲得必要的字節。我唯一的問題是將其轉換爲事件代碼。使用evtest,我得到這樣的輸出:從原始字節中獲取EVDEV事件代碼?

Input driver version is 1.0.1 
    Input device ID: bus 0x18 vendor 0x0 product 0x0 version 0x0 
    Input device name: "stmpe-ts" 
    Supported events: 
Event type 0 (EV_SYN) 
Event type 1 (EV_KEY) 
    Event code 330 (BTN_TOUCH) 
Event type 3 (EV_ABS) 
    Event code 0 (ABS_X) 
    Value 2486 
    Min  0 
    Max  4095 
    Event code 1 (ABS_Y) 
    Value 1299 
    Min  0 
    Max  4095 
    Event code 24 (ABS_PRESSURE) 
    Value  0 
    Min  0 
    Max  255 
Properties: 
Testing ... (interrupt to exit) 

我需要那些事件代碼,通過直接從/ dev /輸入/事件2閱讀中獲得的原始數據。這是如下:

236 21 100 83 63 223 11 0 3 0 0 0 124 8 0 0 236 21 100 83 72 223 11 0 3 0 1 0 237 7 
0 0 236 21 100 83 76 223 11 0 3 0 24 0 60 0 0 0 236 21 100 83 80 223 11 0 1 0 74  
1 1 0 0 0 236 21 100 83 84 223 11 0 0 0 0 0 0 0 0 0 236 21 100 83 251 247 11 0 3 0 0 0 
123 8 0 0 236 21 100 83 6 248 11 0 3 0 1 0 242 7 0 0 236 21 100 83 10 248 11 0 3 0 24 
0 142 0 0 0 236 21 100 83 16 248 11 0 0 0 0 0 0 0 0 0 236 21 100 83 137 16 12 0 3 0 0 
0 121 8 0 0 236 21 100 83 147 16 12 0 3 0 1 0 7 8 0 0 236 21 100 83 150 16 12 0 3 0 24 
0 163 0 0 0 236 21 100 83 156 16 12 0 0 0 0 0 0 0 0 0 

這甚至有可能嗎?如果是這樣,有人可以幫我在這裏嗎? (另外,我已經確定每16個字節左右出現一個模式,我還確定236和237是字節,指出事件是觸摸事件,236是觸摸而不點擊,237是點擊觸摸)

+0

不錯的問題。請通過編輯問題來增強此示例數據的必要輸出。祝你好運。 – shellter

+0

謝謝,我現在就那樣做... – Einstein12345

+0

???我的樣本中只看到<15個數字。爲什麼在你的示例輸出中有這麼多。我在樣本輸入的任何地方都看不到'236'。示例輸入 - >示例輸出,對嗎? :-) 祝你好運。 – shellter

回答

1

evdev節點的輸出是在linux/input.h中定義的一系列struct input_event。

struct input_event { 
      struct timeval time; 
      __u16 type; 
      __u16 code; 
      __s32 value; 
    }; 

因此,所有你需要做的是閱讀到這些結構的數組,然後根據需要訪問的每個類型/代碼。不知道如何在Java中這樣做,但可能並不難。

evtest是免費軟件btw,所以你可以看看代碼,看看它做了什麼。 另外看看libevdev,這是MIT的許可證,所以你不會因爲看到它而感到「污染」。 http://www.freedesktop.org/wiki/Software/libevdev/

+0

謝謝!這和JNI結合起來讓我可以運行起來。我只是最終在Java中使用了回調風格的方法,並且每次發生事件時都調用該方法。 – Einstein12345

相關問題