G-sensor On Android

來源:互聯網
上載者:User

 

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?

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)

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.