src/orientation_sensor.cpp
OrientationSensor::OrientationSensor(uint8_t pin_i2c_sda, uint8_t pin_i2c_scl,
                                     uint8_t accel_mag_i2c_addr,
                                     uint8_t gyro_i2c_addr) {
  sensor_interface_ = new SensorFusion();  // create our fusion engine instance

  bool success;
  // init IO subsystem, passing NULLs since we use Signal-K output instead.
  success =
      sensor_interface_->InitializeInputOutputSubsystem(NULL, NULL) &&
      // connect to the sensors.  Accelerometer and magnetometer are in same IC.
      sensor_interface_->InstallSensor(accel_mag_i2c_addr,
                                       SensorType::kMagnetometer) &&
      sensor_interface_->InstallSensor(accel_mag_i2c_addr,
                                       SensorType::kAccelerometer) &&
      // A thermometer (uncalibrated) is available in the
      // accelerometer/magnetometer IC.
      sensor_interface_->InstallSensor(accel_mag_i2c_addr,
                                       SensorType::kThermometer) &&
      sensor_interface_->InstallSensor(gyro_i2c_addr, SensorType::kGyroscope);
  if (!success) {
    debugE("Trouble installing sensors.");
  } else {
    sensor_interface_->Begin(pin_i2c_sda, pin_i2c_scl);
    debugI("Sensors connected & Fusion ready");

    // The Fusion Library, in build.h, defines how fast the ICs generate new
    // orientation data and how fast the fusion algorithm runs, using FUSION_HZ.
    // Usually this rate should be the same as ReadAndProcessSensors() is
    // called.
    const uint32_t kFusionIntervalMs = 1000.0 / FUSION_HZ;
    // Start periodic reads of sensor and running of fusion algorithm.
    app.onRepeat(kFusionIntervalMs,
                 [this]() { this->ReadAndProcessSensors(); });
  }

}
/**
 * @brief Constructor sets up the I2C communications to the sensor and
 * initializes the sensor fusion library.
 *
 * @param pin_i2c_sda Pin of SDA line to sensor. Use -1 for Arduino default.
 * @param pin_i2c_scl Pin of SCL line to sensor. Use -1 for Arduino default.
 * @param accel_mag_i2c_addr I2C address of accelerometer/magnetometer IC.
 * @param gyro_i2c_addr I2C address of gyroscope IC.
 * @param config_path RESTful path by which sensor can be configured.
 */
@brief Constructor sets up the I2C communications to the sensor and
initializes the sensor fusion library.

@param pin_i2c_sda Pin of SDA line to sensor. Use -1 for Arduino default.
@param pin_i2c_scl Pin of SCL line to sensor. Use -1 for Arduino default.
@param accel_mag_i2c_addr I2C address of accelerometer/magnetometer IC.
@param gyro_i2c_addr I2C address of gyroscope IC.
@param config_path RESTful path by which sensor can be configured.
@brief Constructor sets up the I2C communications to the sensor and initializes the sensor fusion library . @param pin_i2c_sda Pin of SDA line to sensor . Use - 1 for Arduino default . @param pin_i2c_scl Pin of SCL line to sensor . Use - 1 for Arduino default . @param accel_mag_i2c_addr I2C address of accelerometer / magnetometer IC . @param gyro_i2c_addr I2C address of gyroscope IC . @param config_path RESTful path by which sensor can be configured .
OrientationSensor::OrientationSensor(uint8_t pin_i2c_sda, uint8_t pin_i2c_scl,
                                     uint8_t accel_mag_i2c_addr,
                                     uint8_t gyro_i2c_addr) {
  sensor_interface_ = new SensorFusion();  
  bool success;
  success =
      sensor_interface_->InitializeInputOutputSubsystem(NULL, NULL) &&
      sensor_interface_->InstallSensor(accel_mag_i2c_addr,
                                       SensorType::kMagnetometer) &&
      sensor_interface_->InstallSensor(accel_mag_i2c_addr,
                                       SensorType::kAccelerometer) &&
      sensor_interface_->InstallSensor(accel_mag_i2c_addr,
                                       SensorType::kThermometer) &&
      sensor_interface_->InstallSensor(gyro_i2c_addr, SensorType::kGyroscope);
  if (!success) {
    debugE("Trouble installing sensors.");
  } else {
    sensor_interface_->Begin(pin_i2c_sda, pin_i2c_scl);
    debugI("Sensors connected & Fusion ready");
    const uint32_t kFusionIntervalMs = 1000.0 / FUSION_HZ;
    app.onRepeat(kFusionIntervalMs,
                 [this]() { this->ReadAndProcessSensors(); });
  }
}
OrientationSensor :: OrientationSensor ( uint8_t pin_i2c_sda , uint8_t pin_i2c_scl , uint8_t accel_mag_i2c_addr , uint8_t gyro_i2c_addr ) { sensor_interface_ = new SensorFusion ( ) ; bool success ; success = sensor_interface_ -> InitializeInputOutputSubsystem ( NULL , NULL ) && sensor_interface_ -> InstallSensor ( accel_mag_i2c_addr , SensorType :: kMagnetometer ) && sensor_interface_ -> InstallSensor ( accel_mag_i2c_addr , SensorType :: kAccelerometer ) && sensor_interface_ -> InstallSensor ( accel_mag_i2c_addr , SensorType :: kThermometer ) && sensor_interface_ -> InstallSensor ( gyro_i2c_addr , SensorType :: kGyroscope ) ; if ( ! success ) { debugE ( " " ) ; } else { sensor_interface_ -> Begin ( pin_i2c_sda , pin_i2c_scl ) ; debugI ( " " ) ; const uint32_t kFusionIntervalMs = 1000.0 / FUSION_HZ ; app . onRepeat ( kFusionIntervalMs , [ this ] ( ) { this -> ReadAndProcessSensors ( ) ; } ) ; } }
@brief Constructor sets up the I2C communications to the sensor and
 initializes the sensor fusion library.
@brief Constructor sets up the I2C communications to the sensor and initializes the sensor fusion library .
// create our fusion engine instance // init IO subsystem, passing NULLs since we use Signal-K output instead. // connect to the sensors.  Accelerometer and magnetometer are in same IC. // A thermometer (uncalibrated) is available in the // accelerometer/magnetometer IC. // The Fusion Library, in build.h, defines how fast the ICs generate new // orientation data and how fast the fusion algorithm runs, using FUSION_HZ. // Usually this rate should be the same as ReadAndProcessSensors() is // called. // Start periodic reads of sensor and running of fusion algorithm.