我正在阅读(触摸)来自linux内核的事件。我想记录这些事件的时间,但我不知道这些事件是以timespec还是timeval的形式传递的。有人能指出我的正确方向吗?
示例代码(在从缓冲区读取事件之后)
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;
}
}随着时间的推移,它可以工作,但这是否也是一个自动幸运的类型转换?
编辑:一旦我写了这篇文章,我就想出了一些方法来检查它。读取linux内核事件的代码“evtest”是开源的。在第1060项上,他们使用timeval结构来报告事件时间。我猜这是一个明确的答案:或者它仍然是一个不可预见的类型化?
发布于 2019-07-24 05:48:28
有人能指出我的正确方向吗?
见文件/输入/输入。
从/dev/input/eventX设备读取数据将返回struct input_event的数据,该struct input_event的第一个成员是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.发布于 2019-07-23 23:39:54
C++不会自动转换结构,尽管它们可以定义转换。( Linux中的C结构永远不会这么做。)
https://stackoverflow.com/questions/57173044
复制相似问题