在Android内核级别访问和使用加速度计的值

在Android内核级别访问和使用加速度计的值

本文介绍了在Android内核级别访问和使用加速度计的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

如何在android内核空间中访问加速度计并使用其数据?我正在做一个项目,该项目需要在手机移动(在汽车中)时控制手机的某些功能,并且我想使用加速度计来帮助确定手机是否已加速.它必须全部在内核空间中完成.我在android开发人员页面上找到了如何使用加速度计和SensorEvent来检测用户级应用程序中的更改.但是,如何在内核级别执行类似的操作?我应该打系统电话吗?

How can I access the accelerometer in the android kernel space and use it's data? I'm working on a project where I need to control some of the phone's functionality while the phone is moving (in a car) and I want to use the accelerometer to help determine if the phone had accelerated. It has to all be done in the kernel space. I found on the android developer pages how to use the accelerometer and the SensorEvent to detect changes in a user level application. But how to do something like that on the kernel level? Should I make a system call?

环顾四周并进行搜索,我认为文件位于/goldfish/drivers/hwmon/中,但我不太确定.

From looking around a bit and searching, I think the files are in /goldfish/drivers/hwmon/ but I'm not quite sure.

推荐答案

处于活动状态的加速度计输入来自/dev/input/event 设备.您可以使用工具箱的 getevent()进行验证,该工具会在您倾斜手机时实时向您显示输入事件(如果有内存,则需要/dev/input/event3 ,但您可以自己检查一下.)

The accelerometer input, at the antive level, is taken from /dev/input/event devices. You can verify that using the toolbox's getevent(), which will show you the input events in real time as you tilt the phone (if memory serves, you need /dev/input/event3 but you can check this for yourself easily).

加速度计的驱动程序导出此字符设备,然后Android运行时(在 libhardware 的帮助下)随后将其转换为熟悉的SensorEvent.没有用于此的内核API.您最简单的解决方案是直接与/dev/event 交互.这可以通过两种方式完成:

The drivers for the accelerometer export this character device, which in turn the Android runtime (with the assistance of libhardware) later converts to the familiar SensorEvent. There is no kernel API for this. Your simplest solution would be to interface with the /dev/event directly. This could be done in two ways:

  1. 用户模式守护程序在/dev/event 上侦听,并且还与您的内核线程通信(例如,通过阻止您的内核模块导出的其他字符设备进行阻塞,反向系统调用等)

  1. User mode daemon listens on /dev/event, and also communicates with your kernel thread (e.g. by blocking on another character device which your kernel module exports, reverse system call, etc)

不建议使用,但可以使用-从内核模式打开/dev/input/event (直接调用 sys_open ,然后调用 sys_read ).这将需要解决"内核保护(最显着的是设置 KERNEL_DS ).

not recommended but would work - opening the /dev/input/event from kernel mode (using a direct call to sys_open and then calls to sys_read). This would require "working around" kernel protections (most notably KERNEL_DS being set).

这篇关于在Android内核级别访问和使用加速度计的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 07:07