Reputation: 1
I am working on handling input event by my own program in Android without Eventhub&InputReader,and the code worked in single-touch screen,while can't work in multi-touch screent,below are my codes(partialy):
int readSize = read(mInputTouchfd, mEventData, EVS_READ_EVENT_MAX_NUM * sizeof(struct input_event));
if (readSize >= (int)sizeof(struct input_event))
{
int eventNum = readSize / sizeof(struct input_event);
LOG1("HandleTouchEvent has read %d input event", eventNum);
for (int i = 0; i < eventNum; i++)
{
LOG1("number %d event,details:type:[0x%X] code:[0x%X (%d)] value:[0x%X]", i, mEventData[i].type, mEventData[i].code, mEventData[i].code, mEventData[i].value);
if (mEventData[i].type == EV_ABS && mEventData[i].code == ABS_MT_POSITION_X)
{
realx = mEventData[i].value;
}
else if (mEventData[i].type == EV_ABS && mEventData[i].code == ABS_MT_POSITION_Y)
{
realy = mEventData[i].value;
}
else if (mEventData[i].type == EV_KEY && mEventData[i].code == BTN_TOUCH)
{
if (mEventData[i].value == TOUCH_EVENT_DOWN)
{
buttonEvent = TOUCH_EVENT_DOWN;
}
else if (mEventData[i].value == TOUCH_EVENT_UP)
{
buttonEvent = TOUCH_EVENT_UP;
}
}
else if (mEventData[i].type == EV_SYN && mEventData[i].code == SYN_REPORT)
{
LOG1("parse Event succeed:Event[%s],x[%d],y[%d]", toString(buttonEvent), realx, realy);
if (spHomePage)
{
spHomePage->dispatchTouchEvent(buttonEvent, realx, realy);
}
// reset event type after handle finished
buttonEvent = TOUCH_EVENT_MOVE;
}
}
}
I have found that the event code,type,and value are different in multi-touch screen,I used getevent
command to catch such events:
/dev/input/event0: EV_KEY BTN_TOUCH UP
/dev/input/event0: EV_MSC MSC_TIMESTAMP 00032c80
/dev/input/event0: EV_SYN SYN_REPORT 00000000
/dev/input/event0: EV_ABS ABS_MT_TRACKING_ID 0000004d
/dev/input/event0: EV_ABS ABS_MT_POSITION_X 00003dad
/dev/input/event0: EV_ABS ABS_MT_POSITION_Y 000012bc
/dev/input/event0: EV_KEY BTN_TOUCH DOWN
/dev/input/event0: EV_ABS ABS_X 00003dad
/dev/input/event0: EV_ABS ABS_Y 000012bc
/dev/input/event0: EV_MSC MSC_TIMESTAMP 00034bc0
/dev/input/event0: EV_SYN SYN_REPORT 00000000
/dev/input/event0: EV_MSC MSC_TIMESTAMP 00036b00
when code=EV_ABS,type=ABS_MT_POSITION_X,the value is 00003dad(hex),equal to 15789(Dec),which is much bigger than 1920(my touch screen is 10 inCh,16:9 and 1080p,),I am confused how can I get the accurate coordinates(including x and y)?I think the value’s unit is Pixel while it seems not,anyone can help me?
I have searched ChatGPT/Google bard while I got the wrong answers.
Upvotes: 0
Views: 255
Reputation: 1
Finally I found the answer for this question,in Android we can use getevent
to get input protocol details including X/Y interval,for example:
a1000b:/ $ getevent -lp /dev/input/event0
add device 1: /dev/input/event0
name: "ILITEK ILITEK-TP"
events:
KEY (0001): BTN_TOUCH
ABS (0003): ABS_X : value 11767, min 0, max 16384, fuzz 0, flat 0, resolution 34
ABS_Y : value 2656, min 0, max 9600, fuzz 0, flat 0, resolution 36
ABS_MT_SLOT : value 0, min 0, max 9, fuzz 0, flat 0, resolution 0
ABS_MT_POSITION_X : value 0, min 0, max 16384, fuzz 0, flat 0, resolution 34
ABS_MT_POSITION_Y : value 0, min 0, max 9600, fuzz 0, flat 0, resolution 36
ABS_MT_TRACKING_ID : value 0, min 0, max 65535, fuzz 0, flat 0, resolution 0
MSC (0004): MSC_TIMESTAMP
input props:
INPUT_PROP_DIRECT
a1000b:/ $
here we got X value interval:0-16384,Y value interval:0-9600;
And we got events(also us getevent
command) like this:
130|a1000b:/ $ getevent -l /dev/input/event0
EV_ABS ABS_MT_TRACKING_ID 0000000b
EV_ABS ABS_MT_POSITION_X 00002e95
EV_ABS ABS_MT_POSITION_Y 00000f32
EV_KEY BTN_TOUCH DOWN
EV_ABS ABS_X 00002e95
EV_ABS ABS_Y 00000f32
EV_MSC MSC_TIMESTAMP 00000000
EV_SYN SYN_REPORT 00000000
EV_MSC MSC_TIMESTAMP 00001f40
here we got x(ABS_MT_POSITION_X)=2e95(HEX),equals to 11925(DEC),and we translate to pixel(my screen is 1920*1080):
11925/16384*1920=1397.4609375≈1397,so can got X(in Pixel)is 1397,and the Y value is same calculation.
Upvotes: 0