From: taemin.yeom Date: Thu, 16 Sep 2021 07:53:04 +0000 (+0900) Subject: Support new orientation sensor types X-Git-Tag: submit/tizen/20210916.080205^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7591c7fe1e98195ad1f13038d1adbae732ab92ed;p=platform%2Fcore%2Fsystem%2Fsensord.git Support new orientation sensor types - GYROSCOPE_ORIENTATION_SENSOR : based on gyroscope_rotation_vector - GEOMAGNETIC_ORIENTATION_SENSOR : based on geomagnetic_rotration_vector Change-Id: I604e4bb772274660be31077f30a3cdb051c9d342 Signed-off-by: taemin.yeom --- diff --git a/src/fusion-sensor/create.cpp b/src/fusion-sensor/create.cpp index 241a4cd4..1d996fe1 100644 --- a/src/fusion-sensor/create.cpp +++ b/src/fusion-sensor/create.cpp @@ -36,6 +36,8 @@ #endif #ifdef ENABLE_ORIENTATION #include "orientation/orientation_sensor.h" +#include "orientation/magnetic_orientation_sensor.h" +#include "orientation/gyro_orientation_sensor.h" #endif #ifdef ENABLE_PEDOMETER #include "pedometer/pedometer_sensor.h" @@ -87,6 +89,8 @@ extern "C" int create(fusion_sensor_t **fsensors) #ifdef ENABLE_ORIENTATION create_sensor("Orientation Sensor"); + create_sensor("Magnetic Orientation Sensor"); + create_sensor("Gyroscope Orientation Sensor"); #endif #ifdef ENABLE_PEDOMETER diff --git a/src/fusion-sensor/orientation/gyro_orientation_sensor.cpp b/src/fusion-sensor/orientation/gyro_orientation_sensor.cpp new file mode 100644 index 00000000..019162d6 --- /dev/null +++ b/src/fusion-sensor/orientation/gyro_orientation_sensor.cpp @@ -0,0 +1,111 @@ +/* + * sensord + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "gyro_orientation_sensor.h" + +#include +#include +#include + +#define NAME_SENSOR "http://tizen.org/sensor/general/gyroscope_orientation/tizen_default" +#define NAME_VENDOR "tizen.org" +#define SRC_ID_RV 0x1 +#define SRC_STR_RV "http://tizen.org/sensor/general/gyroscope_rotation_vector" + +static sensor_info2_t sensor_info = { + id: 0x1, + type: GYROSCOPE_ORIENTATION_SENSOR, + uri: NAME_SENSOR, + vendor: NAME_VENDOR, + min_range: -180, + max_range: 360, + resolution: 0.01, + min_interval: 10, + max_batch_count: 0, + wakeup_supported: false, + privilege:"", +}; + +static required_sensor_s required_sensors[] = { + {SRC_ID_RV, SRC_STR_RV}, +}; + + +gyro_orientation_sensor::gyro_orientation_sensor() +: m_azimuth(-1) +, m_pitch(-1) +, m_roll(-1) +, m_accuracy(-1) +, m_time(0) +, m_interval(0) +{ +} + +gyro_orientation_sensor::~gyro_orientation_sensor() +{ +} + +int gyro_orientation_sensor::get_sensor_info(const sensor_info2_t **info) +{ + *info = &sensor_info; + return OP_SUCCESS; +} + +int gyro_orientation_sensor::get_required_sensors(const required_sensor_s **sensors) +{ + *sensors = required_sensors; + return 1; +} + +int gyro_orientation_sensor::update(uint32_t id, sensor_data_t *data, int len) +{ + int error; + float azimuth, pitch, roll; + + error = quat_to_orientation(data->values, azimuth, pitch, roll); + retv_if(error, OP_ERROR); + + m_azimuth = azimuth; + m_pitch = pitch; + m_roll = roll; + m_time = data->timestamp; + m_accuracy = data->accuracy; + + _D("[gyro_orientation] : [%10f] [%10f] [%10f]", m_azimuth, m_pitch, m_roll); + return OP_SUCCESS; +} + +int gyro_orientation_sensor::get_data(sensor_data_t **data, int *length) +{ + sensor_data_t *sensor_data; + sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory"); + + sensor_data->accuracy = m_accuracy; + sensor_data->timestamp = m_time; + sensor_data->value_count = 3; + sensor_data->values[0] = m_azimuth; + sensor_data->values[1] = m_pitch; + sensor_data->values[2] = m_roll; + + *data = sensor_data; + *length = sizeof(sensor_data_t); + + return 0; +} diff --git a/src/fusion-sensor/orientation/gyro_orientation_sensor.h b/src/fusion-sensor/orientation/gyro_orientation_sensor.h new file mode 100644 index 00000000..10438ccc --- /dev/null +++ b/src/fusion-sensor/orientation/gyro_orientation_sensor.h @@ -0,0 +1,41 @@ +/* + * sensord + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +class gyro_orientation_sensor : public fusion_sensor { +public: + gyro_orientation_sensor(); + virtual ~gyro_orientation_sensor(); + + int get_sensor_info(const sensor_info2_t **info); + int get_required_sensors(const required_sensor_s **sensors); + + int update(uint32_t id, sensor_data_t *data, int len); + int get_data(sensor_data_t **data, int *len); + +private: + float m_azimuth; + float m_pitch; + float m_roll; + int m_accuracy; + unsigned long long m_time; + unsigned long m_interval; +}; \ No newline at end of file diff --git a/src/fusion-sensor/orientation/magnetic_orientation_sensor.cpp b/src/fusion-sensor/orientation/magnetic_orientation_sensor.cpp new file mode 100644 index 00000000..66d435fe --- /dev/null +++ b/src/fusion-sensor/orientation/magnetic_orientation_sensor.cpp @@ -0,0 +1,112 @@ +/* + * sensord + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "magnetic_orientation_sensor.h" + +#include +#include +#include + +#define NAME_SENSOR "http://tizen.org/sensor/general/geomagnetic_orientation/tizen_default" +#define NAME_VENDOR "tizen.org" + +#define SRC_ID_RV 0x1 +#define SRC_STR_RV "http://tizen.org/sensor/general/geomagnetic_rotation_vector" + +static sensor_info2_t sensor_info = { + id: 0x1, + type: GEOMAGNETIC_ORIENTATION_SENSOR, + uri: NAME_SENSOR, + vendor: NAME_VENDOR, + min_range: -180, + max_range: 360, + resolution: 0.01, + min_interval: 10, + max_batch_count: 0, + wakeup_supported: false, + privilege:"", +}; + +static required_sensor_s required_sensors[] = { + {SRC_ID_RV, SRC_STR_RV}, +}; + + +magnetic_orientation_sensor::magnetic_orientation_sensor() +: m_azimuth(-1) +, m_pitch(-1) +, m_roll(-1) +, m_accuracy(-1) +, m_time(0) +, m_interval(0) +{ +} + +magnetic_orientation_sensor::~magnetic_orientation_sensor() +{ +} + +int magnetic_orientation_sensor::get_sensor_info(const sensor_info2_t **info) +{ + *info = &sensor_info; + return OP_SUCCESS; +} + +int magnetic_orientation_sensor::get_required_sensors(const required_sensor_s **sensors) +{ + *sensors = required_sensors; + return 1; +} + +int magnetic_orientation_sensor::update(uint32_t id, sensor_data_t *data, int len) +{ + int error; + float azimuth, pitch, roll; + + error = quat_to_orientation(data->values, azimuth, pitch, roll); + retv_if(error, OP_ERROR); + + m_azimuth = azimuth; + m_pitch = pitch; + m_roll = roll; + m_time = data->timestamp; + m_accuracy = data->accuracy; + + _D("[magnetic_orientation] : [%10f] [%10f] [%10f]", m_azimuth, m_pitch, m_roll); + return OP_SUCCESS; +} + +int magnetic_orientation_sensor::get_data(sensor_data_t **data, int *length) +{ + sensor_data_t *sensor_data; + sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory"); + + sensor_data->accuracy = m_accuracy; + sensor_data->timestamp = m_time; + sensor_data->value_count = 3; + sensor_data->values[0] = m_azimuth; + sensor_data->values[1] = m_pitch; + sensor_data->values[2] = m_roll; + + *data = sensor_data; + *length = sizeof(sensor_data_t); + + return 0; +} diff --git a/src/fusion-sensor/orientation/magnetic_orientation_sensor.h b/src/fusion-sensor/orientation/magnetic_orientation_sensor.h new file mode 100644 index 00000000..982247d5 --- /dev/null +++ b/src/fusion-sensor/orientation/magnetic_orientation_sensor.h @@ -0,0 +1,41 @@ +/* + * sensord + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +class magnetic_orientation_sensor : public fusion_sensor { +public: + magnetic_orientation_sensor(); + virtual ~magnetic_orientation_sensor(); + + int get_sensor_info(const sensor_info2_t **info); + int get_required_sensors(const required_sensor_s **sensors); + + int update(uint32_t id, sensor_data_t *data, int len); + int get_data(sensor_data_t **data, int *len); + +private: + float m_azimuth; + float m_pitch; + float m_roll; + int m_accuracy; + unsigned long long m_time; + unsigned long m_interval; +};