use test_bit to determining if a device is a touchscreen (#1389)

pull/1256/merge
Dean Lee 2020-05-12 06:30:22 +08:00 committed by GitHub
parent e37aaffaad
commit 3349b5b3be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -10,6 +10,13 @@
#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() {
int err;
@ -28,10 +35,7 @@ static int find_dev() {
err = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(ev_bits)), ev_bits);
assert(err >= 0);
const int x_key = ABS_MT_POSITION_X / 8;
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))) {
if (test_bit(ABS_MT_POSITION_X, ev_bits) && test_bit(ABS_MT_POSITION_Y, ev_bits)) {
ret = fd;
break;
}