Use hal-api-sensor instead of legacy interface
authorBoram Bae <boram21.bae@samsung.com>
Wed, 27 Jan 2021 04:25:51 +0000 (13:25 +0900)
committerBoram Bae <boram21.bae@samsung.com>
Wed, 27 Jan 2021 04:25:51 +0000 (13:25 +0900)
* This change is for Tizen Next-HAL
* Now, all implementations of sensor device inherit sensor device interface of the hal-api-sensor
* Move sensor_hal and sensor_hal_types to hal-api-sensor
* Name sensor_loader`s existing HAL as Legacy HAL
* Change an install path for libsensorhub-hal to /hal/lib/sensorhub/

Change-Id: I4c4df4b7e72eebcb86116ea49c7addf12b95b573
Signed-off-by: Boram Bae <boram21.bae@samsung.com>
15 files changed:
CMakeLists.txt
packaging/sensor-hal-emulator.spec
src/accel/accel_device.h
src/create.cpp [deleted file]
src/geomag/geomag_device.h
src/gyro/gyro_device.h
src/gyro_uncal/gyro_uncal_device.h
src/hal-backend-sensor.cpp [new file with mode: 0644]
src/hrm/hrm_device.h
src/light/light_device.h
src/pressure/pressure_device.cpp
src/pressure/pressure_device.h
src/proxi/proxi_device.h
src/sensorhub/CMakeLists.txt
src/ultraviolet/uv_device.h

index 16741d8..2f7c395 100644 (file)
@@ -2,6 +2,12 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 PROJECT(sensor-hal-emulator CXX)
 INCLUDE(GNUInstallDirs)
 
+SET(LIBRARY_NAME "hal-backend-sensor")
+SET(HAL_LIBDIR ${CMAKE_HAL_LIBDIR_PREFIX})
+SET(HAL_LICENSEDIR ${CMAKE_HAL_LICENSEDIR_PREFIX})
+SET(DEPENDENTS "dlog hal-api-common hal-api-sensor")
+
+
 SET(ACCEL "ON")
 SET(GYRO "ON")
 SET(GYRO_UNCAL "OFF")
@@ -31,10 +37,10 @@ MESSAGE("FLAGS: ${CMAKE_CXX_FLAGS}")
 MESSAGE("FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
 
 # Internal Debugging Options
-#ADD_DEFINITIONS(-Wall -g -D_DEBUG)
+ADD_DEFINITIONS(-Wall -g -D_DEBUG)
 
 INCLUDE(FindPkgConfig)
-PKG_CHECK_MODULES(HAL_PKGS REQUIRED dlog)
+PKG_CHECK_MODULES(HAL_PKGS REQUIRED ${DEPENDENTS})
 
 FOREACH(flag ${HAL_PKGS_CFLAGS})
        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
@@ -152,7 +158,8 @@ ADD_SUBDIRECTORY(src/sensorhub)
 ENDIF()
 
 MESSAGE("Sources: ${SRCS}")
-ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${HAL_PKGS_LDFLAGS})
+ADD_LIBRARY(${LIBRARY_NAME} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${HAL_PKGS_LDFLAGS})
 
-INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensor)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.APLv2 DESTINATION ${HAL_LICENSEDIR}/${PROJECT_NAME})
+INSTALL(TARGETS ${LIBRARY_NAME} DESTINATION ${HAL_LIBDIR} COMPONENT RuntimeLibraries)
index 71074ec..b12165c 100644 (file)
@@ -12,7 +12,8 @@ ExcludeArch: %{arm} aarch64
 
 BuildRequires:  cmake
 BuildRequires:  pkgconfig(dlog)
-BuildRequires:  sensor-hal-devel
+BuildRequires:  pkgconfig(hal-api-common)
+BuildRequires:  pkgconfig(hal-api-sensor)
 
 %ifarch %ix86
 %define _arch x86
@@ -29,7 +30,7 @@ Emulator Sensor HAL
 %setup -q
 
 %build
-%cmake . -DBUILD_ARCH=%{_arch}
+%cmake . -DBUILD_ARCH=%{_arch} -DCMAKE_HAL_LIBDIR_PREFIX=%{_hal_libdir} -DCMAKE_HAL_LICENSEDIR_PREFIX=%{_hal_licensedir}
 make %{?_smp_mflags}
 
 %install
@@ -50,5 +51,6 @@ install -m 0644 %SOURCE2 %{buildroot}%{_libdir}/udev/rules.d
 %manifest packaging/%{name}.manifest
 %{_libdir}/udev/rules.d/99-sensor.rules
 %{_libdir}/udev/rules.d/99-sensorhub.rules
-%{_libdir}/sensor/*.so
-%license LICENSE.APLv2
+%{_hal_libdir}/*.so*
+%{_hal_libdir}/sensorhub/*.so*
+%{_hal_licensedir}/%{name}/LICENSE.APLv2
index 6c4b02b..0566fd9 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef _ACCEL_DEVICE_H_
 #define _ACCEL_DEVICE_H_
 
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 #include <string>
 #include <vector>
 #include <functional>
diff --git a/src/create.cpp b/src/create.cpp
deleted file mode 100644 (file)
index 17341e9..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * 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/sensor_hal.h>
-#include <sensor_log.h>
-#include <vector>
-
-#include "accel/accel_device.h"
-#include "gyro/gyro_device.h"
-#include "geomag/geomag_device.h"
-#include "pressure/pressure_device.h"
-#include "ultraviolet/uv_device.h"
-#include "light/light_device.h"
-#include "proxi/proxi_device.h"
-#include "hrm/hrm_device.h"
-
-static std::vector<sensor_device_t> devs;
-
-template<typename _sensor>
-void create_sensor(const char *name)
-{
-       sensor_device *instance = NULL;
-       try {
-               instance = new _sensor;
-       } catch (std::exception &e) {
-               ERR("Failed to create %s sensor device, exception: %s", name, e.what());
-               return;
-       } catch (int err) {
-               _ERRNO(err, _E, "Failed to create %s sensor device", name);
-               return;
-       }
-
-       devs.push_back(instance);
-}
-
-extern "C" int create(sensor_device_t **devices)
-{
-       create_sensor<accel_device>("Accelerometer");
-       create_sensor<gyro_device>("Gyroscope");
-       create_sensor<geomag_device>("Geomagnetic");
-       create_sensor<pressure_device>("Pressure");
-       create_sensor<uv_device>("Ultra Violet");
-       create_sensor<light_device>("Light");
-       create_sensor<proxi_device>("Proximity");
-       create_sensor<hrm_device>("HRM");
-
-       *devices = &devs[0];
-       return devs.size();
-}
index eba671f..c46a2ee 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef _GEOMAG_DEVICE_H_
 #define _GEOMAG_DEVICE_H_
 
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 #include <string>
 #include <vector>
 #include <functional>
index 994c1b2..e811d18 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef _GYRO_DEVICE_H_
 #define _GYRO_DEVICE_H_
 
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 #include <string>
 #include <vector>
 #include <functional>
index 8f0b30d..5ee1f99 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef _GYRO_UNCAL_DEVICE_H_
 #define _GYRO_UNCAL_DEVICE_H_
 
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 #include <string>
 #include <vector>
 #include <functional>
diff --git a/src/hal-backend-sensor.cpp b/src/hal-backend-sensor.cpp
new file mode 100644 (file)
index 0000000..e9ed041
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * 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 <errno.h>
+#include <hal/hal-sensor-interface.h>
+#include <sensor_log.h>
+#include <stdlib.h>
+
+#include <vector>
+
+#include "accel/accel_device.h"
+#include "geomag/geomag_device.h"
+#include "gyro/gyro_device.h"
+#include "hrm/hrm_device.h"
+#include "light/light_device.h"
+#include "pressure/pressure_device.h"
+#include "proxi/proxi_device.h"
+#include "ultraviolet/uv_device.h"
+
+static std::vector<sensor_device_t> devs;
+
+template <typename _sensor>
+void create_sensor(const char *name) {
+  sensor_device *instance = NULL;
+  try {
+    instance = new _sensor;
+  } catch (std::exception &e) {
+    ERR("Failed to create %s sensor device, exception: %s", name, e.what());
+    return;
+  } catch (int err) {
+    _ERRNO(err, _E, "Failed to create %s sensor device", name);
+    return;
+  }
+
+  devs.push_back(instance);
+}
+
+static int sensor_emulator_create(sensor_device_t **devices) {
+  create_sensor<accel_device>("Accelerometer");
+  create_sensor<gyro_device>("Gyroscope");
+  create_sensor<geomag_device>("Geomagnetic");
+  create_sensor<pressure_device>("Pressure");
+  create_sensor<uv_device>("Ultra Violet");
+  create_sensor<light_device>("Light");
+  create_sensor<proxi_device>("Proximity");
+  create_sensor<hrm_device>("HRM");
+
+  *devices = &devs[0];
+  return devs.size();
+}
+
+static int sensor_emulator_init(void **data) {
+  _I("init hal backend sensor");
+  hal_backend_sensor_funcs *funcs;
+
+  funcs =
+      (hal_backend_sensor_funcs *)calloc(1, sizeof(hal_backend_sensor_funcs));
+  if (!funcs) return -ENOMEM;
+
+  funcs->create = sensor_emulator_create;
+
+  *data = (void *)funcs;
+
+  return 0;
+}
+
+static int sensor_emulator_exit(void *data) {
+  if (!data) return -EINVAL;
+  free(data);
+
+  return 0;
+}
+
+extern "C" hal_backend hal_backend_sensor_data = {
+    .name = "sensor-emulator",
+    .vendor = "Tizen",
+    .abi_version = HAL_ABI_VERSION_TIZEN_6_5,
+    .init = sensor_emulator_init,
+    .exit = sensor_emulator_exit,
+};
index 6600f05..f6d8406 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef _HRM_DEVICE_H_
 #define _HRM_DEVICE_H_
 
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 #include <string>
 #include <vector>
 #include <functional>
index 1a8e916..21c0839 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef _LIGHT_DEVICE_H_
 #define _LIGHT_DEVICE_H_
 
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 #include <string>
 #include <vector>
 #include <functional>
index 0ed56d8..c314db6 100755 (executable)
@@ -236,7 +236,7 @@ bool pressure_device::update_value_input_event(void)
 
        m_fired_time = fired_time;
 
-       _D("m_pressure = %d, sea_level = %d, temperature = %d, time = %lluus", m_pressure, m_sea_level_pressure, m_temperature, m_fired_time);
+       _D("m_pressure = %d, sea_level = %f, temperature = %d, time = %lluus", m_pressure, m_sea_level_pressure, m_temperature, m_fired_time);
 
        return true;
 }
@@ -283,6 +283,7 @@ void pressure_device::raw_to_base(sensor_data_t *data)
        m_sea_level_pressure = data->values[1] * SEA_LEVEL_RESOLUTION;
        data->values[1] = pressure_to_altitude(data->values[0]);
        data->values[2] = data->values[2] * TEMPERATURE_RESOLUTION + TEMPERATURE_OFFSET;
+       _D("data->values[0] %f", data->values[0]);
 }
 
 float pressure_device::pressure_to_altitude(float pressure)
index c46b320..52679a0 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef _PRESSURE_DEVICE_H_
 #define _PRESSURE_DEVICE_H_
 
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 #include <string>
 #include <vector>
 #include <functional>
index f9cf22b..29114d1 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef _PROXI_DEVICE_H_
 #define _PROXI_DEVICE_H_
 
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 #include <string>
 #include <vector>
 #include <functional>
index 01c0254..a53a731 100644 (file)
@@ -1,8 +1,8 @@
 IF("${BUILD_ARCH}" STREQUAL "x86")
-       INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/libsensorhub-hal.i586.so DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensor)
+       INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/libsensorhub-hal.i586.so DESTINATION ${HAL_LIBDIR}/sensorhub/ COMPONENT RuntimeLibraries)
 ENDIF()
 
 IF("${BUILD_ARCH}" STREQUAL "x86_64")
-       INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/libsensorhub-hal.x86_64.so DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensor)
+       INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/libsensorhub-hal.x86_64.so DESTINATION ${HAL_LIBDIR}/sensorhub/ COMPONENT RuntimeLibraries)
 ENDIF()
 
index 635ff82..0dd8859 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef _UV_DEVICE_H_
 #define _UV_DEVICE_H_
 
-#include <sensor/sensor_hal.h>
+#include <hal/hal-sensor-interface.h>
 #include <string>
 #include <vector>
 #include <functional>