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.
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.
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.
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)