4 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include "rv_sensor.h"
22 #include <sensor_log.h>
23 #include <sensor_types.h>
24 #include <fusion_util.h>
26 #define NAME_SENSOR "http://tizen.org/sensor/general/rotation_vector/tizen_default"
27 #define NAME_VENDOR "tizen.org"
29 #define SRC_ID_ACC 0x1
30 #define SRC_STR_ACC "http://tizen.org/sensor/general/accelerometer"
32 #define SRC_ID_GYRO 0x2
33 #define SRC_STR_GYRO "http://tizen.org/sensor/general/gyroscope"
35 #define SRC_ID_MAG 0x3
36 #define SRC_STR_MAG "http://tizen.org/sensor/general/magnetic"
38 static sensor_info2_t sensor_info = {
40 type: ROTATION_VECTOR_SENSOR,
48 wakeup_supported: false,
52 static required_sensor_s required_sensors[] = {
53 {SRC_ID_ACC, SRC_STR_ACC},
54 {SRC_ID_GYRO, SRC_STR_GYRO},
55 {SRC_ID_MAG, SRC_STR_MAG},
58 rv_sensor::rv_sensor()
65 , m_accuracy(SENSOR_ACCURACY_UNDEFINED)
69 rv_sensor::~rv_sensor()
73 int rv_sensor::get_sensor_info(const sensor_info2_t **info)
79 int rv_sensor::get_required_sensors(const required_sensor_s **sensors)
81 *sensors = required_sensors;
85 int rv_sensor::update(uint32_t id, sensor_data_t *data, int len)
87 unsigned long long timestamp;
90 m_fusion.push_accel(*data);
91 else if (id == SRC_ID_MAG)
92 m_fusion.push_mag(*data);
93 else if (id == SRC_ID_GYRO)
94 m_fusion.push_gyro(*data);
96 if (!m_fusion.get_rv(timestamp, m_w, m_x, m_y, m_z))
99 if (timestamp == m_time)
103 m_accuracy = data->accuracy;
105 _D("[rotation_vector] : [%10f] [%10f] [%10f] [%10f]", m_x, m_y, m_z, m_w);
109 int rv_sensor::get_data(sensor_data_t **data, int *length)
111 sensor_data_t *sensor_data;
112 sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
113 retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory");
115 sensor_data->accuracy = m_accuracy;
116 sensor_data->timestamp = m_time;
117 sensor_data->value_count = 4;
118 sensor_data->values[0] = m_w;
119 sensor_data->values[1] = m_x;
120 sensor_data->values[2] = m_y;
121 sensor_data->values[3] = m_z;
124 *length = sizeof(sensor_data_t);