Enabling Auto_rotation to support landscape/potrait 90 degree events 81/43681/7
authorAnkur <ankur29.garg@samsung.com>
Tue, 11 Aug 2015 09:37:53 +0000 (15:07 +0530)
committerAnkur <ankur29.garg@samsung.com>
Tue, 11 Aug 2015 09:38:21 +0000 (15:08 +0530)
Tested on rd-pq

Change-Id: I9ce16a9fb8ba9f3235e19b5fb29e6063ab8f0f2a
Signed-off-by: Ankur <ankur29.garg@samsung.com>
packaging/sensord.spec
sensor_plugins.xml.in
src/auto_rotation/CMakeLists.txt
src/auto_rotation/auto_rotation_sensor.cpp
src/auto_rotation/auto_rotation_sensor.h
src/libsensord/sensor_internal_deprecated.h
virtual_sensors.xml

index 5ca2327..b9bf107 100755 (executable)
@@ -18,6 +18,7 @@ BuildRequires:  pkgconfig(libsystemd-daemon)
 BuildRequires:  pkgconfig(capi-system-info)
 
 %define accel_state ON
+%define auto_rotation_state ON
 %define gyro_state ON
 %define proxi_state ON
 %define light_state ON
@@ -83,7 +84,7 @@ cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DACCEL=%{accel_state} \
        -DORIENTATION=%{orientation_state} -DGRAVITY=%{gravity_state} \
        -DLINEAR_ACCEL=%{linear_accel_state} -DRV=%{rv_state} \
        -DGEOMAGNETIC_RV=%{geomagnetic_rv_state} -DGAMING_RV=%{gaming_rv_state} \
-       -DUNCAL_GYRO=%{uncal_gyro_state} \
+       -DUNCAL_GYRO=%{uncal_gyro_state} -DAUTO_ROTATION=%{auto_rotation_state} \
        -DTILT=%{tilt_state} -DTEST_SUITE=%{build_test_suite} \
        -DLIBDIR=%{_libdir} -DINCLUDEDIR=%{_includedir}
 
index 66d7d26..a088a2a 100755 (executable)
@@ -11,6 +11,7 @@
 
        <SENSOR>
                <MODULE path = "/usr/lib/sensord/libaccel_sensor.so"/>
+               <MODULE path = "/usr/lib/sensord/libauto_rotation_sensor.so"/>
                <MODULE path = "/usr/lib/sensord/libgyro_sensor.so"/>
                <MODULE path = "/usr/lib/sensord/libgeo_sensor.so"/>
                <MODULE path = "/usr/lib/sensord/libproxi_sensor.so"/>
index a0076b2..13b56e5 100644 (file)
@@ -6,23 +6,20 @@ SET(SENSOR_NAME auto_rotation_sensor)
 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 include_directories(${CMAKE_SOURCE_DIR}/src/libsensord)
 
-INCLUDE(FindPkgConfig)
-PKG_CHECK_MODULES(auto_rot_pkgs REQUIRED vconf)
-
-FOREACH(flag ${auto_rot_pkgs_LDFLAGS})
+FOREACH(flag ${auto_rotation_pkgs_LDFLAGS})
        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
 ENDFOREACH(flag)
 
-FOREACH(flag ${auto_rot_pkgs_CFLAGS})
+FOREACH(flag ${auto_rotation_pkgs_CFLAGS})
        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
 ENDFOREACH(flag)
 
 add_library(${SENSOR_NAME} SHARED
-               auto_rotation_sensor.cpp
-               auto_rotation_alg.cpp
-               auto_rotation_alg_emul.cpp
-               )
+       auto_rotation_sensor.cpp
+       auto_rotation_alg.cpp
+       auto_rotation_alg_emul.cpp
+)
 
