G-sensor On Android

 

What's G-sensor?

An g-sensor (or accelerometer) is a device that measures proper acceleration, the acceleration experienced relative to freefall.

Single- and multi-axis models are available to detect magnitude and direction of the acceleration as a vector quantity, and can be used to sense orientation, acceleration, vibration shock, and falling. Micromachined accelerometers are increasingly present in portable electronic devices and video game controllers, to detect the position of the device or provide for game input.

How it works in Linux?

KXTE9 sensor is designed for embedded system, it could export three kinds of data.
1) acceleration data in each axis(x,y,z).
2) tilt data about current position.
3) activate motion detection (Wake Up/Back to Sleep) for power saving.

For screen rotation and basic games applications, first kind of data is enough. while second kind of data is auxiliary which evolve from axis acceleration data. As I known, third kind of data is used for power saving.

Put KXTE9 chip driver to kernel/driver/input/misc/kxte9.c and board specific gpio code to kernel/arch/arm/mach-prima/prima_evb_kxte9.c. Notice that i2c_new-device() should be called after i2c driver or adapter is ready, so proper sequence is considered.

Low level KXTE9 driver read x/y/z axis acceleration data from chip and report to Linux input subsystem through input_report_abs() and input_sync(), then Linux application could read value from /dev/input/event*.

No interrupt is used exactly but coded in driver.

How it works in Android?

sensor_axis

For acceleration data in Android, all values are in SI units (m/s2) and measure the acceleration of the device minus the force of gravity.
x: Acceleration minus Gx on the x-axis 
y: Acceleration minus Gy on the y-axis 
z: Acceleration minus Gz on the z-axis 

HAL layer of sensor should be implement in Android, which should realize some important structure defined in Android/libhardware/include/hardware/sensors.h

SensorManager deal with the raw data and WindowOrientationLister calculate data to determine if screen should be roation, WindowManager do the specific rotation work.

Why game is not smoothly?

Some tips should be considered to make the best game experience.
1) ODR in sensor chip refer to time interval of data reported, more data, more smoothly application is.
2) Delay time in Linux driver and Android also influence the performance.
3) KXTE9 is less powerful than other serial of sensor product, maybe it will limit the performance (accuracy is low)

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值