Linux 内核事件:timeval 或 timespec [英] Linux kernel event: timeval or timespec
问题描述
我正在从 linux 内核读取(触摸)事件.我想记录这些事件的时间,但我不知道这些是作为 timespec 还是 timeval 传递的.有人能指出我正确的方向吗?
I am reading (touch)event from the linux kernel. I'd like to log the time of these events, but I am unaware whether these are passed as timespec or timeval. Could anyone point me in the right direction?
示例代码(从缓冲区读取事件后)
Example code (after the events are read from the buffer)
switch(evnt.code) {
case ABS_X:
case ABS_Y:
break;
case ABS_MT_SLOT:
// this one sets the digit (virtual representation of the finger)
current.setSlot(evnt.value);
break;
case ABS_MT_POSITION_X:
current.setX(evnt.value, evnt.time);
break;
case ABS_MT_POSITION_Y:
current.setY(evnt.value, evnt.time);
break;
case ABS_MT_TRACKING_ID:
current.setActive(evnt.value >= 0, evnt.time);
break;
default:
W_MOD("EV_ABS, unhandled event code " << evnt.code);
}
和进程函数之一:
inline void setY(int value, struct timeval KernelTime)
{
if (slot < ndigits) {
// store both time and value
digit[slot].y = value;
digit[slot].TimeOfEvent = KernelTime.tv_sec*1000000 + KernelTime.tv_usec;;
digit[slot].changed = true;
}
}
使用 timeval 它可以工作,但这也可能是自动的幸运类型转换吗?
With timeval it works, but could this also be an automatic lucky typecasting?
当我写完这篇文章时,我想出了一些方法来检查它.读取 linux 内核事件的代码evtest"是开源的.在 第 1060 行 上,他们使用 timeval 结构来报告活动时间.我猜这是肯定的答案:或者它仍然是一个无法预料的类型转换?
as soon as I wrote this I figured some way to check it. the code 'evtest' which reads linux kernel events is open source. On line 1060 they use a timeval struct to report the event time. I am guessing this is the definite answer: or could it still be a unforeseen typecasting?
推荐答案
有人能指出我正确的方向吗?
Could anyone point me in the right direction?
请参阅文档/input/input.rst.
从 /dev/input/eventX
设备读取返回 struct input_event
的数据,其第一个成员是 struct timeval time;
See Documentation/input/input.rst.
Reading from a /dev/input/eventX
device returns data for a struct input_event
, whose first member is struct timeval time;
Event interface
===============
...
struct input_event {
struct timeval time;
unsigned short type;
unsigned short code;
unsigned int value;
};
``time`` is the timestamp, it returns the time at which the event happened.
这篇关于Linux 内核事件:timeval 或 timespec的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!