gpt4 book ai didi

c++ - Linux 内核事件 : timeval or timespec

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:31:45 26 4
gpt4 key购买 nike

我正在从 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;
}
}

timeval 可以工作,但这也可以是自动幸运类型转换吗?

编辑:我一写这篇文章,就想出了一些方法来检查它。读取 linux 内核事件的代码“evtest”是开源的。在 line 1060他们使用 timeval 结构来报告事件时间。我猜这是肯定的答案:还是它仍然是无法预料的类型转换?

最佳答案

Could anyone point me in the right direction?

参见 Documentation/input/input.rst .
/dev/input/eventX 设备读取返回 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.

关于c++ - Linux 内核事件 : timeval or timespec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57173044/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com