Warn on non-evdev devices

This commit is contained in:
Iwan Timmer
2014-10-25 17:07:18 +02:00
parent 597b4a48db
commit 8f27977374
6 changed files with 24 additions and 10 deletions

View File

@@ -11,12 +11,13 @@ Java_com_limelight_input_IO_ioctl(
jboolean retval;
int fd;
int ret;
if ((fd = open(jni_filename, O_RDONLY)) < 0) {
retval = 0;
} else {
ioctl(fd, request, jni_buffer);
ret = ioctl(fd, request, jni_buffer);
close(fd);
retval = 1;
retval = ret > 0;
}
(*env)->ReleaseByteArrayElements(env, buffer, jni_buffer, 0);

View File

@@ -12,8 +12,6 @@ public class EvdevAbsolute {
public final static int UP = 1, DOWN = -1, NONE = 0;
private final static int ABS_OFFSET = 0x40;
private final static int READ_ONLY = 2;
private final static char EVDEV_TYPE = 'E';
private int avg;
private int range;
@@ -25,7 +23,7 @@ public class EvdevAbsolute {
ByteBuffer buffer = ByteBuffer.allocate(6*4);
buffer.order(ByteOrder.nativeOrder());
byte[] data = buffer.array();
int request = getRequest(READ_ONLY, EVDEV_TYPE, ABS_OFFSET+axis, 6*4);
int request = IO.getRequest(IO.READ_ONLY, EvdevConstants.EVDEV_TYPE, ABS_OFFSET+axis, 6*4);
IO.ioctl(filename, data, request);
buffer.getInt(); //Skip current value
@@ -39,10 +37,6 @@ public class EvdevAbsolute {
this.reverse = reverse;
}
private int getRequest(int dir, int type, int nr, int size) {
return (dir << 30) | (size << 16) | (type << 8) | nr;
}
/**
* Convert input value to short range
* @param value received input

View File

@@ -183,4 +183,7 @@ public class EvdevConstants {
/* Events */
public static final int KEY_RELEASED = 0;
public static final int KEY_PRESSED = 1;
/* ioctl */
public final static char EVDEV_TYPE = 'E';
}

View File

@@ -18,7 +18,7 @@ public class EvdevHandler extends EvdevReader {
/* GFE's prefix for every key code */
public static final short KEY_PREFIX = (short) 0x80;
/* Gamepad state */
private short buttonFlags;
private byte leftTrigger, rightTrigger;

View File

@@ -11,6 +11,8 @@ import java.nio.channels.FileChannel;
public abstract class EvdevReader implements Runnable {
private final static int EVIOCGNAME = 0x06;
private FileChannel deviceInput;
private ByteBuffer inputBuffer;
@@ -20,6 +22,13 @@ public abstract class EvdevReader implements Runnable {
throw new FileNotFoundException("File " + device + " not found");
if (!file.canRead())
throw new IOException("Can't read from " + device);
byte[] data = new byte[255];
int request = IO.getRequest(IO.READ_ONLY, EvdevConstants.EVDEV_TYPE, EVIOCGNAME, data.length-1);
if (!IO.ioctl(device, data, request))
throw new IOException("Path " + device + " is not a evdev device");
LimeLog.info("Using " + new String(data));
FileInputStream in = new FileInputStream(file);
deviceInput = in.getChannel();

View File

@@ -5,10 +5,17 @@ package com.limelight.input;
* @author Iwan Timmer
*/
public class IO {
public final static int READ_ONLY = 2;
static {
System.loadLibrary("nv_io");
}
public static native boolean ioctl(String filename, byte[] buffer, int request);
public static int getRequest(int dir, int type, int nr, int size) {
return (dir << 30) | (size << 16) | (type << 8) | nr;
}
}