Reputation: 950
currently I have an N-Trig Multitouch panel hooked to the event file /dev/input/event4, and I am trying this to access it. I have included all of the natives and such in the java.library.path but am getting this error even when superuser. The exception:
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)
Does anyone know why this happens? Thanks
Upvotes: 1
Views: 1422
Reputation: 41
I answered this question on the project's 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:
- 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; }
Upvotes: 4