Linux 内核事件:timeval 或 timespec
Linux kernel event: timeval or timespec
我正在从linux内核读取(触摸(事件。我想记录这些事件的时间,但我不知道这些是作为时间规范还是时间值传递的。谁能指出我正确的方向?
示例代码(从缓冲区读取事件后(
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 结构来报告事件时间。我猜这是确定的答案:或者它仍然是一个不可预见的类型转换?
谁能指出我正确的方向?
请参阅 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.
<</div>
div class="answers">C++不会自动转换结构,尽管它们可以定义转换。 (来自 Linux 的 C 结构永远不会这样做。
相关文章:
- 提升错误:变量"TimeSpec RQTP"具有初始值设定项,但类型不完整
- Linux 内核事件:timeval 或 timespec
- 将 Timeval 结构转换为 C#
- 格式化时间(使用timespec)以获得以纳秒为单位的正确值
- Linux 中的 timeval 变量声明
- timespec.tv_sec始终返回 0
- 在 Multimap 中使用 TimeSpec 结构,其中和/或如何定义运算符<
- C++11: struct timeval
- 将 Timeval 成员变量复制到整数变量
- 相当于窗口的Timespec
- 将std::chrono::system_clock::time_point转换为struct timeval并返回
- 将timeval格式化为“最佳单位”
- 正在从struct-timespec转换为std::chrono::
- 重新初始化timeval结构
- windows编译器上的timespec
- select() 不使用为 timeval 设置的内容