From b55fe6104e3b6dc10082ba48346370dfb7d89ebd Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 27 Jan 2022 15:02:15 +0900 Subject: [PATCH] battery: convert ONLINE property value to standard one Change-Id: I0a98cd552865437cf4b45316e256d75375aeaaa4 Signed-off-by: Youngjae Cho --- hw/battery/battery.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/hw/battery/battery.c b/hw/battery/battery.c index 3a3d962..70e9812 100644 --- a/hw/battery/battery.c +++ b/hw/battery/battery.c @@ -87,6 +87,7 @@ static void uevent_delivered(struct udev_device *dev) struct battery_info info; char *val; int ret; + int temp; _I("POWER_SUPPLY uevent is delivered"); @@ -113,7 +114,19 @@ static void uevent_delivered(struct udev_device *dev) val = (char *)udev_device_get_property_value(dev, "POWER_SUPPLY_ONLINE"); if (!val) return; - info.online = atoi(val); + /* + * Convert the value to standard value, 0 or 1. + * POWER_SUPPLY_TYPE_UNKNOWN=0, -> 0(disconnected) + * POWER_SUPPLY_TYPE_BATTERY=1, -> 0(disconnected) + * POWER_SUPPLY_TYPE_UPS=2, -> 1(connected) + * POWER_SUPPLY_TYPE_MAINS=3, -> 1(connected) + * POWER_SUUPLY_TYPE_USB=4 -> 1(connected) + */ + temp = atoi(val); + if (temp == 1 || temp == 0) + info.online = 0; + else + info.online = 1; val = (char *)udev_device_get_property_value(dev, "POWER_SUPPLY_PRESENT"); if (!val) -- 2.7.4