msm8909+android5.1.1 's BSP development---switching machine charging Tri-color lamp control

Source: Internet
Author: User
<span id="Label3"></p><p align="center"><p align="center"><span style="font-size:14px;">msm8909+android5.1.1 's BSP development---switching machine charging Tri-color lamp control</span></p></p><p align="center"><p align="center"><span style="font-size:14px;"><br></span></p></p><p align="center"><p align="center"></p></p><p align="center"><p align="center"><span style="font-size:14px;">Figure 1</span></p></p><p><p><span style="font-size:14px;"></span></p></p><p><p><span style="font-size:14px;"></span></p></p><p><p><span style="font-size:14px;">1. Charge Tri-color Lamp Control</span></p></p><p><p><span style="font-size:14px;">1.1 Power-off charge Tri-color Lamp Control</span></p></p><p><p><span style="font-size:14px;">Related Documents: system\core\healthd\healthd_mode_charger.cpp</span></p></p><p><p><span style="font-size:14px;"></span></p></p><p><p><span style="font-size:14px;">When the current charge is not equal to the previous charge, call Handle_power_supply_state ()--->set_battery_soc_leds () to control the Tri-color lamp, first look at the global array used in it</span></p></p><p><p></p></p><pre code_snippet_id="1586395" snippet_file_name="blog_20160224_1_7949533" name="code" class="cpp"><pre code_snippet_id="1586395" snippet_file_name="blog_20160224_1_7949533" name="code" class="cpp">#define Red_led_path " /sys/class/leds/red/brightness" #define Green_led_path "/sys/class/leds/green/ Brightness "#define blue_led_path" /sys/class/leds/blue/brightness "struct led_ctl leds[3] = {{red_led, red_ led_path}, {green_led, green_led_path},{blue_led,blue_led_path}}; struct soc_led_color_mapping soc_leds[3] ={ {red_led}, {$ , red_led | green_led}, {green_led},};</pre></pre><p><p></p></p><p><p><span style="font-size:14px;">Qualcomm's Design Ideas Are:</span></p></p><p><p><span style="font-size:14px;">Red: low power, less than 15%</span></p></p><p><p><span style="font-size:14px;">Blue: charging, charge from 15% to 90%</span></p></p><p><p><span style="font-size:14px;">Green: 90% to 100% Power</span></p></p><p><p><span style="font-size:14px;">For example, for/sys/class/leds/chg_red/brightness, set to 0 for red, 1 for green, and 255 for Green</span></p></p><p><p><span style="font-size:14px;">/green/brightness, set to 0 for off green, set to 1 to open the light</span></p></p><p><p></p></p><pre code_snippet_id="1586395" snippet_file_name="blog_20160224_2_4045056" name="code" class="cpp"><pre code_snippet_id="1586395" snippet_file_name="blog_20160224_2_4045056" name="code" class="cpp">static int set_battery_soc_leds (int soc) { int i, color; static int old_color = 0; int fd; Char buffer[10]; FD = Open ("/sys/class/leds/chg_red/brightness", o_rdwr); snprintf (buffer, sizeof (int), "%d\n", 0); Write (fd, buffer, strlen (buffer)); Close (fd); For (i = 0; i < (int) array_size (soc_leds), i++) { if (soc <= soc_leds[i].soc) break ; } color = soc_leds[i].color; If (old_color! = Color) { set_tricolor_led (0, old_color); set_tricolor_led (1, color); Old_color = color; LOGV ("SOC =%d, Set led color 0x%x\n", soc,soc_leds[i].color); } Return 0;}</pre></pre><br><p><p></p></p><p><p><span style="font-size:14px;">This is the High-pass default design, but for our hardware design, there is a problem, is the power >15%, red and green lights are bright, in order to solve this problem, and we power off the battery <95% is a red light, >=95% for green, modified as Follows:</span></p></p><p><p></p></p><pre code_snippet_id="1586395" snippet_file_name="blog_20160224_3_523045" name="code" class="cpp">struct Led_ctl leds[2] = {{red_led, red_led_path}, {green_led, green_led_path}}; struct soc_led_color_mapping soc_leds[2] ={{green_led},};static, red_led}, {----) int i, color; static int old_color = 0; int fd; Char buffer[10]; FD = Open ("/sys/class/leds/chg_red/brightness", o_rdwr); snprintf (buffer, sizeof (int), "%d\n", 0),//red on write (fd, buffer, strlen (buffer)); Close (fd); For (i = 0; i < (int) array_size (soc_leds), i++) {if (soc <= soc_leds[i].soc) break; If (old_color! = Color) {if (soc>=soc_leds[1].soc) {fd =open ("/sys/class/leds/chg_red/brightness", o_rdwr); snprintf (buffer,sizeof (int), "%d\n", 255);//red off write (fd,buffer, strlen (buffer)); Close (fd); Fd= Open ("/sys/class/leds/red/brightness", o_rdwr); snprintf (buffer,sizeof (int), "%d\n", 0); Write (fd,buffer, strlen (buffer)); Close (fd); Set_tricolor_led (1,green_led); } else {set_tricolor_led (1,red_led); } Old_color = color; LOGV ("SOC =%d, Set led color0x%x\n", soc, soc_leds[i].color); } return 0;}</pre><br><p><p></p></p><p><p><span style="font-size:14px;">1.2 power-on Charge Tri-color light control</span></p></p><p><p></p></p><pre code_snippet_id="1586395" snippet_file_name="blog_20160224_4_4285036" name="code" class="cpp">frameworks/base/services/core/java/com/android/server/batteryservice.javapublic void updateLightsLocked ()/** * Synchronize on Batteryservice. */public void updatelightslocked () {final int. level = mbatteryprops.batterylevel; Final int status = mbatteryprops.batterystatus; If (level < Mlowbatterywarninglevel) {if (status ==batterymanager.battery_status_charging) { Solid Red when Batteryis charging Mbatterylight.setcolor (mbatterylowargb); } else {//Flash red when batteryis low and not charging mbatterylight.setflashing (m batterylowargb, light.light_flash_timed, mbatteryledon,mbatteryledoff); }} else if (status = = Batterymanager.battery_status_charging | | status ==batterymanager.batt Ery_status_full) {if (STATUS ==batterymanager.battery_Status_full | | Level >=95) {//kandi change from the To95//Solid green when full orcharging and nearly full Mbatterylight.setcolor (mbatteryfullargb); } else {//Solid Orange whencharging and halfway full Mbatterylight.setcolor (mbatter ylowargb); }} Else {//No lights if not charging Andnot low Mbatterylight.turnoff (); } }</pre><br><p><p></p></p><p><p><span style="font-size:14px;">2. Discharge Tri-color Lamp Control</span></p></p><p><p><span style="font-size:14px;">2.1 Battery <15%</span></p></p><p><p><span style="font-size:14px;">Low battery red flashes are also controlled using the updatelightslocked () Above.</span></p></p><p><p><span style="font-size:14px;"></span></p></p><p><p><span style="font-size:14px;"></span></p></p><p><p>msm8909+android5.1.1 's BSP development---switching machine charging Tri-color lamp control</p></p></span>

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.