summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaeminYeom <taemin.yeom@samsung.com>2023-01-17 17:01:17 +0900
committerTaeminYeom <taemin.yeom@samsung.com>2023-01-26 18:20:51 +0900
commitac2cdc50bac2c672bc991b485624494ebe5dc84b (patch)
treef9fbbae783291b9a08840569a2c11bd4d017cb9d
parentc40356bcb837cd6daef3cb9b0feb261219745c9b (diff)
downloadsensor-ac2cdc50bac2c672bc991b485624494ebe5dc84b.tar.gz
sensor-ac2cdc50bac2c672bc991b485624494ebe5dc84b.tar.bz2
sensor-ac2cdc50bac2c672bc991b485624494ebe5dc84b.zip
Add setter and getter sensor handle attribute
Sensor handle attribute is diffrent with sensor listener attribute. Listener attribute is depending on each listener, not sensor. But handle attribute can affect all listeners connecting the sensor. API function -sensor_set_attribute_int : set sensor handle attribute -sensor_get_attribute_int : get sensor handle attribute Enumeration -sensor_handle_attribute_e SENSOR_HANDLE_ATTR_PROXIMITY_SENSITIVITY_LEVEL : attribute of proximity sensor to control sensitivity level. the value should be sensor_proximity_sensitivity_level_e. -sensor_proximity_sensitivity_level_e It can be used to set SENSOR_HANDLE_ATTR_PROXIMITY_SENSITIVITY_LEVEL. SENSOR_PROXIMITY_SENSITIVITY_LEVEL_WEAK : detects close distances. SENSOR_PROXIMITY_SENSITIVITY_LEVEL_MEDIUM : detects middle distances. SENSOR_PROXIMITY_SENSITIVITY_LEVEL_STRONG : detects long distances. Change-Id: I6b736933b426c08fe93ee605587d25984a60b79b Signed-off-by: TaeminYeom <taemin.yeom@samsung.com>
-rw-r--r--include/sensor-internal.h57
-rw-r--r--src/api/api-sensor-internal.cpp58
2 files changed, 115 insertions, 0 deletions
diff --git a/include/sensor-internal.h b/include/sensor-internal.h
index 6c45fc0..52eeaea 100644
--- a/include/sensor-internal.h
+++ b/include/sensor-internal.h
@@ -20,6 +20,8 @@
#include <sensor.h>
#include <hal-sensor-types.h>
+#define CONVERT_TO_ATTR(type, index) ((type) << 8 | 0x80 | (index))
+
#ifdef __cplusplus
extern "C"
{
@@ -34,6 +36,27 @@ typedef enum {
} sensor_type_internel_e;
/**
+ * @brief Enumeration for sensor handle attribute.
+ * @since_tizen 7.0
+ */
+typedef enum
+{
+ SENSOR_HANDLE_ATTR_PROXIMITY_SENSITIVITY_LEVEL =
+ CONVERT_TYPE_ATTR(SENSOR_PROXIMITY, 0x1)
+} sensor_handle_attribute_e;
+
+/**
+ * @brief Enumeration for proximity sensitivity attribute value.
+ * @since_tizen 7.0
+ */
+typedef enum
+{
+ SENSOR_PROXIMITY_SENSITIVITY_LEVEL_WEAK = 1,
+ SENSOR_PROXIMITY_SENSITIVITY_LEVEL_MEDIUM = 2,
+ SENSOR_PROXIMITY_SENSITIVITY_LEVEL_STRONG = 3
+} sensor_proximity_sensitivity_level_e;
+
+/**
* @brief Sets the attribute to a connected sensor.
* @since_tizen 6.5
*
@@ -82,6 +105,40 @@ int sensor_util_get_attribute_int(sensor_type_e type, sensor_attribute_e attr, i
*/
int sensor_listener_get_attribute_int(sensor_listener_h listener, sensor_attribute_e attribute, int *value);
+/**
+ * @brief Sets the attribute to a connected sensor.
+ * @since_tizen 7.0
+ *
+ * @remarks Each attribute has a range of values or use fixed enum.
+ * For example, proximity sensitivity level attribute can be set to
+ * only sensor_proximity_sensitivity_level_e.
+ *
+ * @param[in] sensor a sensor handle of represensting a connected sensor
+ * @param[in] attr an attribute to change
+ * @param[in] value an attribute value
+ *
+ * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
+ */
+int sensor_set_attribute_int(sensor_h sensor, sensor_handle_attribute_e attribute, int value);
+
+/**
+ * @brief Gets the attribute to a connected sensor.
+ * @since_tizen 7.0
+ *
+ * @param[in] sensor a sensor handle of represensting a connected sensor
+ * @param[in] attr an attribute to change
+ * @param[out] value an attribute value
+ *
+ * @return #SENSOR_ERROR_NONE on success, otherwise a negative error value
+ * @retval #SENSOR_ERROR_NONE Successful
+ * @retval #SENSOR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SENSOR_ERROR_OPERATION_FAILED Operation failed
+ */
+int sensor_get_attribute_int(sensor_h sensor, sensor_handle_attribute_e attribute, int *value);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/api/api-sensor-internal.cpp b/src/api/api-sensor-internal.cpp
index cedab98..ed1ddf7 100644
--- a/src/api/api-sensor-internal.cpp
+++ b/src/api/api-sensor-internal.cpp
@@ -120,3 +120,61 @@ int sensor_listener_get_attribute_int(sensor_listener_h listener, sensor_attribu
return SENSOR_ERROR_NONE;
}
+
+static bool is_supported_sensor_handle_attribute(sensor_handle_attribute_e attribute)
+{
+ switch (attribute) {
+ case SENSOR_HANDLE_ATTR_PROXIMITY_SENSITIVITY_LEVEL:
+ return true;
+ default:
+ return false;
+ }
+}
+
+int sensor_set_attribute_int(sensor_h sensor, sensor_handle_attribute_e attribute, int value)
+{
+ if (!sensor) {
+ _E("Invalid sensor handle.");
+ return SENSOR_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!is_supported_sensor_handle_attribute(attribute)) {
+ _E("Invalid sensor handle attribute");
+ return SENSOR_ERROR_INVALID_PARAMETER;
+ }
+
+ int ret = sensord_set_attribute_int(sensor, attribute, value);
+ if (ret == -EINVAL) {
+ _E("Failed to validate the parameter");
+ return SENSOR_ERROR_INVALID_PARAMETER;
+ } else if (ret != SENSOR_ERROR_NONE) {
+ _E("Failed to set attribute");
+ return SENSOR_ERROR_OPERATION_FAILED;
+ }
+
+ return SENSOR_ERROR_NONE;
+}
+
+int sensor_get_attribute_int(sensor_h sensor, sensor_handle_attribute_e attribute, int *value)
+{
+ if (!sensor || !value) {
+ _E("Failed to validate the parameter");
+ return SENSOR_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!is_supported_sensor_handle_attribute(attribute)) {
+ _E("Invalid sensor handle attribute");
+ return SENSOR_ERROR_INVALID_PARAMETER;
+ }
+
+ int ret = sensord_get_attribute_int(sensor, attribute, value);
+ if (ret == -EINVAL) {
+ _E("Failed to validate the parameter");
+ return SENSOR_ERROR_INVALID_PARAMETER;
+ } else if (ret != SENSOR_ERROR_NONE) {
+ _E("Failed to get attribute");
+ return SENSOR_ERROR_OPERATION_FAILED;
+ }
+
+ return SENSOR_ERROR_NONE;
+}