Android Sensor detailed

Source: Internet
Author: User
Tags variables

1.Sensor Type

Gravity sensor/Accelerometer (g-sensor)

Light Sensing (light-sensor)

Temperature sensing

Direction sensing

Magnetic field

Proximity of

2. How to implement sensor programming

A. Get system services (Sensor_service) return a Sensormanager object

Sensormanager = (Sensormanager) getsystemseriver (Sensor_service);

B. Obtaining an object of the corresponding sensor type through the Sensormanager object

Sensorobject = Sensormanager.getdefaultsensor (sensor Type);

C. Declare a Sensoreventlistener object to listen for sensor events and overload the Onsensorchanged method

Sensoreventlistener Sensorlistener = new Sensoreventlistener () {

};

D. Register the corresponding Sensorservice

Sensormanager.registerlistener (Sensorlistener, Sensorobject, Sensor TYPE);

E. Destruction of corresponding Sensorservice

Sensormanager.unregisterlistener (Sensorlistener, sensorobject);

The F:sensorlistener interface is the center of the sensor application. It consists of two required methods:

The onsensorchanged (int sensor,float values[]) method is invoked when the sensor value changes.

This method is invoked only for sensors that are monitored by this application (see below for more). The parameters of the method include an integer that indicates the changed sensor, and an array of floating-point values representing the sensor data itself. Some sensors provide only one data value, while others provide three floating-point values. The orientation and accelerometer sensors all provide three data values.

When the sensor's accuracy changes, the onaccuracychanged (int sensor,int accuracy) method is invoked. The parameter includes two integers: one represents the sensor and the other represents the new exact value of the sensor.

3. About G-sensor

The type of the Android acceleration sensor is sensor.type_accelerometer

Returns the accelerometer value via Android.hardware.SensorEvent.

The unit of the acceleration sensor return value is the unit m/s^2 of the acceleration (meter every two seconds), and the values in three directions are

Values[0]: X-axis direction acceleration

VALUES[1]: Y-axis direction acceleration

VALUES[2]: Z-axis direction acceleration

The definition of X,y,z direction is to position the right leg of the mobile phone as the reference coordinate origin.

x direction is the mobile phone's horizontal direction, right is positive

The y direction is the horizontal vertical direction of the cell phone, the front is positive

Y direction is the cell phone's vertical direction, the direction of the sky is positive, the direction of the Earth is negative

It should be noted that due to the intrinsic gravitational acceleration of the earth g (value of 9.8 m/s^2),

So in reality the actual acceleration value should be the Z-direction return value-9.8 m/s^2.

For example, if you toss your phone with a 2 m/s^2 acceleration, the return value in the z direction should be 11.8 m/s^2.

Conversely, if the mobile phone with the acceleration of 2 m/s^2 Fall, the z-direction of the return value should be 7.8 m/s^2.

There is no such limitation in the x,y direction.

The origin of this article: http://blog.csdn.net/henry000/archive/2010/11/02/5980867.aspx

In addition, what is the G-sensor workflow?

1. What is necessary to make g-sensor normal work:

G-sensor driver files include:

Driver/i2c/chips/lis331dl.c

Driver/i2c/chips/sensorioctl.h

Include/linux/lis331dl.h

And in the/kernel/arch/arm/mach-s3c6410/mach-ur6410.c file I2C chanel1 structure variable i2c_devs1[] __initdata need to add g-sensor device information.

The lookup is based on the order of the sensor.*.so extensions defined in harware.c, stops when the first match is found, and brings back a global variable hal_module_info_sym that is defined in the sensor.so. The variable contains a

The important information is one of its member structure variables, which contains a function pointer open, which assigns a value to a device struct variable, bringing out all the information required for sensorService.cpp and sensorManager.cpp to communicate with sensor.

There are two variants of device structure variables for use by SensorService.cpp and SensorManaer.cpp respectively. This is mainly a function of pointers to the functions of communication with sensor.

SensorService.cpp and SensorManager.cpp will invoke the Sensors.h inline function open () after the HAL_MODULE_INFO_SYM structure is obtained hal_module_info_ The SYM Open function pointer retrieves the required device information.

When the system starts Activitymanager.java, it starts the Sensormanager.java, and it also invokes the method Hw_get_module () in hardware.c to bring it back to Hal_module_info_sym.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.