Add setter and getter sensor handle attribute 82/287382/1
authorTaeminYeom <taemin.yeom@samsung.com>
Tue, 17 Jan 2023 08:01:17 +0000 (17:01 +0900)
committerTaeminYeom <taemin.yeom@samsung.com>
Fri, 27 Jan 2023 09:01:31 +0000 (18:01 +0900)
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>
include/sensor-internal.h
src/api/api-sensor-internal.cpp

index 95ed7836f643d1aed14d93205d8d7c4797524020..0c9bf0f83617ce5ecca78eaceb7bed805ddebf8f 100644 (file)
 #include <sensor.h>
 #include <hal-sensor-types.h>
 
+#define CONVERT_TO_ATTR(type, index) ((type) << 8 | 0x80 | (index))
+
 #ifdef __cplusplus
 extern "C"
 {
 #endif
 
+/**
+ * @brief Enumeration for sensor types.
+ * @since_tizen 6.5
+ */
 typedef enum {
        SENSOR_LIDAR = 1000,
 } sensor_type_internel_e;
 
 /**
- * @brief Set the attribute to a connected sensor
+ * @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
  *
  * @param[in] type a sensor type of represensting a connected sensor
  * @param[in] attribute an attribute to change
@@ -76,6 +104,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
index cedab98d25f60dcf4a6912f1b5856d8df1a326d6..ed1ddf775dfdc97e92a8fc23306cb3e04818dcf9 100644 (file)
@@ -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;
+}