Supporting Virtual Sensors based on On-Chip(Hardware Based) Sensor Fusion Solution


Software Fusion Sensor:


The fusion sensor registers for accelerometer, gyroscope and geomagnetic sensors. Uses the data from these three sensors to fusion_event, which is used by various sensors to generate their specific sensor events.


->The virtual sensor starts the hardware and fusion sensor.

->Fusion sensor registers for hardware sensors. It received accelerometer, gyroscope and/or geomagnetic sensor events.

->Based on what all events are received, fusion sensor generates a fusion sensor event.

->The FUSION_EVENT is sent to all virtual sensors which have registered for fusion sensor.

->The virtual sensors then use the data from FUSION_EVENT to create their specific virtual sensor events.


Hardware Fusion Sensor:


In case hardware based fusion sensor is present, individual sensors won't be required by fusion sensor to generate FUSION_EVENT.

So, virtual sensors won't have to register and start the individual hardware sensors (accel, gyro or geomagnetic) for receiving FUSION_EVENT. They will just have to register for hardware fusion sensor event and they will receive the hardware sensor event.


Adding hardware fusion sensor in virtual sensors:

In case hardware fusion sensor is present, instead of registering of individual hardware sensors and fusion sensor, virtual sensor will register for just sensor hal fusion sensor.


Also, fusion sensor will register for just fusion_sensor_hal and send the events to all virtual sensor registered for fusion sensor events.


For this, the virtual sensor must register/start specific sensors in case hardware fusion sensor is present or not.


In any virtual sensor class, to add support for both hardware and software sensor fusion,


->In the constructor use sensor_plugin_loader to check if the hal sensor fusion is present or not:

sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION)


->If it returns NULL, in that case, hardware fusion sensor is not present, else the hardware fusion is present.

->Store this result in virtual_sensor::m_hardware_fusion


sensor_hal *fusion_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(SENSOR_HAL_TYPE_FUSION);

if (!fusion_sensor_hal)

  m_hardware_fusion = false;

else

  m_hardware_fusion = true;



->Bases on this, in on_start, on_stop, add_interval, delete_interval etc functions, the physical sensors will be started in case hardware fusion sensor is not present and only fusion sensor will be started in case hardware fusion sensor is present.



bool orientation_sensor::on_start(void)

{

  AUTOLOCK(m_mutex);


  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);

  m_fusion_sensor->add_client(FUSION_EVENT);

  m_fusion_sensor->add_interval((intptr_t)this, (m_interval/MS_TO_US), false);

  m_fusion_sensor->start();


  activate();

  return true;

}