# Compile Source files
SET(SOURCES src/sensor.cpp
src/sensor_provider.cpp
+ src/sensor-internal.cpp
src/geomagnetic_field.c
src/fusion_util.c)
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER} CLEAN_DIRECT_OUTPUT 1)
CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
-INSTALL(FILES include/sensor.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor)
+INSTALL(FILES include/sensor.h include/sensor-internal.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor)
INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
ADD_SUBDIRECTORY(test/stress_test)
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <sensor.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+typedef enum {
+ SENSOR_ATTRIBUTE_INTERNAL_START = 10000,
+ SENSOR_ATTRIBUTE_POWER_STATE,
+} sensor_attribute_internal_e;
+
+/**
+ * @brief Set the attribute to a connected sensor
+ *
+ * @param[in] type a sensor type of represensting a connected sensor
+ * @param[in] attribute an attribute to change
+ * @param[in] value an attribute value
+ * @return 0 on success, otherwise a negative error value
+ * @retval 0 Successful
+ * @retval -EINVAL Invalid parameter
+ * @retval -EPERM Operation not permitted
+ */
+int sensor_util_set_attribute_int(sensor_type_e type, sensor_attribute_internal_e attr, int value);
+
+/**
+ * @brief Get the attribute to a connected sensor
+ *
+ * @param[in] type a sensor type of represensting a connected sensor
+ * @param[in] attribute an attribute to get value
+ * @param[out] value an attribute value
+ * @return 0 on success, otherwise a negative error value
+ * @retval 0 Successful
+ * @retval -EINVAL Invalid parameter
+ * @retval -EPERM Operation not permitted
+ */
+int sensor_util_get_attribute_int(sensor_type_e type, sensor_attribute_internal_e attr, int *value);
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <sensor-internal.h>
+
+#include <errno.h>
+#include <sensor.h>
+#include <sensor_internal.h>
+
+int sensor_util_set_attribute_int(sensor_type_e type, sensor_attribute_internal_e attr, int value)
+{
+ sensor_t sensor;
+ int ret = 0;
+ int handle = 0;
+ ret = sensord_get_default_sensor((sensor_type_t) type, &sensor);
+ if (ret < 0) {
+ return ret;
+ }
+
+ handle = sensord_connect(sensor);
+ if (handle < 0) {
+ return handle;
+ }
+
+ ret = sensord_set_attribute_int(handle, attr, value);
+ if (ret < 0) {
+ return ret;
+ }
+
+ ret = sensord_disconnect(handle);
+ if (ret < 0) {
+ return ret;
+ }
+
+ return 0;
+}
+
+int sensor_util_get_attribute_int(sensor_type_e type, sensor_attribute_internal_e attr, int *value)
+{
+ if (!value)
+ return -EINVAL;
+
+ sensor_t sensor;
+ int ret = 0;
+ int handle = 0;
+ ret = sensord_get_default_sensor((sensor_type_t) type, &sensor);
+ if (ret < 0) {
+ return ret;
+ }
+
+ handle = sensord_connect(sensor);
+ if (handle < 0) {
+ return handle;
+ }
+
+ ret = sensord_get_attribute_int(handle, attr, value);
+ if (ret < 0) {
+ return ret;
+ }
+
+ ret = sensord_disconnect(handle);
+ if (ret < 0) {
+ return ret;
+ }
+
+ return 0;
+}