Support new orientation sensor types 45/264345/1 accepted/tizen/6.5/unified/20211028.115556 accepted/tizen/6.5/unified/20211109.041700 accepted/tizen/unified/20210920.131502 submit/tizen/20210916.080205 submit/tizen_6.5/20211028.162501 submit/tizen_6.5/20211108.015632 submit/tizen_6.5/20211222.073549 submit/tizen_6.5/20211222.074647 tizen_6.5.m2_release
authortaemin.yeom <taemin.yeom@samsung.com>
Thu, 16 Sep 2021 07:53:04 +0000 (16:53 +0900)
committertaemin.yeom <taemin.yeom@samsung.com>
Thu, 16 Sep 2021 07:53:04 +0000 (16:53 +0900)
- GYROSCOPE_ORIENTATION_SENSOR : based on gyroscope_rotation_vector
- GEOMAGNETIC_ORIENTATION_SENSOR : based on geomagnetic_rotration_vector

Change-Id: I604e4bb772274660be31077f30a3cdb051c9d342
Signed-off-by: taemin.yeom <taemin.yeom@samsung.com>
src/fusion-sensor/create.cpp
src/fusion-sensor/orientation/gyro_orientation_sensor.cpp [new file with mode: 0644]
src/fusion-sensor/orientation/gyro_orientation_sensor.h [new file with mode: 0644]
src/fusion-sensor/orientation/magnetic_orientation_sensor.cpp [new file with mode: 0644]
src/fusion-sensor/orientation/magnetic_orientation_sensor.h [new file with mode: 0644]

index 241a4cd..1d996fe 100644 (file)
@@ -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>("Orientation Sensor");
+       create_sensor<magnetic_orientation_sensor>("Magnetic Orientation Sensor");
+       create_sensor<gyro_orientation_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 (file)
index 0000000..019162d
--- /dev/null
@@ -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 <sensor_log.h>
+#include <sensor_types.h>
+#include <fusion_util.h>
+
+#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 (file)
index 0000000..10438cc
--- /dev/null
@@ -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 <fusion_sensor.h>
+#include <sensor_types.h>
+
+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 (file)
index 0000000..66d435f
--- /dev/null
@@ -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 <sensor_log.h>
+#include <sensor_types.h>
+#include <fusion_util.h>
+
+#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 (file)
index 0000000..982247d
--- /dev/null
@@ -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 <fusion_sensor.h>
+#include <sensor_types.h>
+
+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;
+};