Android: Android light sensor howto

Source: Internet
Author: User

Added support for light sensor based on Android 2.2:

1) UI

2) Framework section

3) Hal part

4) Driver

 

The following are discussed respectively:

1) UI

A) Enable the brightness setting menu to automatically adjust the brightness checkbox.

Frameworks/base/CORE/RES/values/config. xml:

-<Bool name = "config_automatic_brightness_available"> false </bool>

+ <Bool name = "config_automatic_brightness_available"> true </bool>

B) set both the Lux level and the brightness level. Take the 5-level brightness as an example.

<Integer-array name = "config_autobrightnesslevels">

 

+ <Item> 1000 </item> + <item> 2000 </item> + <item> 3000 </item> + <item> 4000 </item> </integer- array> <integer-array name = "config_autobrightnesslcdbacklightvalues"> + <item> 20 </item> + <item> 80 </item> + <item> 120 </item> + <item> 160 </item> + <item> 250 </item> </integer-array> autobrightnesslevels, the data transmitted by the Hal layer falls between these values to distinguish the lcdbacklightvalues from the actual value of the 5-level brightness. 2) Framework sectionA) files related to the framework layer. /CORE/Java/Android/hardware/sensorevent. java. /CORE/Java/Android/hardware/sensorlistener. java. /CORE/Java/Android/hardware/isensorservice. aidl. /CORE/Java/Android/hardware/sensor. java. /CORE/Java/Android/hardware/sensoreventlistener. java. /CORE/JNI/android_hardware_sensormanager.cpp // sensormanager JNI. /CORE/Java/Android/hardware/sensormanager. java // sensormanager. /services/JNI/com_android_server_sensorservice.cpp // sensorsersvice JNI. /services/Java/COM/Android/Server/sensorservice. java // sensorservice. /services/Java/COM/Android/Server/powermanagerservice. the Java sensor system is relatively simple, so we need to modify less: to add light sensor, we only need to modify sensormanager. java, powermanagerservice. java two files B) sensormanager. java: @-582,6 + 582,8 @ public class sensormanager <br/> return sensor_orientation_raw; <br/> case sensor. type_temperature: <br/> return sensor_temperature; <br/> + case sensor. type_light: <br/> + return sensor_light; <br/>}< br/> return 0; <br/>}< br/> @-606,6 + 608,9 @ public class sensormanager <br/> result | = sensormanager. sensor_orientation | <br/> sensormanager. sensor_orientation_raw; <br/> break; <br/> + case sensor. type_light: <br/> + Result | = sensormanager. sensor_light; <br/> + break; <br/>}< br/> return result; <br/> @-707,6 + 712,8 @ public class sensormanager <br/> listener, sensors, rate) | result; <br/> result = registerlegacylistener (sensor_temperature, sensor. type_temperature, <br/> listener, sensors, rate) | result; <br/> + Result = registerlegacylistener (sensor_light, sensor. type_light, <br/> + listener, sensors, rate) | result; <br/> return result; <br/>}</P> <p> @-766,6 + 773,8 @ public class sensormanager <br/> listener, sensors); <br/> unregisterlegacylistener (sensor_temperature, sensor. type_temperature, <br/> listener, sensors); <br/> + unregisterlegacylistener (sensor_light, sensor. type_light, <br/> + listener, sensors); <br/>}C) powermanagerservice. Java: It seems to be a system bug. Int lcdvalue = getautobrightnessvalue (<br/>-(misdocked? Value: mhighestlightsensorvalue), <br/>-mlcdbacklightvalues); <br/> + (true? Value: mhighestlightsensorvalue), <br/> + mlcdbacklightvalues ); 3) Hal partImplement hardware/libhardware/include/hardware/sensor. H Interface, write a Hal layer. For this part, please refer to my previous article: Android sensor Hal example. If that example is well written, it must be noted that, all Android sensor files share a Hal file, therefore, if your system already has other sensor, you need to add the light sensor Hal layer to the Hal implementation of other sensor to generate/system/lib/HW/sensors. xxx. so 4) DriverWhatever the light sensor of the interface, write it as an input device and provide data through/dev/input/eventx so that nread = read (ls_fd, & event, sizeof (event )); If (Event-> type = ev_abs) {<br/> logv ("light-level type: % d code: % d value: %-5d time: % ds ", <br/> event-> type, event-> code, event-> value, <br/> (INT) Event-> time. TV _sec); <br/> If (Event-> code = event_type_light) {<br/> struct input_absinfo absinfo; <br/> int index; <br/> If (! IOCTL (FD, eviocgabs (abs_distance), & absinfo) {<br/> Index = event-> value; <br/> If (index> = 0) {<br/> new_sensors | = sensors_light; <br/> If (index> = array_size (sluxvalues) {<br/> Index = array_size (sluxvalues)-1; <br/>}< br/> Dev-> sensors [id_l]. light = sluxvalues [Index]; <br/>}< br/>}. Light is finally passed to powermanager. powermanager obtains the specific Brightness Value of config_autobrightnesslcdbacklightvalues Based on the config_autobrightnessnevels array, and then adjusts the brightness, for example,. Light = 2500.0 3000.0 <2500.0 <4000.0 corresponds to lcdbacklightvalues is --

 

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.