From ed2c92540c01ed9d51a25736feb2169cd06ee70b Mon Sep 17 00:00:00 2001 From: PaulK Date: Mon, 26 Mar 2012 23:02:06 +0200 Subject: playlpm: added low brightness and various fixes --- playlpm/playlpm.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/playlpm/playlpm.c b/playlpm/playlpm.c index dec2691..4dfa0e1 100644 --- a/playlpm/playlpm.c +++ b/playlpm/playlpm.c @@ -94,7 +94,8 @@ int lpm_battery_level(void) int level = -1; int fd = -1; - char value[2]; + int c = -1; + char value[3]; char status[6]; fd = open("/sys/class/power_supply/battery/capacity", O_RDONLY); @@ -104,7 +105,8 @@ int lpm_battery_level(void) return 0; } - read(fd, value, sizeof(value)); + c = read(fd, value, sizeof(value)); + value[c] = '\0'; close(fd); @@ -140,11 +142,37 @@ int lpm_battery_level(void) return level; } +void lpm_backlight_brightness(char *brightness) +{ + int fd = -1; + int length; + + if(brightness == NULL) + { + LOGE("brightness isn't set, aborting"); + return; + } + + fd = open("/sys/class/backlight/s5p_bl/brightness", O_WRONLY); + if(fd < 0) + { + LOGE("Failed to open brightness node, aborting"); + return; + } + + length = strlen(brightness); + + LOGD("Setting brightness to: %s", brightness); + write(fd, brightness, length); + + close(fd); +} + // This is the main loop function, where we check battery state void lpm_loop(void) { int level = -1; - int l; + int l = -1; while(1) { @@ -152,7 +180,11 @@ void lpm_loop(void) // Only refresh the image if the battery level changed if(level != l) + { + // Setting brightness to a very low level to reduce battery usage while charging + lpm_backlight_brightness("5"); lpm_display_level(level); + } l = level; -- cgit v1.1