From 4fd5379bbb2182237c88cc625ef469a51afeb7c8 Mon Sep 17 00:00:00 2001 From: Ankur Date: Mon, 18 May 2015 13:30:53 +0530 Subject: [PATCH] Adding common plugin for hardware/software fusion - orientation sensor Support for common virtual sensor plugin for orientation sensor for both hardware and software based sensor fusion Tested on rd-pq device with tizen 2.4 repo Change-Id: I676cc594d167928508e3e82a585e2d5910d01e40 --- src/orientation/orientation_sensor.cpp | 62 +++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/src/orientation/orientation_sensor.cpp b/src/orientation/orientation_sensor.cpp index b9291e8..8b55c7e 100755 --- a/src/orientation/orientation_sensor.cpp +++ b/src/orientation/orientation_sensor.cpp @@ -68,6 +68,12 @@ orientation_sensor::orientation_sensor() { cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance(); + sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(FUSION_SENSOR); + if (!fusion_sensor_hal) + m_hardware_fusion = false; + else + m_hardware_fusion = true; + m_name = string(SENSOR_NAME); register_supported_event(ORIENTATION_RAW_DATA_EVENT); m_enable_orientation = 0; @@ -150,15 +156,17 @@ bool orientation_sensor::on_start(void) { AUTOLOCK(m_mutex); - m_accel_sensor->add_client(ACCELEROMETER_RAW_DATA_EVENT); - m_accel_sensor->add_interval((intptr_t)this, (m_interval/MS_TO_US), false); - m_accel_sensor->start(); - m_gyro_sensor->add_client(GYROSCOPE_RAW_DATA_EVENT); - m_gyro_sensor->add_interval((intptr_t)this, (m_interval/MS_TO_US), false); - m_gyro_sensor->start(); - m_magnetic_sensor->add_client(GEOMAGNETIC_RAW_DATA_EVENT); - m_magnetic_sensor->add_interval((intptr_t)this, (m_interval/MS_TO_US), false); - m_magnetic_sensor->start(); + if (!m_hardware_fusion) { + m_accel_sensor->add_client(ACCELEROMETER_RAW_DATA_EVENT); + m_accel_sensor->add_interval((intptr_t)this, (m_interval/MS_TO_US), false); + m_accel_sensor->start(); + m_gyro_sensor->add_client(GYROSCOPE_RAW_DATA_EVENT); + m_gyro_sensor->add_interval((intptr_t)this, (m_interval/MS_TO_US), false); + m_gyro_sensor->start(); + m_magnetic_sensor->add_client(GEOMAGNETIC_RAW_DATA_EVENT); + m_magnetic_sensor->add_interval((intptr_t)this, (m_interval/MS_TO_US), false); + m_magnetic_sensor->start(); + } m_fusion_sensor->register_supported_event(FUSION_EVENT); m_fusion_sensor->register_supported_event(FUSION_ORIENTATION_ENABLED); @@ -174,15 +182,17 @@ bool orientation_sensor::on_stop(void) { AUTOLOCK(m_mutex); - m_accel_sensor->delete_client(ACCELEROMETER_RAW_DATA_EVENT); - m_accel_sensor->delete_interval((intptr_t)this, false); - m_accel_sensor->stop(); - m_gyro_sensor->delete_client(GYROSCOPE_RAW_DATA_EVENT); - m_gyro_sensor->delete_interval((intptr_t)this, false); - m_gyro_sensor->stop(); - m_magnetic_sensor->delete_client(GEOMAGNETIC_RAW_DATA_EVENT); - m_magnetic_sensor->delete_interval((intptr_t)this, false); - m_magnetic_sensor->stop(); + if (!m_hardware_fusion) { + m_accel_sensor->delete_client(ACCELEROMETER_RAW_DATA_EVENT); + m_accel_sensor->delete_interval((intptr_t)this, false); + m_accel_sensor->stop(); + m_gyro_sensor->delete_client(GYROSCOPE_RAW_DATA_EVENT); + m_gyro_sensor->delete_interval((intptr_t)this, false); + m_gyro_sensor->stop(); + m_magnetic_sensor->delete_client(GEOMAGNETIC_RAW_DATA_EVENT); + m_magnetic_sensor->delete_interval((intptr_t)this, false); + m_magnetic_sensor->stop(); + } m_fusion_sensor->delete_client(FUSION_EVENT); m_fusion_sensor->delete_interval((intptr_t)this, false); @@ -198,9 +208,11 @@ bool orientation_sensor::add_interval(int client_id, unsigned int interval) { AUTOLOCK(m_mutex); - m_accel_sensor->add_interval(client_id, interval, false); - m_gyro_sensor->add_interval(client_id, interval, false); - m_magnetic_sensor->add_interval(client_id, interval, false); + if (!m_hardware_fusion) { + m_accel_sensor->add_interval(client_id, interval, false); + m_gyro_sensor->add_interval(client_id, interval, false); + m_magnetic_sensor->add_interval(client_id, interval, false); + } m_fusion_sensor->add_interval(client_id, interval, false); @@ -211,9 +223,11 @@ bool orientation_sensor::delete_interval(int client_id) { AUTOLOCK(m_mutex); - m_accel_sensor->delete_interval(client_id, false); - m_gyro_sensor->delete_interval(client_id, false); - m_magnetic_sensor->delete_interval(client_id, false); + if (!m_hardware_fusion) { + m_accel_sensor->delete_interval(client_id, false); + m_gyro_sensor->delete_interval(client_id, false); + m_magnetic_sensor->delete_interval(client_id, false); + } m_fusion_sensor->delete_interval(client_id, false); -- 2.7.4