From 470035e8b630a00edd313a4ec608436f500c0e00 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 27 Dec 2018 20:35:51 +0900 Subject: [PATCH] Add device_thermal_get_temperature for public API Change-Id: I20855ea5557aef442db52076bcff3c78143bd30e Signed-off-by: lokilee73 --- doc/device_doc.h | 34 +++++++++++++++++++-- include/temperature.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++ src/dbus.h | 4 +++ src/temperature.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 191 insertions(+), 2 deletions(-) create mode 100644 include/temperature.h create mode 100644 src/temperature.c diff --git a/doc/device_doc.h b/doc/device_doc.h index 187b051..e18706d 100644 --- a/doc/device_doc.h +++ b/doc/device_doc.h @@ -29,8 +29,9 @@ * \#include \n * \#include \n * \#include \n - * \#include - * \#include + * \#include \n + * \#include \n + * \#include \n * * @section CAPI_SYSTEM_DEVICE_MODULE_OVERVIEW Overview * The DEVICE API provides functions to control devices or to get status of devices. @@ -42,6 +43,7 @@ * - LED * - Power * - IR + * - Temperature */ /** @@ -223,4 +225,32 @@ * */ +/** + * @ingroup CAPI_SYSTEM_DEVICE_MODULE + * @defgroup CAPI_SYSTEM_DEVICE_THERMAL_MODULE Thermal + * @brief The Temperature API provides functions to get information about the temperature. + * + * @section CAPI_SYSTEM_DEVICE_THERMAL_MODULE_HEADER Required Header + * \#include \n + * + * @section CAPI_SYSTEM_DEVICE_THERMAL_MODULE_OVERVIEW Overview + * The Temperature API provides the way to get the current thermal value such as Application Processor, Communication Processor and Battery. + * + * @section CAPI_SYSTEM_DEVICE_THERMAL_MODULE_OVERVIEW Related Features + * This API is related with the following features:\n + * - %http://tizen.org/feature/thermistor.ap\n + * - %http://tizen.org/feature/thermistor.cp\n + * - %http://tizen.org/feature/thermistor.battery\n + * + * It is recommended to use features in your application for reliability.\n + * + * You can check if the device supports the related features for this API by using System Information, and control your application's actions accordingly.\n + * + * To ensure your application is running only on devices with specific features, please define the features in your manifest file using the manifest editor in the SDK. + * + * More details on using features in your application can be found in the feature element description. + * + * + */ + #endif /* __TIZEN_SYSTEM_DEVICE_DOC_H__ */ diff --git a/include/temperature.h b/include/temperature.h new file mode 100644 index 0000000..38da4e1 --- /dev/null +++ b/include/temperature.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __TIZEN_SYSTEM_TEMPERATURE_H__ +#define __TIZEN_SYSTEM_TEMPERATURE_H__ + + +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_DEVICE_THERMAL_MODULE + * @{ + */ + + +/** + * @brief Enumeration for the device temperature. + * @since_tizen 5.5 + */ +typedef enum +{ + DEVICE_THERMAL_AP, /**< Temperature for Application Processor */ + DEVICE_THERMAL_CP, /**< Temperature for Communication Processor */ + DEVICE_THERMAL_BATTERY, /**< Temperature for Battery */ +} device_thermal_e; + + +/** + * @brief Gets the temperature value. + * @since_tizen 5.5 + * @param[in] type The index of the device + * @param[out] temp The temperature value in degrees Celsius + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + */ +int device_thermal_get_temperature(device_thermal_e type, int *temp); + + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif + + +#endif /* __TIZEN_SYSTEM_TEMPERATURE_H__ */ diff --git a/src/dbus.h b/src/dbus.h index c502284..2ae4d77 100644 --- a/src/dbus.h +++ b/src/dbus.h @@ -58,6 +58,10 @@ #define DEVICED_PATH_IR DEVICED_OBJECT_PATH"/Ir" #define DEVICED_INTERFACE_IR DEVICED_INTERFACE_NAME".ir" +/* Thermal service: operatioins about temperature */ +#define DEVICED_PATH_TEMPERATURE DEVICED_OBJECT_PATH"/Temperature" +#define DEVICED_INTERFACE_TEMPERATURE DEVICED_INTERFACE_NAME".temperature" + struct dbus_int { int *list; int size; diff --git a/src/temperature.c b/src/temperature.c new file mode 100644 index 0000000..12f5c5b --- /dev/null +++ b/src/temperature.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include +#include +#include "common.h" +#include "dbus.h" +#include "temperature.h" + +#define METHOD_GET_TEMPERATURE "GetTemperature" + +#define THERMAL_AP_FEATURE "http://tizen.org/feature/thermistor.ap" +#define THERMAL_CP_FEATURE "http://tizen.org/feature/thermistor.cp" +#define THERMAL_BATTERY_FEATURE "http://tizen.org/feature/thermistor.battery" + +static int is_temperature_supported(device_thermal_e type) +{ + int ret = 0; + bool thermal_avail; + + if (type == DEVICE_THERMAL_AP) + ret = system_info_get_platform_bool(THERMAL_AP_FEATURE, &thermal_avail); + else if (type == DEVICE_THERMAL_CP) + ret = system_info_get_platform_bool(THERMAL_CP_FEATURE, &thermal_avail); + else + ret = system_info_get_platform_bool(THERMAL_BATTERY_FEATURE, &thermal_avail); + if (ret < 0) { + _E("Failed to get value of temp feature : %d", ret); + return false; + } else if (ret == 0 && !thermal_avail) { + _D("Temperature is not supported"); + return false; + } else + return true; +} + +int device_thermal_get_temperature(device_thermal_e type, int *temp) +{ + char *arr[1]; + char str_val[32]; + int ret; + + if (type > DEVICE_THERMAL_BATTERY) + return DEVICE_ERROR_INVALID_PARAMETER; + + ret = is_temperature_supported(type); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + + snprintf(str_val, sizeof(str_val), "%d", type); + arr[0] = str_val; + + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_TEMPERATURE, + DEVICED_INTERFACE_TEMPERATURE, + METHOD_GET_TEMPERATURE, "i", arr); + if (ret < 0) + return errno_to_device_error(ret); + + *temp = ret; + return DEVICE_ERROR_NONE; +} + -- 2.7.4