2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <hal/hal-sensor-interface.h>
19 #include <sensor_log.h>
24 #include "accel/accel_device.h"
25 #include "proxi/proxi_device.h"
26 #include "sensorhub/sensorhub.h"
28 static std::vector<sensor_device_t> devs;
30 template <typename _sensor>
31 void create_sensor(const char *name) {
32 sensor_device *instance = NULL;
34 instance = new _sensor;
35 } catch (std::exception &e) {
36 ERR("Failed to create %s sensor device, exception: %s", name, e.what());
39 _ERRNO(err, _E, "Failed to create %s sensor device", name);
43 devs.push_back(instance);
46 static int sensor_tm1_create(sensor_device_t **devices) {
48 create_sensor<accel_device>("Accelerometer");
50 #ifdef ENABLE_PROXIMITY
51 create_sensor<proxi_device>("Proximity");
53 #ifdef ENABLE_SENSORHUB
54 create_sensor<sensorhub_device>("Sensorhub");
61 static int sensor_tm1_init(void **data) {
62 _I("init hal backend sensor");
63 hal_backend_sensor_funcs *funcs;
66 (hal_backend_sensor_funcs *)calloc(1, sizeof(hal_backend_sensor_funcs));
67 if (!funcs) return -ENOMEM;
69 funcs->create = sensor_tm1_create;
71 *data = (void *)funcs;
76 static int sensor_tm1_exit(void *data) {
77 if (!data) return -EINVAL;
83 extern "C" hal_backend hal_backend_sensor_data = {
86 .abi_version = HAL_ABI_VERSION_TIZEN_6_5,
87 .init = sensor_tm1_init,
88 .exit = sensor_tm1_exit,