2 * Copyright (c) 2016 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 <sensor_log.h>
19 #include <fusion_sensor.h>
22 #ifdef ENABLE_AUTO_ROTATION
23 #include "auto_rotation/auto_rotation_sensor.h"
26 #include "gravity/gravity_lowpass_sensor.h"
27 #include "gravity/gravity_comp_sensor.h"
29 #ifdef ENABLE_LINEAR_ACCEL
30 #include "linear_accel/linear_accel_sensor.h"
32 #ifdef ENABLE_ROTATION_VECTOR
33 #include "rotation_vector/rv_sensor.h"
34 #include "rotation_vector/magnetic_rv_sensor.h"
35 #include "rotation_vector/gyro_rv_sensor.h"
37 #ifdef ENABLE_ORIENTATION
38 #include "orientation/orientation_sensor.h"
41 static std::vector<fusion_sensor_t> sensors;
43 template<typename _sensor>
44 void create_sensor(const char *name)
46 fusion_sensor *instance = NULL;
48 instance = new _sensor;
49 } catch (std::exception &e) {
50 _E("Failed to create %s sensor, exception: %s", name, e.what());
53 _ERRNO(err, _E, "Failed to create %s sensor device", name);
57 sensors.push_back(instance);
60 extern "C" int create(fusion_sensor_t **fsensors)
62 #ifdef ENABLE_AUTO_ROTATION
63 create_sensor<auto_rotation_sensor>("Accelerometer");
67 create_sensor<gravity_lowpass_sensor>("Gravity(Lowpass)");
68 create_sensor<gravity_comp_sensor>("Gravity(Complementary)");
71 #ifdef ENABLE_LINEAR_ACCEL
72 create_sensor<linear_accel_sensor>("Linear Acceleration Sensor");
75 #ifdef ENABLE_ROTATION_VECTOR
76 create_sensor<rv_sensor>("Rotation Vector Sensor");
77 create_sensor<magnetic_rv_sensor>("Magnetic Rotation Vector Sensor");
78 create_sensor<gyro_rv_sensor>("Gyroscope Rotation Vector Sensor");
81 #ifdef ENABLE_ORIENTATION
82 create_sensor<orientation_sensor>("Orientation Sensor");
85 *fsensors = &sensors[0];
86 return sensors.size();