mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-03 06:26:04 +00:00
Warn on non-evdev devices
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user