summaryrefslogtreecommitdiffstats
path: root/healthd
diff options
context:
space:
mode:
authorFenglin Wu <fenglinw@codeaurora.org>2014-09-11 10:15:03 +0800
committerSteve Kondik <steve@cyngn.com>2015-10-30 16:40:00 -0700
commit20711f93debf634e441856f693407ec20b77b1a8 (patch)
tree28acce96ca82afa56c9e77d245b9237433836b8c /healthd
parentca3ec94baf63e78a551c8f9d441993a79229498e (diff)
downloadsystem_core-20711f93debf634e441856f693407ec20b77b1a8.zip
system_core-20711f93debf634e441856f693407ec20b77b1a8.tar.gz
system_core-20711f93debf634e441856f693407ec20b77b1a8.tar.bz2
healthd: charger: Add tricolor led to indicate battery capacity
Add led to indicate battery capacity when doing off mode charging. The led behavior is design as below: i. Shows red led if capacity is lower than 15%. ii. Shows yellow (red + green) led if capacity is lower than 90% but higher than 15%. iii. Shows green led if capacity is higher than 90%. Change-Id: If637defec8a04e859b00a6492ec1f95d6bff2200
Diffstat (limited to 'healthd')
-rw-r--r--healthd/healthd_mode_charger.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp
index c0db457..e4e1632 100644
--- a/healthd/healthd_mode_charger.cpp
+++ b/healthd/healthd_mode_charger.cpp
@@ -72,6 +72,9 @@ char *locale;
#define LAST_KMSG_PATH "/proc/last_kmsg"
#define LAST_KMSG_PSTORE_PATH "/sys/fs/pstore/console-ramoops"
#define LAST_KMSG_MAX_SZ (32 * 1024)
+#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"
#define LOGE(x...) do { KLOG_ERROR("charger", x); } while (0)
#define LOGW(x...) do { KLOG_WARNING("charger", x); } while (0)
@@ -168,6 +171,33 @@ static struct animation battery_animation = {
.capacity = 0,
};
+enum {
+ RED_LED = 0x01 << 0,
+ GREEN_LED = 0x01 << 1,
+ BLUE_LED = 0x01 << 2,
+};
+
+struct led_ctl {
+ int color;
+ const char *path;
+};
+
+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 {
+ int soc;
+ int color;
+};
+
+struct soc_led_color_mapping soc_leds[3] = {
+ {15, RED_LED},
+ {90, RED_LED | GREEN_LED},
+ {100, GREEN_LED},
+};
+
static struct charger charger_state;
static struct healthd_config *healthd_config;
static struct android::BatteryProperties *batt_prop;
@@ -175,6 +205,54 @@ static int char_width;
static int char_height;
static bool minui_inited;
+static int set_tricolor_led(int on, int color)
+{
+ int fd, i;
+ char buffer[10];
+
+ for (i = 0; i < (int)ARRAY_SIZE(leds); i++) {
+ if ((color & leds[i].color) && (access(leds[i].path, R_OK | W_OK) == 0)) {
+ fd = open(leds[i].path, O_RDWR);
+ if (fd < 0) {
+ LOGE("Could not open red led node\n");
+ goto cleanup;
+ }
+ if (on)
+ snprintf(buffer, sizeof(int), "%d\n", 255);
+ else
+ snprintf(buffer, sizeof(int), "%d\n", 0);
+
+ if (write(fd, buffer, strlen(buffer)) < 0)
+ LOGE("Could not write to led node\n");
+cleanup:
+ if (fd >= 0)
+ close(fd);
+ }
+ }
+
+ return 0;
+}
+
+static int set_battery_soc_leds(int soc)
+{
+ int i, color;
+ static int old_color = 0;
+
+ 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;
+}
+
/* current time in milliseconds */
static int64_t curr_time_ms(void)
{
@@ -576,11 +654,20 @@ static void handle_input_state(struct charger *charger, int64_t now)
static void handle_power_supply_state(struct charger *charger, int64_t now)
{
+ static int old_soc = 0;
+ int soc;
+
if (!charger->have_battery_state)
return;
healthd_board_mode_charger_battery_update(batt_prop);
+ soc = get_battery_capacity();
+ if (old_soc != soc) {
+ old_soc = soc;
+ set_battery_soc_leds(soc);
+ }
+
if (!charger->charger_connected) {
/* Last cycle would have stopped at the extreme top of battery-icon