SET(AUTO_ROTATION "ON")
SET(GRAVITY "ON")
SET(LINEAR_ACCEL "ON")
+SET(RV "ON")
+SET(ORIENTATION "ON")
INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/shared
ADD_DEFINITIONS(-DENABLE_LINEAR_ACCEL)
ENDIF()
+IF("${RV}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} rotation_vector/*.cpp)
+ADD_DEFINITIONS(-DENABLE_ROTATION_VECTOR)
+ENDIF()
+
+IF("${ORIENTATION}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} orientation/*.cpp)
+ADD_DEFINITIONS(-DENABLE_ORIENTATION)
+ENDIF()
+
MESSAGE("Sources: ${SRCS}")
ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PLUGINS_PKGS_LDFLAGS})
#ifdef ENABLE_LINEAR_ACCEL
#include "linear_accel/linear_accel_sensor.h"
#endif
+#ifdef ENABLE_ROTATION_VECTOR
+#include "rotation_vector/rv_sensor.h"
+#include "rotation_vector/magnetic_rv_sensor.h"
+#include "rotation_vector/gyro_rv_sensor.h"
+#endif
+#ifdef ENABLE_ORIENTATION
+#include "orientation/orientation_sensor.h"
+#endif
static std::vector<fusion_sensor_t> sensors;
create_sensor<linear_accel_sensor>("Linear Acceleration Sensor");
#endif
+#ifdef ENABLE_ROTATION_VECTOR
+ create_sensor<rv_sensor>("Rotation Vector Sensor");
+ create_sensor<magnetic_rv_sensor>("Magnetic Rotation Vector Sensor");
+ create_sensor<gyro_rv_sensor>("Gyroscope Rotation Vector Sensor");
+#endif
+
+#ifdef ENABLE_ORIENTATION
+ create_sensor<orientation_sensor>("Orientation Sensor");
+#endif
+
*fsensors = &sensors[0];
return sensors.size();
}
*
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <math.h>
-#include <time.h>
-#include <sys/types.h>
-#include <dlfcn.h>
+#include "orientation_sensor.h"
#include <sensor_log.h>
#include <sensor_types.h>
-
-#include <sensor_common.h>
-#include <virtual_sensor.h>
-#include <orientation_sensor.h>
-#include <sensor_loader.h>
#include <fusion_util.h>
-#define SENSOR_NAME "SENSOR_ORIENTATION"
+#define NAME_SENSOR "http://tizen.org/sensor/orientation/orientation"
+#define NAME_VENDOR "Samsung"
+
+#define SRC_ID_RV 0x1
+#define SRC_STR_RV "http://tizen.org/sensor/rotation_vector"
+
+static sensor_info2_t sensor_info = {
+ id: 0x1,
+ type: 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},
+};
+
orientation_sensor::orientation_sensor()
-: m_rotation_vector_sensor(NULL)
-, m_azimuth(-1)
+: m_azimuth(-1)
, m_pitch(-1)
, m_roll(-1)
, m_accuracy(-1)
, m_time(0)
+, m_interval(0)
{
}
orientation_sensor::~orientation_sensor()
{
- _I("%s is destroyed!", SENSOR_NAME);
-}
-
-bool orientation_sensor::init(void)
-{
- m_rotation_vector_sensor = sensor_loader::get_instance().get_sensor(ROTATION_VECTOR_SENSOR);
-
- if (!m_rotation_vector_sensor) {
- _W("cannot load sensor[%s]", SENSOR_NAME);
- return false;
- }
- _I("%s is created!", SENSOR_NAME);
- return true;
-}
-
-sensor_type_t orientation_sensor::get_type(void)
-{
- return ORIENTATION_SENSOR;
}
-unsigned int orientation_sensor::get_event_type(void)
+int orientation_sensor::get_sensor_info(const sensor_info2_t **info)
{
- return ORIENTATION_EVENT_RAW_DATA_REPORT_ON_TIME;
+ *info = &sensor_info;
+ return OP_SUCCESS;
}
-const char* orientation_sensor::get_name(void)
+int orientation_sensor::get_required_sensors(const required_sensor_s **sensors)
{
- return SENSOR_NAME;
+ *sensors = required_sensors;
+ return 1;
}
-bool orientation_sensor::get_sensor_info(sensor_info &info)
-{
- info.set_type(get_type());
- info.set_id(get_id());
- info.set_privilege(SENSOR_PRIVILEGE_PUBLIC);
- info.set_name(get_name());
- info.set_vendor("Samsung Electronics");
- info.set_min_range(-180);
- info.set_max_range(360);
- info.set_resolution(0.01);
- info.set_min_interval(1);
- info.set_fifo_count(0);
- info.set_max_batch_count(0);
- info.set_supported_event(get_event_type());
- info.set_wakeup_supported(false);
-
- return true;
-}
-
-void orientation_sensor::synthesize(const sensor_event_t& event)
+int orientation_sensor::update(uint32_t id, sensor_data_t *data, int len)
{
int error;
- sensor_event_t *orientation_event;
float azimuth, pitch, roll;
- if (CONVERT_ID_TYPE(event.sensor_id) != ROTATION_VECTOR_SENSOR)
- return;
-
- error = quat_to_orientation(event.data->values, azimuth, pitch, roll);
- ret_if(error);
-
- orientation_event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
- if (!orientation_event) {
- _E("Failed to allocate memory");
- return;
- }
- orientation_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
- if (!orientation_event->data) {
- _E("Failed to allocate memory");
- free(orientation_event);
- return;
- }
-
- orientation_event->sensor_id = get_id();
- orientation_event->event_type = CONVERT_TYPE_EVENT(ORIENTATION_SENSOR);
- orientation_event->data_length = sizeof(sensor_data_t);
- orientation_event->data->accuracy = event.data->accuracy;
- orientation_event->data->timestamp = event.data->timestamp;
- orientation_event->data->value_count = 3;
- orientation_event->data->values[0] = azimuth;
- orientation_event->data->values[1] = pitch;
- orientation_event->data->values[2] = roll;
- push(orientation_event);
+ 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 = event.data->timestamp;
- m_accuracy = event.data->accuracy;
+ m_time = data->timestamp;
+ m_accuracy = data->accuracy;
_D("[orientation] : [%10f] [%10f] [%10f]", m_azimuth, m_pitch, m_roll);
+ return OP_SUCCESS;
}
int orientation_sensor::get_data(sensor_data_t **data, int *length)
{
- /* if It is batch sensor, remains can be 2+ */
- int remains = 1;
-
sensor_data_t *sensor_data;
sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
*data = sensor_data;
*length = sizeof(sensor_data_t);
- return --remains;
-}
-
-bool orientation_sensor::set_interval(unsigned long interval)
-{
- m_interval = interval;
- return true;
-}
-
-bool orientation_sensor::set_batch_latency(unsigned long latency)
-{
- return false;
-}
-
-bool orientation_sensor::on_start(void)
-{
- if (m_rotation_vector_sensor)
- m_rotation_vector_sensor->start();
-
- m_time = 0;
-
- return activate();
-}
-
-bool orientation_sensor::on_stop(void)
-{
- if (m_rotation_vector_sensor)
- m_rotation_vector_sensor->stop();
-
- m_time = 0;
-
- return deactivate();
-}
-
-bool orientation_sensor::add_interval(int client_id, unsigned int interval, bool is_processor)
-{
- if (m_rotation_vector_sensor)
- m_rotation_vector_sensor->add_interval(client_id, interval, true);
-
- return sensor_base::add_interval(client_id, interval, is_processor);
-}
-
-bool orientation_sensor::delete_interval(int client_id, bool is_processor)
-{
- if (m_rotation_vector_sensor)
- m_rotation_vector_sensor->delete_interval(client_id, true);
-
- return sensor_base::delete_interval(client_id, is_processor);
+ return 1;
}
*
*/
-#ifndef _ORIENTATION_SENSOR_H_
-#define _ORIENTATION_SENSOR_H_
+#ifndef __ORIENTATION_SENSOR_H__
+#define __ORIENTATION_SENSOR_H__
-#include <virtual_sensor.h>
+#include <fusion_sensor.h>
#include <sensor_types.h>
-#include <sensor_fusion.h>
-class orientation_sensor : public virtual_sensor {
+class orientation_sensor : public fusion_sensor {
public:
orientation_sensor();
virtual ~orientation_sensor();
- /* initialize sensor */
- bool init(void);
+ int get_sensor_info(const sensor_info2_t **info);
+ int get_required_sensors(const required_sensor_s **sensors);
- /* sensor info */
- virtual sensor_type_t get_type(void);
- virtual unsigned int get_event_type(void);
- virtual const char* get_name(void);
+ int update(uint32_t id, sensor_data_t *data, int len);
+ int get_data(sensor_data_t **data, int *len);
- virtual bool get_sensor_info(sensor_info &info);
-
- /* synthesize event */
- virtual void synthesize(const sensor_event_t& event);
-
- bool add_interval(int client_id, unsigned int interval, bool is_processor);
- bool delete_interval(int client_id, bool is_processor);
-
- /* get data */
- virtual int get_data(sensor_data_t **data, int *length);
private:
- sensor_base *m_rotation_vector_sensor;
-
float m_azimuth;
float m_pitch;
float m_roll;
int m_accuracy;
unsigned long long m_time;
unsigned long m_interval;
-
- virtual bool set_interval(unsigned long interval);
- virtual bool set_batch_latency(unsigned long latency);
-
- virtual bool on_start(void);
- virtual bool on_stop(void);
-
- int rotation_to_orientation(const float *rotation, float &azimuth, float &pitch, float &roll);
};
-#endif /* _ORIENTATION_SENSOR_H_ */
+#endif /* __ORIENTATION_SENSOR_H__ */
#include <errno.h>
#include <sys/types.h>
#include <sensor_log.h>
-#include <sensor_loader.h>
-#include <sensor_base.h>
#include <cmath>
#include "fusion_base.h"
: m_enable_accel(false)
, m_enable_gyro(false)
, m_enable_magnetic(false)
+, m_x(0)
+, m_y(0)
+, m_z(0)
+, m_w(0)
+, m_timestamp(0)
{
- _I("fusion_base is created!");
}
fusion_base::~fusion_base()
{
- _I("fusion_sensor is destroyed!");
}
void fusion_base::clear(void)
#ifndef __FUSION_BASE_H__
#define __FUSION_BASE_H__
-#include <fusion.h>
+#include "fusion.h"
#include "fusion_utils/orientation_filter.h"
class fusion_base : public virtual fusion {
#ifndef __GYRO_FUSION_H__
#define __GYRO_FUSION_H__
-#include <fusion_base.h>
+#include "fusion_base.h"
class gyro_fusion : public fusion_base {
public:
#ifndef __GYRO_MAGNETIC_FUSION_H__
#define __GYRO_MAGNETIC_FUSION_H__
-#include <fusion_base.h>
+#include "fusion_base.h"
class gyro_magnetic_fusion : public fusion_base {
public:
*
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <math.h>
-#include <time.h>
-#include <sys/types.h>
+#include "gyro_rv_sensor.h"
#include <sensor_log.h>
#include <sensor_types.h>
-
-#include <sensor_common.h>
-#include <virtual_sensor.h>
-#include <gyro_rv_sensor.h>
-#include <sensor_loader.h>
#include <fusion_util.h>
-#define SENSOR_NAME "SENSOR_GYROSCOPE_ROTATION_VECTOR"
-
+#define NAME_SENSOR "http://tizen.org/sensor/gyro_rotation_vector/gyro_rv"
+#define NAME_VENDOR "Samsung"
+
+#define SRC_ID_ACC 0x1
+#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer"
+
+#define SRC_ID_GYRO 0x2
+#define SRC_STR_GYRO "http://tizen.org/sensor/gyroscope"
+
+static sensor_info2_t sensor_info = {
+ id: 0x1,
+ type: GYROSCOPE_RV_SENSOR,
+ uri: NAME_SENSOR,
+ vendor: NAME_VENDOR,
+ min_range: 0,
+ max_range: 1,
+ resolution: 1,
+ min_interval: 10,
+ max_batch_count: 0,
+ wakeup_supported: false,
+ privilege:"",
+};
+
+static required_sensor_s required_sensors[] = {
+ {SRC_ID_ACC, SRC_STR_ACC},
+ {SRC_ID_GYRO, SRC_STR_GYRO},
+};
gyro_rv_sensor::gyro_rv_sensor()
-: m_accel_sensor(NULL)
-, m_gyro_sensor(NULL)
-, m_x(-1)
+: m_x(-1)
, m_y(-1)
, m_z(-1)
, m_w(-1)
, m_time(0)
+, m_interval(100)
, m_accuracy(SENSOR_ACCURACY_UNDEFINED)
{
}
gyro_rv_sensor::~gyro_rv_sensor()
{
- _I("%s is destroyed!", SENSOR_NAME);
-}
-
-bool gyro_rv_sensor::init(void)
-{
- m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR);
- m_gyro_sensor = sensor_loader::get_instance().get_sensor(GYROSCOPE_SENSOR);
-
- if (!m_accel_sensor || !m_gyro_sensor) {
- _W("cannot load sensors[%s]", SENSOR_NAME);
- return false;
- }
-
- _I("%s is created!", SENSOR_NAME);
- return true;
-}
-
-sensor_type_t gyro_rv_sensor::get_type(void)
-{
- return GYROSCOPE_RV_SENSOR;
}
-unsigned int gyro_rv_sensor::get_event_type(void)
+int gyro_rv_sensor::get_sensor_info(const sensor_info2_t **info)
{
- return CONVERT_TYPE_EVENT(GYROSCOPE_RV_SENSOR);
+ *info = &sensor_info;
+ return OP_SUCCESS;
}
-const char* gyro_rv_sensor::get_name(void)
+int gyro_rv_sensor::get_required_sensors(const required_sensor_s **sensors)
{
- return SENSOR_NAME;
+ *sensors = required_sensors;
+ return 2;
}
-bool gyro_rv_sensor::get_sensor_info(sensor_info &info)
+int gyro_rv_sensor::update(uint32_t id, sensor_data_t *data, int len)
{
- info.set_type(get_type());
- info.set_id(get_id());
- info.set_privilege(SENSOR_PRIVILEGE_PUBLIC);
- info.set_name(get_name());
- info.set_vendor("Samsung Electronics");
- info.set_min_range(0);
- info.set_max_range(1);
- info.set_resolution(1);
- info.set_min_interval(1);
- info.set_fifo_count(0);
- info.set_max_batch_count(0);
- info.set_supported_event(get_event_type());
- info.set_wakeup_supported(false);
-
- return true;
-}
-
-void gyro_rv_sensor::synthesize(const sensor_event_t& event)
-{
- sensor_event_t *rotation_vector_event;
-
- if (event.event_type != ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME &&
- event.event_type != GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME)
- return;
+ unsigned long long timestamp;
- if (event.event_type == ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME)
- m_fusion.push_accel(*(event.data));
- else if (event.event_type == GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME)
- m_fusion.push_gyro(*(event.data));
+ if (id == SRC_ID_ACC)
+ m_fusion.push_accel(*data);
+ else if (id == SRC_ID_GYRO)
+ m_fusion.push_gyro(*data);
- if (m_accuracy == SENSOR_ACCURACY_UNDEFINED)
- m_accuracy = event.data->accuracy;
- else if (m_accuracy > event.data->accuracy)
- m_accuracy = event.data->accuracy;
+ if (m_accuracy > data->accuracy)
+ m_accuracy = data->accuracy;
- unsigned long long timestamp;
if (!m_fusion.get_rv(timestamp, m_w, m_x, m_y, m_z))
- return;
+ return OP_ERROR;
if(timestamp == m_time)
- return;
- m_time = timestamp;
+ return OP_ERROR;
- rotation_vector_event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
- if (!rotation_vector_event) {
- _E("Failed to allocate memory");
- return;
- }
- rotation_vector_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
- if (!rotation_vector_event->data) {
- _E("Failed to allocate memory");
- free(rotation_vector_event);
- return;
- }
-
- rotation_vector_event->sensor_id = get_id();
- rotation_vector_event->event_type = CONVERT_TYPE_EVENT(GYROSCOPE_RV_SENSOR);
- rotation_vector_event->data_length = sizeof(sensor_data_t);
- rotation_vector_event->data->accuracy = m_accuracy;
- rotation_vector_event->data->timestamp = m_time;
- rotation_vector_event->data->value_count = 4;
- rotation_vector_event->data->values[0] = m_w;
- rotation_vector_event->data->values[1] = m_x;
- rotation_vector_event->data->values[2] = m_y;
- rotation_vector_event->data->values[3] = m_z;
- push(rotation_vector_event);
- m_accuracy = SENSOR_ACCURACY_UNDEFINED;
+ m_time = timestamp;
_D("[rotation_vector] : [%10f] [%10f] [%10f] [%10f]", m_x, m_y, m_z, m_w);
+ return OP_SUCCESS;
}
int gyro_rv_sensor::get_data(sensor_data_t **data, int *length)
sensor_data->accuracy = m_accuracy;
sensor_data->timestamp = m_time;
- sensor_data->value_count = 3;
- sensor_data->values[0] = m_x;
- sensor_data->values[1] = m_y;
- sensor_data->values[2] = m_z;
+ sensor_data->value_count = 4;
+ sensor_data->values[0] = m_w;
+ sensor_data->values[1] = m_x;
+ sensor_data->values[2] = m_y;
+ sensor_data->values[3] = m_z;
*data = sensor_data;
*length = sizeof(sensor_data_t);
return 0;
}
-
-bool gyro_rv_sensor::set_interval(unsigned long interval)
-{
- m_interval = interval;
- return true;
-}
-
-bool gyro_rv_sensor::set_batch_latency(unsigned long latency)
-{
- return false;
-}
-
-bool gyro_rv_sensor::on_start(void)
-{
- m_accel_sensor->start();
- m_gyro_sensor->start();
- m_time = 0;
- m_accuracy = SENSOR_ACCURACY_UNDEFINED;
- return activate();
-}
-
-bool gyro_rv_sensor::on_stop(void)
-{
- m_accel_sensor->stop();
- m_gyro_sensor->stop();
- m_time = 0;
- m_accuracy = SENSOR_ACCURACY_UNDEFINED;
- return deactivate();
-}
-
-bool gyro_rv_sensor::add_interval(int client_id, unsigned int interval, bool is_processor)
-{
- m_accel_sensor->add_interval(client_id, interval, true);
- m_gyro_sensor->add_interval(client_id, interval, true);
-
- return sensor_base::add_interval(client_id, interval, is_processor);
-}
-
-bool gyro_rv_sensor::delete_interval(int client_id, bool is_processor)
-{
- m_accel_sensor->delete_interval(client_id, true);
- m_gyro_sensor->delete_interval(client_id, true);
-
- return sensor_base::delete_interval(client_id, is_processor);
-}
#ifndef __GYRO_RV_SENSOR_H__
#define __GYRO_RV_SENSOR_H__
-#include <virtual_sensor.h>
+#include <fusion_sensor.h>
#include <sensor_types.h>
-#include <gyro_fusion.h>
+#include "gyro_fusion.h"
-class gyro_rv_sensor : public virtual_sensor {
+class gyro_rv_sensor : public fusion_sensor {
public:
gyro_rv_sensor();
virtual ~gyro_rv_sensor();
- /* initialize sensor */
- bool init(void);
+ int get_sensor_info(const sensor_info2_t **info);
+ int get_required_sensors(const required_sensor_s **sensors);
- /* sensor info */
- virtual sensor_type_t get_type(void);
- virtual unsigned int get_event_type(void);
- virtual const char* get_name(void);
+ int update(uint32_t id, sensor_data_t *data, int len);
+ int get_data(sensor_data_t **data, int *len);
- virtual bool get_sensor_info(sensor_info &info);
-
- /* synthesize event */
- virtual void synthesize(const sensor_event_t& event);
-
- bool add_interval(int client_id, unsigned int interval, bool is_processor);
- bool delete_interval(int client_id, bool is_processor);
-
- /* get data */
- virtual int get_data(sensor_data_t **data, int *length);
private:
- sensor_base *m_accel_sensor;
- sensor_base *m_gyro_sensor;
gyro_fusion m_fusion;
float m_x;
unsigned long long m_time;
unsigned long m_interval;
int m_accuracy;
-
- virtual bool set_interval(unsigned long interval);
- virtual bool set_batch_latency(unsigned long latency);
-
- virtual bool on_start(void);
- virtual bool on_stop(void);
};
#endif /* __GYRO_SENSOR_H__ */
#ifndef __MAGNETIC_FUSION_H__
#define __MAGNETIC_FUSION_H__
-#include <fusion_base.h>
+#include "fusion_base.h"
class magnetic_fusion: public fusion_base {
public:
*
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <math.h>
-#include <time.h>
-#include <sys/types.h>
+#include "magnetic_rv_sensor.h"
#include <sensor_log.h>
#include <sensor_types.h>
-
-#include <sensor_common.h>
-#include <virtual_sensor.h>
-#include <magnetic_rv_sensor.h>
-#include <sensor_loader.h>
#include <fusion_util.h>
-#define SENSOR_NAME "SENSOR_MAGNETIC_ROTATION_VECTOR"
-
+#define NAME_SENSOR "http://tizen.org/sensor/mag_rotation_vector/mag_rv"
+#define NAME_VENDOR "Samsung"
+
+#define SRC_ID_ACC 0x1
+#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer"
+
+#define SRC_ID_MAG 0x3
+#define SRC_STR_MAG "http://tizen.org/sensor/geomagnetic"
+
+static sensor_info2_t sensor_info = {
+ id: 0x1,
+ type: GEOMAGNETIC_RV_SENSOR,
+ uri: NAME_SENSOR,
+ vendor: NAME_VENDOR,
+ min_range: 0,
+ max_range: 1,
+ resolution: 1,
+ min_interval: 10,
+ max_batch_count: 0,
+ wakeup_supported: false,
+ privilege:"",
+};
+
+static required_sensor_s required_sensors[] = {
+ {SRC_ID_ACC, SRC_STR_ACC},
+ {SRC_ID_MAG, SRC_STR_MAG},
+};
magnetic_rv_sensor::magnetic_rv_sensor()
-: m_accel_sensor(NULL)
-, m_mag_sensor(NULL)
-, m_x(-1)
+: m_x(-1)
, m_y(-1)
, m_z(-1)
, m_w(-1)
, m_time(0)
+, m_interval(100)
, m_accuracy(SENSOR_ACCURACY_UNDEFINED)
{
}
magnetic_rv_sensor::~magnetic_rv_sensor()
{
- _I("%s is destroyed!", SENSOR_NAME);
-}
-
-bool magnetic_rv_sensor::init(void)
-{
- m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR);
- m_mag_sensor = sensor_loader::get_instance().get_sensor(GEOMAGNETIC_SENSOR);
-
- if (!m_accel_sensor || !m_mag_sensor) {
- _W("cannot load sensors[%s]", SENSOR_NAME);
- return false;
- }
-
- _I("%s is created!", SENSOR_NAME);
- return true;
-}
-
-sensor_type_t magnetic_rv_sensor::get_type(void)
-{
- return GEOMAGNETIC_RV_SENSOR;
}
-unsigned int magnetic_rv_sensor::get_event_type(void)
+int magnetic_rv_sensor::get_sensor_info(const sensor_info2_t **info)
{
- return CONVERT_TYPE_EVENT(GEOMAGNETIC_RV_SENSOR);
+ *info = &sensor_info;
+ return OP_SUCCESS;
}
-const char* magnetic_rv_sensor::get_name(void)
+int magnetic_rv_sensor::get_required_sensors(const required_sensor_s **sensors)
{
- return SENSOR_NAME;
+ *sensors = required_sensors;
+ return 2;
}
-bool magnetic_rv_sensor::get_sensor_info(sensor_info &info)
+int magnetic_rv_sensor::update(uint32_t id, sensor_data_t *data, int len)
{
- info.set_type(get_type());
- info.set_id(get_id());
- info.set_privilege(SENSOR_PRIVILEGE_PUBLIC);
- info.set_name(get_name());
- info.set_vendor("Samsung Electronics");
- info.set_min_range(0);
- info.set_max_range(1);
- info.set_resolution(1);
- info.set_min_interval(1);
- info.set_fifo_count(0);
- info.set_max_batch_count(0);
- info.set_supported_event(get_event_type());
- info.set_wakeup_supported(false);
-
- return true;
-}
-
-void magnetic_rv_sensor::synthesize(const sensor_event_t& event)
-{
- sensor_event_t *rotation_vector_event;
-
- if (event.event_type != ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME &&
- event.event_type != GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME)
- return;
+ unsigned long long timestamp;
- if (event.event_type == ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME)
- m_fusion.push_accel(*(event.data));
- else if (event.event_type == GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME)
- m_fusion.push_mag(*(event.data));
+ if (id == SRC_ID_ACC)
+ m_fusion.push_accel(*data);
+ else if (id == SRC_ID_MAG)
+ m_fusion.push_mag(*data);
- if (m_accuracy == SENSOR_ACCURACY_UNDEFINED)
- m_accuracy = event.data->accuracy;
- else if (m_accuracy > event.data->accuracy)
- m_accuracy = event.data->accuracy;
+ if (m_accuracy > data->accuracy)
+ m_accuracy = data->accuracy;
- unsigned long long timestamp;
if (!m_fusion.get_rv(timestamp, m_w, m_x, m_y, m_z))
- return;
+ return OP_ERROR;
if (timestamp == m_time)
- return;
- m_time = timestamp;
+ return OP_ERROR;
- rotation_vector_event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
- if (!rotation_vector_event) {
- _E("Failed to allocate memory");
- return;
- }
- rotation_vector_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
- if (!rotation_vector_event->data) {
- _E("Failed to allocate memory");
- free(rotation_vector_event);
- return;
- }
-
- rotation_vector_event->sensor_id = get_id();
- rotation_vector_event->event_type = CONVERT_TYPE_EVENT(GEOMAGNETIC_RV_SENSOR);
- rotation_vector_event->data_length = sizeof(sensor_data_t);
- rotation_vector_event->data->accuracy = m_accuracy;
- rotation_vector_event->data->timestamp = m_time;
- rotation_vector_event->data->value_count = 4;
- rotation_vector_event->data->values[0] = m_w;
- rotation_vector_event->data->values[1] = m_x;
- rotation_vector_event->data->values[2] = m_y;
- rotation_vector_event->data->values[3] = m_z;
- push(rotation_vector_event);
- m_accuracy = SENSOR_ACCURACY_UNDEFINED;
+ m_time = timestamp;
_D("[rotation_vector] : [%10f] [%10f] [%10f] [%10f]", m_x, m_y, m_z, m_w);
+ return OP_SUCCESS;
}
int magnetic_rv_sensor::get_data(sensor_data_t **data, int *length)
sensor_data->accuracy = m_accuracy;
sensor_data->timestamp = m_time;
- sensor_data->value_count = 3;
- sensor_data->values[0] = m_x;
- sensor_data->values[1] = m_y;
- sensor_data->values[2] = m_z;
+ sensor_data->value_count = 4;
+ sensor_data->values[0] = m_w;
+ sensor_data->values[1] = m_x;
+ sensor_data->values[2] = m_y;
+ sensor_data->values[3] = m_z;
*data = sensor_data;
*length = sizeof(sensor_data_t);
return 0;
}
-
-bool magnetic_rv_sensor::set_interval(unsigned long interval)
-{
- m_interval = interval;
- return true;
-}
-
-bool magnetic_rv_sensor::set_batch_latency(unsigned long latency)
-{
- return false;
-}
-
-bool magnetic_rv_sensor::on_start(void)
-{
- m_accel_sensor->start();
- m_mag_sensor->start();
- m_time = 0;
- m_accuracy = SENSOR_ACCURACY_UNDEFINED;
- return activate();
-}
-
-bool magnetic_rv_sensor::on_stop(void)
-{
- m_accel_sensor->stop();
- m_mag_sensor->stop();
- m_time = 0;
- m_accuracy = SENSOR_ACCURACY_UNDEFINED;
- return deactivate();
-}
-
-bool magnetic_rv_sensor::add_interval(int client_id, unsigned int interval, bool is_processor)
-{
- m_accel_sensor->add_interval(client_id, interval, true);
- m_mag_sensor->add_interval(client_id, interval, true);
-
- return sensor_base::add_interval(client_id, interval, is_processor);
-}
-
-bool magnetic_rv_sensor::delete_interval(int client_id, bool is_processor)
-{
- m_accel_sensor->delete_interval(client_id, true);
- m_mag_sensor->delete_interval(client_id, true);
-
- return sensor_base::delete_interval(client_id, is_processor);
-}
#ifndef __MAGNETIC_RV_SENSOR_H__
#define __MAGNETIC_RV_SENSOR_H__
-#include <virtual_sensor.h>
+#include <fusion_sensor.h>
#include <sensor_types.h>
-#include <magnetic_fusion.h>
+#include "magnetic_fusion.h"
-class magnetic_rv_sensor : public virtual_sensor {
+class magnetic_rv_sensor : public fusion_sensor {
public:
magnetic_rv_sensor();
virtual ~magnetic_rv_sensor();
- /* initialize sensor */
- bool init(void);
+ int get_sensor_info(const sensor_info2_t **info);
+ int get_required_sensors(const required_sensor_s **sensors);
- /* sensor info */
- virtual sensor_type_t get_type(void);
- virtual unsigned int get_event_type(void);
- virtual const char* get_name(void);
+ int update(uint32_t id, sensor_data_t *data, int len);
+ int get_data(sensor_data_t **data, int *len);
- virtual bool get_sensor_info(sensor_info &info);
-
- /* synthesize event */
- virtual void synthesize(const sensor_event_t& event);
-
- bool add_interval(int client_id, unsigned int interval, bool is_processor);
- bool delete_interval(int client_id, bool is_processor);
-
- /* get data */
- virtual int get_data(sensor_data_t **data, int *length);
private:
- sensor_base *m_accel_sensor;
- sensor_base *m_mag_sensor;
magnetic_fusion m_fusion;
float m_x;
unsigned long long m_time;
unsigned long m_interval;
int m_accuracy;
-
- virtual bool set_interval(unsigned long interval);
- virtual bool set_batch_latency(unsigned long latency);
-
- virtual bool on_start(void);
- virtual bool on_stop(void);
};
#endif /* __MAGNETIC_SENSOR_H__ */
*
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <math.h>
-#include <time.h>
-#include <sys/types.h>
-#include <dlfcn.h>
+#include "rv_sensor.h"
#include <sensor_log.h>
#include <sensor_types.h>
-
-#include <sensor_common.h>
-#include <virtual_sensor.h>
-#include <rv_sensor.h>
-#include <sensor_loader.h>
#include <fusion_util.h>
-#define SENSOR_NAME "SENSOR_ROTATION_VECTOR"
-
+#define NAME_SENSOR "http://tizen.org/sensor/rotation_vector/rotation_vector"
+#define NAME_VENDOR "Samsung"
+
+#define SRC_ID_ACC 0x1
+#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer"
+
+#define SRC_ID_GYRO 0x2
+#define SRC_STR_GYRO "http://tizen.org/sensor/gyroscope"
+
+#define SRC_ID_MAG 0x3
+#define SRC_STR_MAG "http://tizen.org/sensor/geomagnetic"
+
+static sensor_info2_t sensor_info = {
+ id: 0x1,
+ type: ROTATION_VECTOR_SENSOR,
+ uri: NAME_SENSOR,
+ vendor: NAME_VENDOR,
+ min_range: 0,
+ max_range: 1,
+ resolution: 1,
+ min_interval: 10,
+ max_batch_count: 0,
+ wakeup_supported: false,
+ privilege:"",
+};
+
+static required_sensor_s required_sensors[] = {
+ {SRC_ID_ACC, SRC_STR_ACC},
+ {SRC_ID_GYRO, SRC_STR_GYRO},
+ {SRC_ID_MAG, SRC_STR_MAG},
+};
rv_sensor::rv_sensor()
-: m_accel_sensor(NULL)
-, m_gyro_sensor(NULL)
-, m_mag_sensor(NULL)
-, m_x(-1)
+: m_x(-1)
, m_y(-1)
, m_z(-1)
, m_w(-1)
, m_time(0)
+, m_interval(100)
, m_accuracy(SENSOR_ACCURACY_UNDEFINED)
{
}
rv_sensor::~rv_sensor()
{
- _I("%s is destroyed!", SENSOR_NAME);
-}
-
-bool rv_sensor::init(void)
-{
- m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR);
- m_gyro_sensor = sensor_loader::get_instance().get_sensor(GYROSCOPE_SENSOR);
- m_mag_sensor = sensor_loader::get_instance().get_sensor(GEOMAGNETIC_SENSOR);
-
- if (!m_accel_sensor || !m_gyro_sensor|| !m_mag_sensor) {
- _W("cannot load sensors[%s]", SENSOR_NAME);
- return false;
- }
-
- _I("%s is created!", SENSOR_NAME);
- return true;
-}
-
-sensor_type_t rv_sensor::get_type(void)
-{
- return ROTATION_VECTOR_SENSOR;
}
-unsigned int rv_sensor::get_event_type(void)
+int rv_sensor::get_sensor_info(const sensor_info2_t **info)
{
- return CONVERT_TYPE_EVENT(ROTATION_VECTOR_SENSOR);
+ *info = &sensor_info;
+ return OP_SUCCESS;
}
-const char* rv_sensor::get_name(void)
+int rv_sensor::get_required_sensors(const required_sensor_s **sensors)
{
- return SENSOR_NAME;
+ *sensors = required_sensors;
+ return 3;
}
-bool rv_sensor::get_sensor_info(sensor_info &info)
+int rv_sensor::update(uint32_t id, sensor_data_t *data, int len)
{
- info.set_type(get_type());
- info.set_id(get_id());
- info.set_privilege(SENSOR_PRIVILEGE_PUBLIC);
- info.set_name(get_name());
- info.set_vendor("Samsung Electronics");
- info.set_min_range(0);
- info.set_max_range(1);
- info.set_resolution(1);
- info.set_min_interval(1);
- info.set_fifo_count(0);
- info.set_max_batch_count(0);
- info.set_supported_event(get_event_type());
- info.set_wakeup_supported(false);
-
- return true;
-}
-
-void rv_sensor::synthesize(const sensor_event_t& event)
-{
- sensor_event_t *rotation_vector_event;
-
- if (event.event_type != GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME &&
- event.event_type != ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME &&
- event.event_type != GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME)
- return;
+ unsigned long long timestamp;
- if (event.event_type == ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME)
- m_fusion.push_accel(*(event.data));
- else if (event.event_type == GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME)
- m_fusion.push_mag(*(event.data));
- else if (event.event_type == GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME)
- m_fusion.push_gyro(*(event.data));
+ if (id == SRC_ID_ACC)
+ m_fusion.push_accel(*data);
+ else if (id == SRC_ID_MAG)
+ m_fusion.push_mag(*data);
+ else if (id == SRC_ID_GYRO)
+ m_fusion.push_gyro(*data);
- if (m_accuracy == SENSOR_ACCURACY_UNDEFINED)
- m_accuracy = event.data->accuracy;
- else if (m_accuracy > event.data->accuracy)
- m_accuracy = event.data->accuracy;
+ if (m_accuracy > data->accuracy)
+ m_accuracy = data->accuracy;
- unsigned long long timestamp;
if (!m_fusion.get_rv(timestamp, m_w, m_x, m_y, m_z))
- return;
+ return OP_ERROR;
if (timestamp == m_time)
- return;
- m_time = timestamp;
+ return OP_ERROR;
- rotation_vector_event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
- if (!rotation_vector_event) {
- _E("Failed to allocate memory");
- return;
- }
- rotation_vector_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
- if (!rotation_vector_event->data) {
- _E("Failed to allocate memory");
- free(rotation_vector_event);
- return;
- }
-
- rotation_vector_event->sensor_id = get_id();
- rotation_vector_event->event_type = CONVERT_TYPE_EVENT(ROTATION_VECTOR_SENSOR);
- rotation_vector_event->data_length = sizeof(sensor_data_t);
- rotation_vector_event->data->accuracy = m_accuracy;
- rotation_vector_event->data->timestamp = m_time;
- rotation_vector_event->data->value_count = 4;
- rotation_vector_event->data->values[0] = m_w;
- rotation_vector_event->data->values[1] = m_x;
- rotation_vector_event->data->values[2] = m_y;
- rotation_vector_event->data->values[3] = m_z;
- push(rotation_vector_event);
- m_accuracy = SENSOR_ACCURACY_UNDEFINED;
+ m_time = timestamp;
_D("[rotation_vector] : [%10f] [%10f] [%10f] [%10f]", m_x, m_y, m_z, m_w);
+ return OP_SUCCESS;
}
int rv_sensor::get_data(sensor_data_t **data, int *length)
sensor_data->accuracy = m_accuracy;
sensor_data->timestamp = m_time;
- sensor_data->value_count = 3;
- sensor_data->values[0] = m_x;
- sensor_data->values[1] = m_y;
- sensor_data->values[2] = m_z;
+ sensor_data->value_count = 4;
+ sensor_data->values[0] = m_w;
+ sensor_data->values[1] = m_x;
+ sensor_data->values[2] = m_y;
+ sensor_data->values[3] = m_z;
*data = sensor_data;
*length = sizeof(sensor_data_t);
return 0;
}
-
-bool rv_sensor::set_interval(unsigned long interval)
-{
- m_interval = interval;
- return true;
-}
-
-bool rv_sensor::set_batch_latency(unsigned long latency)
-{
- return false;
-}
-
-bool rv_sensor::on_start(void)
-{
- m_accel_sensor->start();
- m_gyro_sensor->start();
- m_mag_sensor->start();
- m_time = 0;
- m_accuracy = SENSOR_ACCURACY_UNDEFINED;
- return activate();
-}
-
-bool rv_sensor::on_stop(void)
-{
- m_accel_sensor->stop();
- m_gyro_sensor->stop();
- m_mag_sensor->stop();
- m_time = 0;
- m_accuracy = SENSOR_ACCURACY_UNDEFINED;
- return deactivate();
-}
-
-bool rv_sensor::add_interval(int client_id, unsigned int interval, bool is_processor)
-{
- m_accel_sensor->add_interval(client_id, interval, true);
- m_gyro_sensor->add_interval(client_id, interval, true);
- m_mag_sensor->add_interval(client_id, interval, true);
-
- return sensor_base::add_interval(client_id, interval, is_processor);
-}
-
-bool rv_sensor::delete_interval(int client_id, bool is_processor)
-{
- m_accel_sensor->delete_interval(client_id, true);
- m_gyro_sensor->delete_interval(client_id, true);
- m_mag_sensor->delete_interval(client_id, true);
-
- return sensor_base::delete_interval(client_id, is_processor);
-}
*
*/
-#ifndef _ROTATION_VECTOR_SENSOR_H_
-#define _ROTATION_VECTOR_SENSOR_H_
+#ifndef __ROTATION_VECTOR_SENSOR_H__
+#define __ROTATION_VECTOR_SENSOR_H__
-#include <virtual_sensor.h>
+#include <fusion_sensor.h>
#include <sensor_types.h>
-#include <gyro_magnetic_fusion.h>
+#include "gyro_magnetic_fusion.h"
-class rv_sensor : public virtual_sensor {
+class rv_sensor : public fusion_sensor {
public:
rv_sensor();
virtual ~rv_sensor();
- /* initialize sensor */
- bool init(void);
+ int get_sensor_info(const sensor_info2_t **info);
+ int get_required_sensors(const required_sensor_s **sensors);
- /* sensor info */
- virtual sensor_type_t get_type(void);
- virtual unsigned int get_event_type(void);
- virtual const char* get_name(void);
+ int update(uint32_t id, sensor_data_t *data, int len);
+ int get_data(sensor_data_t **data, int *len);
- virtual bool get_sensor_info(sensor_info &info);
-
- /* synthesize event */
- virtual void synthesize(const sensor_event_t& event);
-
- bool add_interval(int client_id, unsigned int interval, bool is_processor);
- bool delete_interval(int client_id, bool is_processor);
-
- /* get data */
- virtual int get_data(sensor_data_t **data, int *length);
private:
- sensor_base *m_accel_sensor;
- sensor_base *m_gyro_sensor;
- sensor_base *m_mag_sensor;
gyro_magnetic_fusion m_fusion;
float m_x;
unsigned long long m_time;
unsigned long m_interval;
int m_accuracy;
-
- virtual bool set_interval(unsigned long interval);
- virtual bool set_batch_latency(unsigned long latency);
-
- virtual bool on_start(void);
- virtual bool on_stop(void);
};
-#endif /* _ROTATION_VECTOR_SENSOR_H_ */
+#endif /* __ROTATION_VECTOR_SENSOR_H__ */