mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-06-17 06:11:36 +00:00
Warn on non-evdev devices
This commit is contained in:
@@ -11,12 +11,13 @@ Java_com_limelight_input_IO_ioctl(
|
|||||||
|
|
||||||
jboolean retval;
|
jboolean retval;
|
||||||
int fd;
|
int fd;
|
||||||
|
int ret;
|
||||||
if ((fd = open(jni_filename, O_RDONLY)) < 0) {
|
if ((fd = open(jni_filename, O_RDONLY)) < 0) {
|
||||||
retval = 0;
|
retval = 0;
|
||||||
} else {
|
} else {
|
||||||
ioctl(fd, request, jni_buffer);
|
ret = ioctl(fd, request, jni_buffer);
|
||||||
close(fd);
|
close(fd);
|
||||||
retval = 1;
|
retval = ret > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*env)->ReleaseByteArrayElements(env, buffer, jni_buffer, 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;
|
public final static int UP = 1, DOWN = -1, NONE = 0;
|
||||||
|
|
||||||
private final static int ABS_OFFSET = 0x40;
|
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 avg;
|
||||||
private int range;
|
private int range;
|
||||||
@@ -25,7 +23,7 @@ public class EvdevAbsolute {
|
|||||||
ByteBuffer buffer = ByteBuffer.allocate(6*4);
|
ByteBuffer buffer = ByteBuffer.allocate(6*4);
|
||||||
buffer.order(ByteOrder.nativeOrder());
|
buffer.order(ByteOrder.nativeOrder());
|
||||||
byte[] data = buffer.array();
|
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);
|
IO.ioctl(filename, data, request);
|
||||||
|
|
||||||
buffer.getInt(); //Skip current value
|
buffer.getInt(); //Skip current value
|
||||||
@@ -39,10 +37,6 @@ public class EvdevAbsolute {
|
|||||||
this.reverse = reverse;
|
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
|
* Convert input value to short range
|
||||||
* @param value received input
|
* @param value received input
|
||||||
|
|||||||
@@ -183,4 +183,7 @@ public class EvdevConstants {
|
|||||||
/* Events */
|
/* Events */
|
||||||
public static final int KEY_RELEASED = 0;
|
public static final int KEY_RELEASED = 0;
|
||||||
public static final int KEY_PRESSED = 1;
|
public static final int KEY_PRESSED = 1;
|
||||||
|
|
||||||
|
/* ioctl */
|
||||||
|
public final static char EVDEV_TYPE = 'E';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import java.nio.channels.FileChannel;
|
|||||||
|
|
||||||
public abstract class EvdevReader implements Runnable {
|
public abstract class EvdevReader implements Runnable {
|
||||||
|
|
||||||
|
private final static int EVIOCGNAME = 0x06;
|
||||||
|
|
||||||
private FileChannel deviceInput;
|
private FileChannel deviceInput;
|
||||||
private ByteBuffer inputBuffer;
|
private ByteBuffer inputBuffer;
|
||||||
|
|
||||||
@@ -21,6 +23,13 @@ public abstract class EvdevReader implements Runnable {
|
|||||||
if (!file.canRead())
|
if (!file.canRead())
|
||||||
throw new IOException("Can't read from " + device);
|
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);
|
FileInputStream in = new FileInputStream(file);
|
||||||
deviceInput = in.getChannel();
|
deviceInput = in.getChannel();
|
||||||
inputBuffer = ByteBuffer.allocate(EvdevConstants.MAX_STRUCT_SIZE_BYTES);
|
inputBuffer = ByteBuffer.allocate(EvdevConstants.MAX_STRUCT_SIZE_BYTES);
|
||||||
|
|||||||
@@ -5,10 +5,17 @@ package com.limelight.input;
|
|||||||
* @author Iwan Timmer
|
* @author Iwan Timmer
|
||||||
*/
|
*/
|
||||||
public class IO {
|
public class IO {
|
||||||
|
|
||||||
|
public final static int READ_ONLY = 2;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("nv_io");
|
System.loadLibrary("nv_io");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static native boolean ioctl(String filename, byte[] buffer, int request);
|
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