本文的led是三色的分别是红色,蓝色,绿色
红色:低电量,电量低于15%
蓝色:充电,电量在15%到90%之间
绿色:电量在90%到100%
开机充电情况:
驱动层:
mediatek\custom\project\lk\cust_leds.c
static struct cust_mt65xx_led cust_led_list[MT65XX_LED_TYPE_TOTAL] = { {"red", MT65XX_LED_MODE_PMIC, MT65XX_LED_PMIC_NLED_ISINK0,{0,0,0,0,0}}, {"green", MT65XX_LED_MODE_PMIC, MT65XX_LED_PMIC_NLED_ISINK1,{0,0,0,0,0}}, {"blue", MT65XX_LED_MODE_NONE, MT65XX_LED_PMIC_NLED_ISINK2,{0,0,0,0,0}}, {"jogball-backlight", MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}}, {"keyboard-backlight",MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}}, {"button-backlight", MT65XX_LED_MODE_NONE, -1,{0,0,0,0,0}}, {"lcd-backlight", MT65XX_LED_MODE_CUST_BLS_PWM, (int)disp_bls_set_backlight,{0,0,0,0,0}}, };
上层:
aplse\frameworks\base\core\res\res\values\config.xml
上层配置文件,修改开机充电模式下led显示情况
<!-- Display low battery warning when battery level dips to this value --> <integer name="config_lowBatteryWarningLevel">15</integer> 控制低电量的最低值 <!-- Close low battery warning when battery level reaches this value --> <integer name="config_lowBatteryCloseWarningLevel">20</integer> <!-- Default color for notification LED. --> <color name="config_defaultNotificationColor">#ffffffff</color> <!-- Default LED on time for notification LED in milliseconds. --> <integer name="config_defaultNotificationLedOn">500</integer> <!-- Default LED off time for notification LED in milliseconds. --> <integer name="config_defaultNotificationLedOff">2000</integer> <!-- Default value for led color when battery is low on charge --> <integer name="config_notificationsBatteryLowARGB">0xFFFF0000</integer> 低电量红色 <!-- Default value for led color when battery is medium charged --> <integer name="config_notificationsBatteryMediumARGB">0xFF0000FF</integer> 15到90 蓝色 <!-- Default value for led color when battery is fully charged --> <integer name="config_notificationsBatteryFullARGB">0xFF00FF00</integer> 90以上绿色
apls\ frameworks\base\services\java\com\android\server\BatteryService.java
public void updateLightsLocked() { final int level = mBatteryProps.batteryLevel; final int status = mBatteryProps.batteryStatus; if(mIPOBoot) { //Get led status in IPO mode getIpoLedStatus(); } if (level < mLowBatteryWarningLevel) { if (status == BatteryManager.BATTERY_STATUS_CHARGING) { updateLedStatus(); // Solid red when battery is charging mBatteryLight.setColor(mBatteryLowARGB); } else { LowLevelFlag = true; updateLedStatus(); // Flash red when battery is low and not charging mBatteryLight.setFlashing(mBatteryLowARGB, LightsService.LIGHT_FLASH_TIMED, mBatteryLedOn, mBatteryLedOff); } } else if (status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL) { if (status == BatteryManager.BATTERY_STATUS_FULL || level >= 90) { updateLedStatus(); // Solid green when full or charging and nearly full mBatteryFullARGB mBatteryLight.setColor(mBatteryFullARGB); } else { updateLedStatus(); // Solid orange when charging and halfway full mBatteryLight.setColor(mBatteryMediumARGB); } } else { if(ipo_led_on && mIPOBoot){ if (status == BatteryManager.BATTERY_STATUS_FULL || level >= 90) { mBatteryLight.setColor(mBatteryFullARGB); } else { mBatteryLight.setColor(mBatteryMediumARGB); } mIPOBoot = false; ipo_led_on = false; } // No lights if not charging and not low mBatteryLight.turnOff(); } }
这里是对三色的判断并输出
关机充电情况:
修改两个文件: mediatek\external\ipod目录下面的ipodlights.cpp和ipodmain.h
修改的代码如下:
ipodlights.cpp
#include <stdio.h> #include <utils/Log.h> #include "ipodmain.h" #define LED_RED_PATH "/sys/class/leds/red/brightness" #define LED_BLUE_PATH "/sys/class/leds/blue/brightness" #define BATTERY_CAPACITY_PATH "/sys/class/power_supply/battery/capacity" #define LED_GREEN_PATH "/sys/class/leds/green/brightness" #define LED_ONOFF_PROP "sys.ipo.ledon" /* int (*ipod_chglights[])(void) = { lights_init, lights_chgfull, lights_chgon, lights_chgexit, }; */ static int led_isOn = CONTROL_UNKNOWN; static int led_green_isOn = CONTROL_UNKNOWN; static int led_red_isOn = CONTROL_UNKNOWN; static int led_blue_isOn = CONTROL_UNKNOWN; static int nChargingFull = CONTROL_UNKNOWN; static int nChargingRemoved = CONTROL_UNKNOWN; void turn_led_on() { if (led_isOn == CONTROL_ON) return; led_isOn = CONTROL_ON; property_set(LED_ONOFF_PROP, "1"); } void turn_led_off() { if (led_isOn == CONTROL_OFF) return; led_isOn = CONTROL_OFF; property_set(LED_ONOFF_PROP, "0"); } void start_blue_led(int skew) { if (led_blue_isOn == CONTROL_ON) return; led_blue_isOn = CONTROL_ON; if (skew > 255) skew = 255; else if (skew < 0) skew = 0; set_int_value(LED_BLUE_PATH, skew); } void stop_blue_led() { if (led_blue_isOn == CONTROL_OFF) return; led_blue_isOn = CONTROL_OFF; set_int_value(LED_BLUE_PATH, 0); } void start_red_led(int skew) { if (led_red_isOn == CONTROL_ON) return; led_red_isOn = CONTROL_ON; if (skew > 255) skew = 255; else if (skew < 0) skew = 0; set_int_value(LED_RED_PATH, skew); } void stop_red_led() { if (led_red_isOn == CONTROL_OFF) return; led_red_isOn = CONTROL_OFF; set_int_value(LED_RED_PATH, 0); } void start_green_led(int skew) { if (led_green_isOn == CONTROL_ON) return; led_green_isOn = CONTROL_ON; if (skew > 255) skew = 255; else if (skew < 0) skew = 0; set_int_value(LED_GREEN_PATH, skew); } void stop_green_led() { if (led_green_isOn == CONTROL_OFF) return; led_green_isOn = CONTROL_OFF; set_int_value(LED_GREEN_PATH, 0); } int lights_chgfull() { /* do not block this function like sleep */ SXLOGI("lights_chgfull"); pthread_mutex_lock(&mutex); nChargingFull = CONTROL_ON; nChargingRemoved = CONTROL_OFF; stop_blue_led(); start_green_led(255); turn_led_on(); pthread_mutex_unlock(&mutex); return 0; } int lights_chgon() { SXLOGI("lights_chgon"); #if 1 pthread_mutex_lock(&mutex); nChargingFull = CONTROL_OFF; nChargingRemoved = CONTROL_OFF; stop_green_led(); if(get_int_value(BATTERY_CAPACITY_PATH) < 15) { stop_blue_led(); start_red_led(255); } else { stop_red_led(); start_blue_led(255); } turn_led_on(); pthread_mutex_unlock(&mutex); #else // an example of light on 2sec, off 3sec. pthread_mutex_lock(&mutex); if (nChargingFull != CONTROL_ON && nChargingRemoved != CONTROL_ON) { nChargingFull = CONTROL_OFF; nChargingRemoved = CONTROL_OFF; stop_green_led(); start_red_led(255); turn_led_on(); } else { nChargingFull = CONTROL_OFF; nChargingRemoved = CONTROL_OFF; pthread_mutex_unlock(&mutex); return 0; } pthread_mutex_unlock(&mutex); usleep(2000*1000); //sleep 2 sec pthread_mutex_lock(&mutex); if (nChargingFull != CONTROL_ON && nChargingRemoved != CONTROL_ON) { stop_red_led(); turn_led_off(); } // reset the state to let next time chgon can work normally. nChargingFull = CONTROL_OFF; nChargingRemoved = CONTROL_OFF; pthread_mutex_unlock(&mutex); #endif return 0; } int lights_chgexit() { /* do not block this function like sleep */ SXLOGI("lights_chgexit"); pthread_mutex_lock(&mutex); nChargingFull = CONTROL_OFF; nChargingRemoved = CONTROL_ON; stop_green_led(); if(get_int_value(BATTERY_CAPACITY_PATH) < 15) { stop_red_led(); } else { stop_blue_led(); } turn_led_off(); pthread_mutex_unlock(&mutex); return 0; }
今天的文章 android mtk6592 添加led三色灯,红色蓝色绿色分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ji-chu/91851.html