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 "magnetic_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/geomagnetic_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_MAG 0x3
33 #define SRC_STR_MAG "http://tizen.org/sensor/general/magnetic"
35 static sensor_info2_t sensor_info = {
37 type: GEOMAGNETIC_RV_SENSOR,
45 wakeup_supported: false,
49 static required_sensor_s required_sensors[] = {
50 {SRC_ID_ACC, SRC_STR_ACC},
51 {SRC_ID_MAG, SRC_STR_MAG},
54 magnetic_rv_sensor::magnetic_rv_sensor()
61 , m_accuracy(SENSOR_ACCURACY_UNDEFINED)
65 magnetic_rv_sensor::~magnetic_rv_sensor()
69 int magnetic_rv_sensor::get_sensor_info(const sensor_info2_t **info)
75 int magnetic_rv_sensor::get_required_sensors(const required_sensor_s **sensors)
77 *sensors = required_sensors;
81 int magnetic_rv_sensor::update(uint32_t id, sensor_data_t *data, int len)
83 unsigned long long timestamp;
86 m_fusion.push_accel(*data);
87 else if (id == SRC_ID_MAG)
88 m_fusion.push_mag(*data);
90 if (!m_fusion.get_rv(timestamp, m_w, m_x, m_y, m_z))
93 if (timestamp == m_time)
97 m_accuracy = data->accuracy;
99 _D("[rotation_vector] : [%10f] [%10f] [%10f] [%10f]", m_x, m_y, m_z, m_w);
103 int magnetic_rv_sensor::get_data(sensor_data_t **data, int *length)
105 sensor_data_t *sensor_data;
106 sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
108 sensor_data->accuracy = m_accuracy;
109 sensor_data->timestamp = m_time;
110 sensor_data->value_count = 4;
111 sensor_data->values[0] = m_w;
112 sensor_data->values[1] = m_x;
113 sensor_data->values[2] = m_y;
114 sensor_data->values[3] = m_z;
117 *length = sizeof(sensor_data_t);