4 * Copyright (c) 2017 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 "auto_rotation_sensor.h"
22 #include <sensor_log.h>
23 #include <sensor_types.h>
25 #include "auto_rotation_alg_emul.h"
27 #define NAME_SENSOR "http://tizen.org/sensor/general/auto_rotation/tizen_default"
28 #define NAME_VENDOR "tizen.org"
30 #define SRC_ID_ACC 0x1
31 #define SRC_STR_ACC "http://tizen.org/sensor/general/accelerometer"
33 static sensor_info2_t sensor_info = {
35 type: AUTO_ROTATION_SENSOR,
38 min_range: AUTO_ROTATION_DEGREE_UNKNOWN,
39 max_range: AUTO_ROTATION_DEGREE_270,
43 wakeup_supported: false,
47 static required_sensor_s required_sensors[] = {
48 {SRC_ID_ACC, SRC_STR_ACC}
51 auto_rotation_sensor::auto_rotation_sensor()
60 auto_rotation_sensor::~auto_rotation_sensor()
65 bool auto_rotation_sensor::init(void)
68 retvm_if(!m_alg, false, "Not supported");
69 retvm_if(!m_alg->open(), false, "Cannot open auto rotation algorithm");
73 void auto_rotation_sensor::deinit(void)
78 int auto_rotation_sensor::get_sensor_info(const sensor_info2_t **info)
84 int auto_rotation_sensor::get_required_sensors(const required_sensor_s **sensors)
86 *sensors = required_sensors;
90 int auto_rotation_sensor::update(uint32_t id, sensor_data_t *data, int len)
94 acc[0] = data->values[0];
95 acc[1] = data->values[1];
96 acc[2] = data->values[2];
98 if (!m_alg->get_rotation(acc, data->timestamp, m_rotation, rotation))
101 _D("Rotation: %d, ACC[0]: %f, ACC[1]: %f, ACC[2]: %f",
102 rotation, data->values[0], data->values[1], data->values[2]);
104 m_rotation = rotation;
105 m_rotation_time = data->timestamp;
110 int auto_rotation_sensor::get_data(sensor_data_t **data, int *length)
112 sensor_data_t *sensor_data;
113 sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
115 sensor_data->accuracy = SENSOR_ACCURACY_GOOD;
116 sensor_data->timestamp = m_rotation_time;
117 sensor_data->values[0] = m_rotation;
118 sensor_data->value_count = 1;
121 *length = sizeof(sensor_data_t);
126 int auto_rotation_sensor::start(observer_h ob)
128 m_rotation = AUTO_ROTATION_DEGREE_UNKNOWN;
134 /* if OP_DEFAULT is returned,
135 * this function is not called anymore before stop() is called */
139 int auto_rotation_sensor::stop(observer_h ob)
143 /* if OP_DEFAULT is returned,
144 * this function is not called anymore before start() is called */
148 int auto_rotation_sensor::set_interval(observer_h ob, int32_t &interval)
155 auto_rotation_alg *auto_rotation_sensor::get_alg(void)
157 auto_rotation_alg *alg = new(std::nothrow) auto_rotation_alg_emul();
158 retvm_if(!alg, NULL, "Failed to allocate memory");