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 "linear_accel_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/linear_accel/linear_accel"
27 #define NAME_VENDOR "Samsung"
29 #define SRC_ID_ACC 0x1
30 #define SRC_STR_ACC "http://tizen.org/sensor/accelerometer"
32 #define SRC_ID_GRAVITY 0x2
33 #define SRC_STR_GRAVITY "http://tizen.org/sensor/gravity"
35 #define GRAVITY 9.80665
37 static sensor_info2_t sensor_info = {
39 type: LINEAR_ACCEL_SENSOR,
47 wakeup_supported: false,
51 static required_sensor_s required_sensors[] = {
52 {SRC_ID_ACC, SRC_STR_ACC},
53 {SRC_ID_GRAVITY, SRC_STR_GRAVITY},
56 linear_accel_sensor::linear_accel_sensor()
68 linear_accel_sensor::~linear_accel_sensor()
72 int linear_accel_sensor::get_sensor_info(const sensor_info2_t **info)
78 int linear_accel_sensor::get_required_sensors(const required_sensor_s **sensors)
80 *sensors = required_sensors;
84 int linear_accel_sensor::update(uint32_t id, sensor_data_t *data, int len)
86 if (id == SRC_ID_GRAVITY) {
87 m_gx = data->values[0];
88 m_gy = data->values[1];
89 m_gz = data->values[2];
90 } else if (id == SRC_ID_ACC) {
91 m_accuracy = data->accuracy;
92 m_time = data->timestamp;
93 m_x = data->values[0] - m_gx;
94 m_y = data->values[1] - m_gy;
95 m_z = data->values[2] - m_gz;
100 return OP_ERROR; /* skip */
103 int linear_accel_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 = SENSOR_ACCURACY_GOOD;
109 sensor_data->timestamp = m_time;
110 sensor_data->value_count = 3;
111 sensor_data->values[0] = m_x;
112 sensor_data->values[1] = m_y;
113 sensor_data->values[2] = m_z;
116 *length = sizeof(sensor_data_t);