gpt4 book ai didi

Java/开发/输入/事件X

转载 作者:太空宇宙 更新时间:2023-11-04 10:54:29 26 4
gpt4 key购买 nike

目前我有一个 N-Trig Multitouch 面板连接到事件文件/dev/input/event4,我正在尝试 this访问它。我已经在 java.library.path 中包含了所有本地人等,但即使是 super 用户,我也会收到此错误。异常:

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)

有人知道为什么会这样吗?谢谢

最佳答案

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

by attilapara
Hi, I tried to use this library on a Raspberry Pi and I got the same exception, but I figured out the source of the problem and managed to get it work. Basically, the problem is that this library is written for 64 bit CPU/OS only. Explanation:

The input_event structure looks like this (source):

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

Here we have timeval, which has the following members (source):

time_t         tv_sec      seconds
suseconds_t tv_usec microseconds

These two types are represented differently on a 32 bit and a 64 bit system.

The solution:

  1. Change the size of input_event from 24 to 16 bytes:

change line 34 of the source file evdev-java/src/com/dgis/input/evdev/InputEvent.java from this:

    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;
}

关于Java/开发/输入/事件X,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29377876/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com