Add setter and getter sensor handle attribute 76/286976/6
authorTaeminYeom <taemin.yeom@samsung.com>
Tue, 17 Jan 2023 08:01:17 +0000 (17:01 +0900)
committerTaeminYeom <taemin.yeom@samsung.com>
Thu, 26 Jan 2023 09:20:51 +0000 (18:20 +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 6c45fc0..52eeaea 100644 (file)
@@ -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
index cedab98..ed1ddf7 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;
+}