#include <sensor.h>
#include <hal-sensor-types.h>
+#define CONVERT_TO_ATTR(type, index) ((type) << 8 | 0x80 | (index))
+
#ifdef __cplusplus
extern "C"
{
} 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
*
*/
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
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;
+}