From 462a6787661c293f7b9383340f1407366f91797c Mon Sep 17 00:00:00 2001 From: "Christopher N. Hesse" Date: Fri, 18 Nov 2016 18:56:17 +0100 Subject: power: Simplify read_panel_brightness() Overengineering. Change-Id: Ifef79a7e8f2249fdd22099a043303f9686ac014b --- power/power.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/power/power.c b/power/power.c index 364a563..f80f3e8 100644 --- a/power/power.c +++ b/power/power.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -124,11 +125,14 @@ static void sysfs_write(const char *path, char *s) close(fd); } -static unsigned int read_panel_brightness() { - unsigned int i, ret = 0; +static int read_panel_brightness() { + int ret = 0; int read_status; // brightness can range from 0 to 255, so max. 3 chars + '\0' char panel_brightness[4]; + // for strtol + char *dummy; + const int base = 10; read_status = sysfs_read(PANEL_BRIGHTNESS, panel_brightness, sizeof(PANEL_BRIGHTNESS)); if (read_status < 0) { @@ -136,12 +140,7 @@ static unsigned int read_panel_brightness() { return -1; } - for (i = 0; i < (sizeof(panel_brightness) / sizeof(panel_brightness[0])); i++) { - if (isdigit(panel_brightness[i])) { - ret += (panel_brightness[i] - '0'); - } - } - + ret = strtol(panel_brightness, &dummy, base); ALOGV("%s: Panel brightness is: %d", __func__, ret); return ret; -- cgit v1.2.3