From 24b201856fe1c7777abd6e7f0f1801e0c86c5c51 Mon Sep 17 00:00:00 2001 From: Iwan Timmer Date: Wed, 19 Mar 2014 19:53:41 +0100 Subject: [PATCH] Revert "Adjusted short and byte scaling and reversal in EvdevAbsolute and accounting for signed and unsigned input" Patch don't take minimum values into account This reverts commit 12efe3b5a39c678d6bfbef732d9c46a4f1ebbf0d. --- src/com/limelight/input/EvdevAbsolute.java | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/com/limelight/input/EvdevAbsolute.java b/src/com/limelight/input/EvdevAbsolute.java index 2c41eb5..5534b6e 100644 --- a/src/com/limelight/input/EvdevAbsolute.java +++ b/src/com/limelight/input/EvdevAbsolute.java @@ -11,18 +11,14 @@ public class EvdevAbsolute { public final static int UP = 1, DOWN = -1, NONE = 0; - private static final int SHORT_MAX_UNSIGNED = 0xFFFF; - private static final int BYTE_MAX_UNSIGNED = 0xFF; private final static int ABS_OFFSET = 0x40; private final static int READ_ONLY = 2; private final static char EVDEV_TYPE = 'E'; - private int max; private int avg; private int range; private boolean reverse; - private boolean signed; public EvdevAbsolute(String filename, int axis, boolean reverse) { ByteBuffer buffer = ByteBuffer.allocate(6*4); @@ -33,10 +29,10 @@ public class EvdevAbsolute { buffer.getInt(); //Skip current value int min = buffer.getInt(); - max = buffer.getInt(); + int max = buffer.getInt(); avg = (min+max)/2; range = max-avg; - signed = min < 0; + this.reverse = reverse; } @@ -50,10 +46,7 @@ public class EvdevAbsolute { * @return input value as short */ public short getShort(int value) { - if (signed) - return (short) ((reverse ? -1 - value : value) * (Short.MAX_VALUE + 1) / (max + 1)); - else - return (short) ((reverse ? max - value : value) * SHORT_MAX_UNSIGNED / max); + return (short) ((value-avg) * (reverse?-range:range) / Short.MAX_VALUE); } /** @@ -62,11 +55,7 @@ public class EvdevAbsolute { * @return input value as byte */ public byte getByte(int value) { - if (signed) { - return (byte) ((reverse ? -1 - value : value) * (Byte.MAX_VALUE + 1) / (max + 1)); - } else { - return (byte) ((reverse ? max - value : value) * BYTE_MAX_UNSIGNED / max); - } + return (byte) ((value-avg) * (reverse?-range:range) / Byte.MAX_VALUE); } /**