Java / dev / input / eventX

时间:2015-03-31 20:24:30

标签: java linux events hid

目前我有一个N-Trig Multitouch面板挂钩到事件文件/ dev / input / event4,我正在尝试this来访问它。我已经在java.library.path中包含了所有本机等,但即使在超级用户时也会收到此错误。例外:

java.io.IOException: Invalid argument
    at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
    at sun.nio.ch.FileDispatcherImpl.read(FileDispatcherImpl.java:46)
    at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
    at sun.nio.ch.IOUtil.read(IOUtil.java:197)
    at sun.nio.ch.FileChannelImpl.read(FileChannelImpl.java:149)
    at com.dgis.input.evdev.EventDevice.readEvent(EventDevice.java:269)
    at com.dgis.input.evdev.EventDevice.access$1(EventDevice.java:265)
    at com.dgis.input.evdev.EventDevice$1.run(EventDevice.java:200)
EVENT:  null
Exception in thread "Thread-0" java.lang.NullPointerException
    at com.asdev.t3.Bootstrap$1.event(Bootstrap.java:41)
    at com.dgis.input.evdev.EventDevice.distributeEvent(EventDevice.java:256)
    at com.dgis.input.evdev.EventDevice.access$2(EventDevice.java:253)
    at com.dgis.input.evdev.EventDevice$1.run(EventDevice.java:201)

有谁知道为什么会这样?感谢

1 个答案:

答案 0 :(得分:1)

我在项目issues page上回答了这个问题。

  

by attilapara
  嗨,我试图在Raspberry Pi上使用这个库,我也一样   例外,但我找出问题的根源并设法   让它工作。基本上,问题是这个库是   仅针对64位CPU / OS编写。说明:

     

input_event结构如下所示(来源):

struct input_event {
    struct timeval time;
    unsigned short type;
    unsigned short code;
    unsigned int value;
};
     

这里我们有timeval,它有以下成员(来源):

time_t         tv_sec      seconds
suseconds_t    tv_usec     microseconds
     

这两种类型在32位和64位上的表示方式不同   系统

     

解决方案:

     
      
  1. 将input_event的大小从24更改为16字节:
  2.         

    更改源文件的第34行   evdev-java / src / com / dgis / input / evdev / InputEvent.java来自:

        public static final int STRUCT_SIZE_BYTES = 24; to this:
    
        public static final int STRUCT_SIZE_BYTES = 16; Change the parse function in the same source file as follows:
    
    public static InputEvent parse(ShortBuffer shortBuffer, String source) throws IOException {
        InputEvent e = new InputEvent();
        short a,b,c,d;
    
        a=shortBuffer.get();
        b=shortBuffer.get();
        //c=shortBuffer.get();
        //d=shortBuffer.get();
        e.time_sec = (b<<16) | a; //(d<<48) | (c<<32) | (b<<16) | a;
        a=shortBuffer.get();
        b=shortBuffer.get();
        //c=shortBuffer.get();
        //d=shortBuffer.get();
        e.time_usec = (b<<16) | a; //(d<<48) | (c<<32) | (b<<16) | a;
        e.type = shortBuffer.get();
        e.code = shortBuffer.get();
        c=shortBuffer.get();
        d=shortBuffer.get();
        e.value = (d<<16) | c;
        e.source = source;
    
        return e;
    }