-target_link_libraries(${SENSOR_NAME} ${auto_rot_pkgs_LDFLAGS} "-lm")
+target_link_libraries(${SENSOR_NAME} ${auto_rotation_pkgs_LDFLAGS} "-lm")
 
 install(TARGETS ${SENSOR_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensord)
index 381e861..1b1954b 100755 (executable)
 #include <virtual_sensor.h>
 #include <auto_rotation_sensor.h>
 #include <sensor_plugin_loader.h>
+#include <cvirtual_sensor_config.h>
 #include <auto_rotation_alg.h>
 #include <auto_rotation_alg_emul.h>
 
 using std::bind1st;
 using std::mem_fun;
 
-#define SENSOR_NAME "AUTO_ROTATION_SENSOR"
-#define AUTO_ROTATION_LIB "/usr/lib/sensord/libauto-rotation.so"
+#define SENSOR_NAME                                            "AUTO_ROTATION_SENSOR"
+#define SENSOR_TYPE_AUTO_ROTATION              "AUTO_ROTATION"
+
+#define MS_TO_US 1000
+
+#define ELEMENT_NAME                                   "NAME"
+#define ELEMENT_VENDOR                                 "VENDOR"
+#define ELEMENT_RAW_DATA_UNIT                  "RAW_DATA_UNIT"
+#define ELEMENT_DEFAULT_SAMPLING_TIME  "DEFAULT_SAMPLING_TIME"
+
+#define AUTO_ROTATION_LIB                              "/usr/lib/sensord/libauto_rotation_sensor.so"
 
 auto_rotation_sensor::auto_rotation_sensor()
 : m_accel_sensor(NULL)
@@ -47,9 +57,34 @@ auto_rotation_sensor::auto_rotation_sensor()
 , m_rotation_time(1) // rotation state is valid from initial state, so set rotation time to non-zero value
 , m_alg(NULL)
 {
+       cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance();
        m_name = string(SENSOR_NAME);
 
        register_supported_event(AUTO_ROTATION_CHANGE_STATE_EVENT);
+
+
+       if (!config.get(SENSOR_TYPE_AUTO_ROTATION, ELEMENT_VENDOR, m_vendor)) {
+               ERR("[VENDOR] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_vendor = %s", m_vendor.c_str());
+
+       if (!config.get(SENSOR_TYPE_AUTO_ROTATION, ELEMENT_RAW_DATA_UNIT, m_raw_data_unit)) {
+               ERR("[RAW_DATA_UNIT] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_raw_data_unit = %s", m_raw_data_unit.c_str());
+
+       if (!config.get(SENSOR_TYPE_AUTO_ROTATION, ELEMENT_DEFAULT_SAMPLING_TIME, &m_default_sampling_time)) {
+               ERR("[DEFAULT_SAMPLING_TIME] is empty\n");
+               throw ENXIO;
+       }
+
+       INFO("m_default_sampling_time = %d", m_default_sampling_time);
+
+       m_interval = m_default_sampling_time * MS_TO_US;
 }
 
 auto_rotation_sensor::~auto_rotation_sensor()
@@ -105,13 +140,12 @@ sensor_type_t auto_rotation_sensor::get_type(void)
 
 bool auto_rotation_sensor::on_start(void)
 {
-       const int SAMPLING_TIME = 60;
        m_rotation = AUTO_ROTATION_DEGREE_UNKNOWN;
 
        m_alg->start();
 
        m_accel_sensor->add_client(ACCELEROMETER_RAW_DATA_EVENT);
-       m_accel_sensor->add_interval((int)this , SAMPLING_TIME, true);
+       m_accel_sensor->add_interval((int)this , (m_interval/MS_TO_US), true);
        m_accel_sensor->start();
 
        return activate();
@@ -159,9 +193,9 @@ void auto_rotation_sensor::synthesize(const sensor_event_t& event, vector<sensor
        return;
 }
 
-int auto_rotation_sensor::get_sensor_data(unsigned int data_id, sensor_data_t &data)
+int auto_rotation_sensor::get_sensor_data(const unsigned int event_type, sensor_data_t &data)
 {
-       if (data_id != AUTO_ROTATION_CHANGE_STATE_EVENT)
+       if (event_type != AUTO_ROTATION_CHANGE_STATE_EVENT)
                return -1;
 
        AUTOLOCK(m_value_mutex);
@@ -174,7 +208,7 @@ int auto_rotation_sensor::get_sensor_data(unsigned int data_id, sensor_data_t &d
        return 0;
 }
 
-bool auto_rotation_sensor::get_properties(sensor_properties_t &properties)
+bool auto_rotation_sensor::get_properties(sensor_properties_s &properties)
 {
        properties.name = "Auto Rotation Sensor";
        properties.vendor = "Samsung Electronics";
index 1124c03..863d419 100755 (executable)
 #define _AUTO_ROTATION_SENSOR_H_
 
 #include <sensor_internal.h>
-#include <vconf.h>
 #include <string>
 #include <auto_rotation_alg.h>
 
-using std::string;
-
 class auto_rotation_sensor : public virtual_sensor {
 public:
        auto_rotation_sensor();
@@ -39,16 +36,21 @@ public:
 
        void synthesize(const sensor_event_t& event, vector<sensor_event_t> &outs);
 
-       int get_sensor_data(unsigned int data_id, sensor_data_t &data);
-       virtual bool get_properties(sensor_properties_t &properties);
+       int get_sensor_data(const unsigned int event_type, sensor_data_t &data);
+       virtual bool get_properties(sensor_properties_s &properties);
 private:
        sensor_base *m_accel_sensor;
        cmutex m_value_mutex;
 
        int m_rotation;
+       unsigned int m_interval;
        unsigned long long m_rotation_time;
        auto_rotation_alg *m_alg;
 
+       string m_vendor;
+       string m_raw_data_unit;
+       int m_default_sampling_time;
+
        auto_rotation_alg *get_alg();
        virtual bool on_start(void);
        virtual bool on_stop(void);
index 3f6aede..85bcce7 100755 (executable)
@@ -38,6 +38,7 @@ extern "C"
 
 /*header for each sensor type*/
 #include <sensor_accel.h>
+#include <sensor_auto_rotation.h>
 #include <sensor_geomag.h>
 #include <sensor_light.h>
 #include <sensor_proxi.h>
index 06263c0..52ce6fb 100755 (executable)
                        <ROLL_ROTATION_COMPENSATION value="-1" />
                </ORIENTATION>
 
+               <AUTO_ROTATION>
+                       <NAME value="AUTO_ROTATION_SENSOR" />
+                       <VENDOR value="SAMSUNG" />
+                       <RAW_DATA_UNIT value="DEGREES" />
+                       <DEFAULT_SAMPLING_TIME value="60" />
+               </AUTO_ROTATION>
+
                <GRAVITY>
                        <NAME value="GRAVITY_SENSOR" />
                        <VENDOR value="SAMSUNG" />
                        <ROLL_ROTATION_COMPENSATION value="-1" />
                </ORIENTATION>
 
+               <AUTO_ROTATION>
+                       <NAME value="AUTO_ROTATION_SENSOR" />
+                       <VENDOR value="SAMSUNG" />
+                       <RAW_DATA_UNIT value="DEGREES" />
+                       <DEFAULT_SAMPLING_TIME value="60" />
+               </AUTO_ROTATION>
+
                <GRAVITY>
                        <NAME value="GRAVITY_SENSOR" />
                        <VENDOR value="SAMSUNG" />