简体   繁体   English

Linux IIO加速度计运动检测事件

[英]Linux IIO accelerometer motion dectection events

I have a MMA8563 accelerometer in an imx6ul board and am using the mma8452.c Linux IIO driver.我在 imx6ul 板上有一个 MMA8563 加速度计,我正在使用 mma8452.c Linux IIO 驱动程序。 I can access x, y, z raw values fine through /sys/bus/iio/devices/iio:device0.我可以通过 /sys/bus/iio/devices/iio:device0 访问 x、y、z 原始值。

However, I am unsure of how to use IIO events.但是,我不确定如何使用 IIO 事件。 I have configured motion detection in the accelerometer using the following commands:我使用以下命令在加速度计中配置了运动检测:

# echo 15 > events/in_accel_mag_rising_value
# echo 1 > events/in_accel_mag_rising_period
# echo 1 > events/in_accel_x_mag_rising_en

I have placed debug print statements in the driver code and can see that the interrupt is being triggered when I move the device.我在驱动程序代码中放置了调试打印语句,并且可以看到当我移动设备时正在触发中断。 I see that the driver then calls the iio_push_event() function. I can also see that the interrupt number in /proc/interrupts increments each time I move the device.我看到驱动程序随后调用 iio_push_event() function。我还可以看到每次移动设备时 /proc/interrupts 中的中断号都会增加。

From user space, how can I get access to this interrupt or event?从用户空间,我怎样才能访问这个中断或事件? I would like to be able to tell when the device is in motion.我希望能够知道设备何时处于运动状态。

The driver creates a buffer and a char dev in /dev/iio:device0 but this seems to only populate when I enable either x, y, or z in the scan_elements directory.驱动程序在 /dev/iio:device0 中创建一个缓冲区和一个 char dev,但这似乎只在我在 scan_elements 目录中启用 x、y 或 z 时填充。

Applications can read events via a special file descriptor obtained from ioctl() requesting IIO_GET_EVENT_FD_IOCTL on the file descriptor of /dev/iio:devicex , something like this:应用程序可以通过从ioctl()获取的特殊文件描述符读取事件,在/dev/iio:devicex的文件描述符上请求IIO_GET_EVENT_FD_IOCTL ,如下所示:

struct iio_event_data event;
int fd, event_fd;

fd = open("/dev/iio:devicex", 0);
ioctl(fd, IIO_GET_EVENT_FD_IOCTL, &event_fd);
read(event_fd, &event, sizeof(event)); 
/* Instead of read(), may also use select() or poll() etc. */

Reference:参考:
linux/tools/iio/iio_event_monitor.c linux/工具/iio/iio_event_monitor.c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM