use test_bit to determining if a device is a touchscreen (#1389)
This commit is contained in:
parent
e37aaffaad
commit
3349b5b3be
|
@ -10,6 +10,13 @@
|
||||||
|
|
||||||
#include "touch.h"
|
#include "touch.h"
|
||||||
|
|
||||||
|
/* this macro is used to tell if "bit" is set in "array"
|
||||||
|
* it selects a byte from the array, and does a boolean AND
|
||||||
|
* operation with a byte that only has the relevant bit set.
|
||||||
|
* eg. to check for the 12th bit, we do (array[1] & 1<<4)
|
||||||
|
*/
|
||||||
|
#define test_bit(bit, array) (array[bit/8] & (1<<(bit%8)))
|
||||||
|
|
||||||
static int find_dev() {
|
static int find_dev() {
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -28,10 +35,7 @@ static int find_dev() {
|
||||||
err = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(ev_bits)), ev_bits);
|
err = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(ev_bits)), ev_bits);
|
||||||
assert(err >= 0);
|
assert(err >= 0);
|
||||||
|
|
||||||
const int x_key = ABS_MT_POSITION_X / 8;
|
if (test_bit(ABS_MT_POSITION_X, ev_bits) && test_bit(ABS_MT_POSITION_Y, ev_bits)) {
|
||||||
const int y_key = ABS_MT_POSITION_Y / 8;
|
|
||||||
if ((ev_bits[x_key] & (ABS_MT_POSITION_X - x_key)) &&
|
|
||||||
(ev_bits[y_key] & (ABS_MT_POSITION_Y - y_key))) {
|
|
||||||
ret = fd;
|
ret = fd;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue