From: lokilee73 Date: Wed, 16 May 2018 07:42:13 +0000 (+0900) Subject: Add voltage and temperature in the structure of battery_info X-Git-Tag: accepted/tizen/unified/20180712.092559^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F88%2F179188%2F6;p=platform%2Fcore%2Fapi%2Fdevice.git Add voltage and temperature in the structure of battery_info In addition, a function to check battery feature is added in APIs. Change-Id: I709e5946d62868371d4d0590804bf4c960a74d14 Signed-off-by: lokilee73 --- diff --git a/doc/device_doc.h b/doc/device_doc.h index 854cd95..881d650 100755 --- a/doc/device_doc.h +++ b/doc/device_doc.h @@ -58,6 +58,19 @@ * It also supports the API for an application to receive the battery events from the system. * To receive the battery event it should be described by the callback function. * + * @section CAPI_SYSTEM_DEVICE_BATTERY_MODULE_OVERVIEW Related Features + * This API is related with the following features:\n + * - %http://tizen.org/feature/battery\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature List. + * + * */ /** diff --git a/include/battery.h b/include/battery.h old mode 100644 new mode 100755 index 07e961c..f28f8ee --- a/include/battery.h +++ b/include/battery.h @@ -80,6 +80,9 @@ typedef enum { DEVICE_BATTERY_PROPERTY_CAPACITY, /**< The battery capacity (0 ~ 100 %) */ DEVICE_BATTERY_PROPERTY_CURRENT_NOW, /**< The battery current (uA) */ DEVICE_BATTERY_PROPERTY_CURRENT_AVERAGE, /**< The average battery current (uA) */ + DEVICE_BATTERY_PROPERTY_VOLTAGE_NOW, /**< The battery voltage (uV) (Since 5.0) */ + DEVICE_BATTERY_PROPERTY_VOLTAGE_AVERAGE, /**< The average battery voltage (uV) (Since 5.0) */ + DEVICE_BATTERY_PROPERTY_TEMPERATURE, /**< The battery temperature (`C) (Since 5.0) */ } device_battery_property_e; @@ -108,6 +111,7 @@ typedef enum { * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device */ int device_battery_get_percent(int *percent); @@ -121,6 +125,7 @@ int device_battery_get_percent(int *percent); * @retval #DEVICE_ERROR_NONE Successful * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device * @see device_add_callback * @see device_remove_callback * @see #DEVICE_CALLBACK_BATTERY_CHARGING @@ -137,6 +142,7 @@ int device_battery_is_charging(bool *charging); * @retval #DEVICE_ERROR_NONE Successful * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device * @see device_battery_level_e * @see device_add_callback * @see device_remove_callback @@ -154,6 +160,7 @@ int device_battery_get_level_status(device_battery_level_e *status); * @retval #DEVICE_ERROR_NONE Successful * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device */ int device_battery_get_health(device_battery_health_e *health); @@ -167,6 +174,7 @@ int device_battery_get_health(device_battery_health_e *health); * @retval #DEVICE_ERROR_NONE Successful * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device */ int device_battery_get_power_source(device_battery_power_source_e *source); @@ -181,6 +189,7 @@ int device_battery_get_power_source(device_battery_power_source_e *source); * @retval #DEVICE_ERROR_NONE Successful * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device */ int device_battery_get_property(device_battery_property_e property, int *value); @@ -194,6 +203,7 @@ int device_battery_get_property(device_battery_property_e property, int *value); * @retval #DEVICE_ERROR_NONE Successful * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device */ int device_battery_get_status(device_battery_status_e *status); diff --git a/src/battery.c b/src/battery.c index 31c0d40..7af1937 100755 --- a/src/battery.c +++ b/src/battery.c @@ -29,6 +29,7 @@ #define METHOD_GET_INFO "GetBatteryInfo" #define INFO_MAX 32 +#define BATTERY_FEATURE "http://tizen.org/feature/battery" struct battery_info { char status[INFO_MAX]; @@ -39,8 +40,28 @@ struct battery_info { int capacity; int current_now; int current_average; + int voltage_now; + int voltage_average; + int temperature; }; +static int is_battery_supported(void) +{ + int ret; + bool battery_avail; + + ret = system_info_get_platform_bool(BATTERY_FEATURE, &battery_avail); + if (ret < 0) { + _E("Failed to get value of battery feature"); + return false; + } else if (ret == 0 && !battery_avail) { + _D("Battery is not supported"); + return false; + } else + return true; +} + + int device_battery_get_percent(int *percent) { int ret; @@ -48,6 +69,10 @@ int device_battery_get_percent(int *percent) if (!percent) return DEVICE_ERROR_INVALID_PARAMETER; + ret = is_battery_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + ret = dbus_method_sync(DEVICED_BUS_NAME, DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, METHOD_GET_PERCENT, NULL, NULL); @@ -68,6 +93,10 @@ int device_battery_is_charging(bool *charging) if (!charging) return DEVICE_ERROR_INVALID_PARAMETER; + ret = is_battery_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &val); /* regard not supported as disconnected */ if (val == -ENOTSUP) @@ -86,6 +115,10 @@ int device_battery_get_level_status(device_battery_level_e *status) if (!status) return DEVICE_ERROR_INVALID_PARAMETER; + ret = is_battery_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, &val); if (ret < 0) return DEVICE_ERROR_OPERATION_FAILED; @@ -123,6 +156,9 @@ static int device_battery_get_info(struct battery_info *info) int capacity; int current_now; int current_average; + int voltage_now; + int voltage_average; + int temperature; if (!info) return DEVICE_ERROR_INVALID_PARAMETER; @@ -136,10 +172,11 @@ static int device_battery_get_info(struct battery_info *info) else if (ret < 0) return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error - g_variant_get(output, "(isssiiiii)", &ret, + g_variant_get(output, "(isssiiiiiiii)", &ret, &status, &health, &power_source, &online, &present, &capacity, - ¤t_now, ¤t_average); + ¤t_now, ¤t_average, &voltage_now, + &voltage_average, &temperature); if (ret < 0) { //LCOV_EXCL_START System Error @@ -156,6 +193,9 @@ static int device_battery_get_info(struct battery_info *info) info->capacity = capacity; info->current_now = current_now; info->current_average = current_average; + info->voltage_now = voltage_now; + info->voltage_average = voltage_average; + info->temperature = temperature; ret = DEVICE_ERROR_NONE; @@ -177,6 +217,10 @@ int device_battery_get_health(device_battery_health_e *health) if (!health) return DEVICE_ERROR_INVALID_PARAMETER; + ret = is_battery_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + ret = device_battery_get_info(&info); if (ret != DEVICE_ERROR_NONE) { _E("Failed to get battery info (%d)", ret); //LCOV_EXCL_LINE Logs @@ -209,6 +253,10 @@ int device_battery_get_power_source(device_battery_power_source_e *source) if (!source) return DEVICE_ERROR_INVALID_PARAMETER; + ret = is_battery_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + ret = device_battery_get_info(&info); if (ret != DEVICE_ERROR_NONE) { _E("Failed to get battery info (%d)", ret); //LCOV_EXCL_LINE Logs @@ -236,6 +284,10 @@ int device_battery_get_property(device_battery_property_e property, int *val) if (!val) return DEVICE_ERROR_INVALID_PARAMETER; + ret = is_battery_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + ret = device_battery_get_info(&info); if (ret != DEVICE_ERROR_NONE) { _E("Failed to get battery info (%d)", ret); //LCOV_EXCL_LINE Logs @@ -252,6 +304,16 @@ int device_battery_get_property(device_battery_property_e property, int *val) case DEVICE_BATTERY_PROPERTY_CURRENT_AVERAGE: *val = info.current_average; break; + case DEVICE_BATTERY_PROPERTY_VOLTAGE_NOW: + *val = info.voltage_now; + break; + case DEVICE_BATTERY_PROPERTY_VOLTAGE_AVERAGE: + *val = info.voltage_average; + break; + case DEVICE_BATTERY_PROPERTY_TEMPERATURE: + *val = info.temperature; + break; + default: return DEVICE_ERROR_INVALID_PARAMETER; } @@ -268,6 +330,10 @@ int device_battery_get_status(device_battery_status_e *status) if (!status) return DEVICE_ERROR_INVALID_PARAMETER; + ret = is_battery_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + ret = device_battery_get_info(&info); if (ret != DEVICE_ERROR_NONE) { _E("Failed to get battery info (%d)", ret); //LCOV_EXCL_LINE Logs